---
name: "SVK::Util"
section: "3pm"
platform: "linux"
package: "svk"
version: "2.0.2-3"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/SVK::Util"
---

# SVK::Util(3pm)

SVK::Util - Utility functions for SVK classes

```
    use SVK::Util qw( func1 func2 func3 )
```

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.\
 **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: `"notepad.exe"` on Win32, `"vi"` otherwise. *TEXT\_MODE* The I/O layer for text files: `":crlf"` on Win32, empty otherwise. *HAS\_SYMLINK* Boolean flag to indicate whether this system supports `"symlink()"`. *HAS\_SVN\_MIRROR* Boolean flag to indicate whether we can successfully load SVN::Mirror.\
 **Constant Scalars** *$SEP* Native path separator: platform: `"\"` on dosish platforms, `"/"` otherwise. *$EOL* End of line marker: `"\015\012"` on Win32, `"\012"` otherwise.\
 **User Interactivity** *get\_prompt ($prompt, $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, $sep, $content, $filename, $anchor, $targets\_ref)* XXX Undocumented *get\_encoding* Get the current encoding from locale *get\_encoder (\[$encoding\])* *from\_native ($octets, $what, \[$encoding\])* *to\_native ($octets, $what, \[$encoding\])*\
 **File Content Manipulation** *read\_file ($filename)* Read from a file and returns its content as a single scalar. *write\_file ($filename, $content)* Write out content to a file, overwriting existing content if present. *slurp\_fh ($input\_fh, $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 `"undef"` if the MIME database is missing on the system. *mimetype\_is\_text ($mimetype)* Return whether a MIME type string looks like a text file. *is\_binary\_file ($filename OR $filehandle)* Returns true if the given file or filehandle contains binary data.  Otherwise, returns false.\
 **Path and Filename Handling** *abspath ($path)* Return paths with components in symlink resolved, but keep the final path even if it's symlink.  Returns `"undef"` 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, $old\_basedir, $new\_basedir, $sep)* Replace the base directory in the native pathname to another base directory and return the result. If the pathname is not under `$old_basedir`, it is returned unmodified. If `$new_basedir` is an empty string, removes the old base directory but keeps the leading slash.  If `$new_basedir` is `"undef"`, also removes the leading slash. By default, the return value of this function will use `$SEP` as its path separator.  Setting `$sep` to `"/"` will turn native path separators into `"/"` 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, $pathname)* Concatenate one or more directory names and a filename to form a complete path, ending with a filename.  If `$pathname` contains directories, they will be splitted off to the end of `@directories`. *catpath ($volume, $directory, $filename)* XXX Undocumented - See File::Spec *devnull ()* Return a file name suitable for reading, and guaranteed to be empty. *get\_anchor ($need\_target, @paths)* Returns the (anchor, target) pairs for native path `@paths`.  Discard the targets being returned unless `$need_target`. *get\_depot\_anchor ($need\_target, @paths)* Returns the (anchor, target) pairs for depotpaths `@paths`.  Discard the targets being returned unless `$need_target`. *catdepot ($depot\_name, @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 `"catdir()"`; return a list of path components. *tmpdir ()* Return the name of the first writable directory from a list of possible temporary directories. *tmpfile (TEXT =\> $is\_textmode, %args)* In scalar context, return the filehandle of a temporary file. In list context, return the filehandle and the filename. If `$is_textmode` is true, the returned file handle is marked with `"TEXT_MODE"`. See File::Temp for valid keys of `%args`. *is\_symlink ($filename)* Return whether a file is a symbolic link, as determined by `"-l"`. If `$filename` is not specified, return `"-l _"` instead. *is\_executable ($filename)* Return whether a file is likely to be an executable file. Unlike `"is_symlink()"`, the `$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, $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. *traverse\_history (root =\> $fs\_root, path =\> $path, cross =\> $cross, callback =\> $cb($path, $revision))* Traverse the history of `$path` in `$fs_root` backwards until the first copy, unless `$cross` is true.  We do cross renames regardless of the value of `$cross` being non-zero, but not -1.  We invoke `$cb` for each `$path`, `$revision` we encounter.  If cb returns a nonzero value we stop traversing as well. *is\_path\_inside($path, $parent)* Returns true if unix path `$path` is inside `$parent`. If they are the same, return true as well.
