man SVK::Util () - Utility functions for SVK classes

NAME

SVK::Util - Utility functions for SVK classes

SYNOPSIS

    use SVK::Util qw( func1 func2 func3 )

DESCRIPTION

This is yet another abstraction function set for portable file, buffer and IO handling, tailored to SVK's specific needs.

No symbols are exported by default; the user module needs to specify the list of functions to import.

CONSTANTS

Constant Functions

IS_WIN32

Boolean flag to indicate whether this system is running Microsoft Windows.

DEFAULT_EDITOR

The default program to invoke for editing buffers: CWnotepad.exe on Win32, CWvi otherwise.

TEXT_MODE

The I/O layer for text files: CW:crlf on Win32, empty otherwise.

HAS_SYMLINK

Boolean flag to indicate whether this system supports CWsymlink().

HAS_SVN_MIRROR

Boolean flag to indicate whether we can successfully load SVN::Mirror.

Constant Scalars

$SEP

Native path separator: platform: CW\ on dosish platforms, CW/ otherwise.

$EOL

End of line marker: CW\015\012 on Win32, CW\012 otherwise.

FUNCTIONS

User Interactivity

get_prompt ($prompt, CI$pattern)

Repeatedly prompt the user for a line of answer, until it matches the regular expression pattern. Returns the chomped answer line.

edit_file ($file_name)

Launch editor to edit a file.

get_buffer_from_editor ($what, CI$sep, CI$content, CI$filename, CI$anchor, CI$targets_ref)

XXX Undocumented

get_encoding

Get the current encoding from locale

get_encoder ([$encoding])

from_native ($octets, CI$what, [$encoding])

to_native ($octets, CI$what, [$encoding])

Mirror Handling

find_local_mirror ($repos, CI$uuid, CI$path, CI$rev)

XXX Undocumented

find_svm_source ($repos, CI$path, CI$rev)

XXX Undocumented

resolve_svm_source ($repos, CI$uuid, CI$path)

XXX Undocumented

File Content Manipulation

read_file ($filename)

Read from a file and returns its content as a single scalar.

write_file ($filename, CI$content)

Write out content to a file, overwriting existing content if present.

slurp_fh ($input_fh, CI$output_fh)

Read all data from the input filehandle and write them to the output filehandle. The input may also be a scalar, or reference to a scalar.

md5_fh ($input_fh)

Calculate MD5 checksum for data in the input filehandle.

mimetype ($file)

Return the MIME type for the file, or CWundef if the MIME database is missing on the system.

mimetype_is_text ($mimetype)

Return whether a MIME type string looks like a text file.

Path and Filename Handling

abspath ($path)

Return paths with components in symlink resolved, but keep the final path even if it's symlink. Returns CWundef if the base directory does not exist.

abs_path_noexist ($path)

Return paths with components in symlink resolved, but keep the final path even if it's symlink. Unlike abs_path(), returns a valid value even if the base directory doesn't exist.

abs2rel ($pathname, CI$old_basedir, CI$new_basedir, CI$sep)

Replace the base directory in the native pathname to another base directory and return the result.

If the pathname is not under CW$old_basedir, it is not unmodified.

If CW$new_basedir is an empty string, removes the old base directory but keeps the trailing slash. If CW$new_basedir is CWundef, also removes the trailing slash.

By default, the return value of this function will use CW$SEP as its path separator. Setting CW$sep to CW/ will turn native path separators into CW/ instead.

catdir (@directories)

Concatenate directory names to form a complete path; also removes the trailing slash from the resulting string, unless it is the root directory.

catfile (@directories, CI$pathname)

Concatenate one or more directory names and a filename to form a complete path, ending with a filename. If CW$pathname contains directories, they will be splitted off to the end of CW@directories.

catpath ($volume, CI$directory, CI$filename)

XXX Undocumented - See File::Spec

devnull ()

Return a file name suitable for reading, and guaranteed to be empty.

get_anchor ($need_target, CI@paths)

Returns the (anchor, target) pairs for native path CW@paths. Discard the targets being returned unless CW$need_target.

get_depot_anchor ($need_target, CI@paths)

Returns the (anchor, target) pairs for depotpaths CW@paths. Discard the targets being returned unless CW$need_target.

catdepot ($depot_name, CI@paths)

make_path ($path)

Create a directory, and intermediate directories as required.

splitpath ($path)

Splits a path in to volume, directory, and filename portions. On systems with no concept of volume, returns an empty string for volume.

splitdir ($path)

The opposite of CWcatdir(); return a list of path components.

tmpdir ()

Return the name of the first writable directory from a list of possible temporary directories.

tmpfile (TEXT => CI$is_textmode, CI%args)

In scalar context, return the filehandle of a temporary file. In list context, return the filehandle and the filename.

If CW$is_textmode is true, the returned file handle is marked with CWTEXT_MODE.

See File::Temp for valid keys of CW%args.

is_symlink ($filename)

Return whether a file is a symbolic link, as determined by CW-l. If CW$filename is not specified, return CW-l _ instead.

is_executable ($filename)

Return whether a file is likely to be an executable file. Unlike CWis_symlink(), the CW$filename argument is not optional.

can_run ($filename)

Check if we can run some command.

is_uri ($string)

Check if a string is a valid URI.

move_path ($source, CI$target)

Move a path to another place, creating intermediate directories in the target path if neccessary. If move failed, tell the user to move it manually.

find_prev_copy ($fs, CI$rev)

Find the revision of the nearest copy in a repository that is less or equal to CW$rev. Returns the found revision number, and a hash of arrayref that contains copied paths and its source found in that revision.

AUTHORS

Chia-liang Kao <clkao@clkao.org>

COPYRIGHT

Copyright 2003-2005 by Chia-liang Kao <clkao@clkao.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>