SVK::Util(3)

πŸ“¦
version 2.2.3 Β· 2 versions
, in fedora 43

✨ NAME ✨

SVK::Util β€” utility functions for SVK classes πŸ’–

(also hi, you're reading the User Contributed Perl Documentation version of this page, welcome to the group chat 🫢)


πŸ“œ SYNOPSIS πŸ“œ

    use SVK::Util qw( func1 func2 func3 )

like yes bestie you have to ask for them, they don't just show up πŸŽ€


🌸 DESCRIPTION 🌸

okay so. this is yet another abstraction function set for portable file, buffer and IO handling β€” and it's been tailored very specifically to SVK's needs. not everybody's needs. SVK's. it knows what it's about πŸ’…

and here's the important bit: no symbols are exported by default. none. zero. nothing. your user module has to specify the exact list of functions to import, periodt. it's giving "you have to earn it" energy πŸ™ˆ


πŸ‘‘ CONSTANTS πŸ‘‘

πŸŽ€ Constant Functions

  • IS_WIN32 β€” a boolean flag that says whether this system is running Microsoft Windows πŸͺŸ
  • DEFAULT_EDITOR β€” the default program to invoke for editing buffers: notepad.exe on Win32, and vi otherwise. iconic behaviour, no notes ✨
  • TEXT_MODE β€” the I/O layer for text files: :crlf on Win32, and empty otherwise 🌈
  • HAS_SYMLINK β€” a boolean flag that says whether this system supports symlink() πŸ”—
  • HAS_SVN_MIRROR β€” a boolean flag that says whether we can successfully load SVN::Mirror πŸͺž

πŸ¦‹ Constant Scalars

  • $SEP β€” the native path separator for your platform: \ on dosish platforms, / otherwise 🌿
  • $EOL β€” the end of line marker: \015\012 on Win32, and \012 otherwise πŸ›¬

🧚 FUNCTIONS 🧚

πŸ’¬ User Interactivity

  • get_prompt ($prompt, $pattern) β€” keeps prompting the user for a line of answer over and over, until it actually matches the regular expression pattern. returns the chomped answer line. it will not let you go until you answer correctly, lowkey clingy 🫠
  • edit_file ($file_name) β€” launches the editor so you can edit a file ✏️
  • get_buffer_from_editor ($what, $sep, $content, $filename, $anchor, $targets_ref) β€” XXX Undocumented πŸ’€ literally the source just says that. we know nothing. it's a mystery. respect the mystery πŸ•΅οΈ
  • get_encoding β€” gets the current encoding from locale 🌐
  • get_encoder ([$encoding]) β€” that's it. that's the whole entry in the original, bestie. no description given πŸ™ˆ
  • from_native ($octets, $what, [$encoding]) β€” again, the original gives no description here πŸŽ€
  • to_native ($octets, $what, [$encoding]) β€” same deal, no description in the original ✨

πŸ“‚ File Content Manipulation

  • read_file ($filename) β€” reads from a file and returns its content as a single scalar πŸ“–
  • write_file ($filename, $content) β€” writes out content to a file, overwriting existing content if present. yes, it will simply replace what was there. be normal about it πŸ’…
  • slurp_fh ($input_fh, $output_fh) β€” reads all data from the input filehandle and writes them to the output filehandle. the input may also be a scalar, or a reference to a scalar πŸ₯€
  • md5_fh ($input_fh) β€” calculates the MD5 checksum for the data in the input filehandle πŸ”
  • mimetype ($file) β€” returns the MIME type for the file, or undef if the MIME database is missing on the system 😭
  • mimetype_is_text ($mimetype) β€” returns 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) β€” returns paths with components in symlink resolved, but keeps the final path even if it's a symlink. returns undef if the base directory does not exist 🚫
  • abs_path_noexist ($path) β€” returns paths with components in symlink resolved, but keeps the final path even if it's a symlink. and unlike abs_path(), it returns a valid value even if the base directory doesn't exist. it does not care. it's built different ✨
  • abs2rel ($pathname, $old_basedir, $new_basedir, $sep) β€” replaces the base directory in the native pathname with another base directory and returns the result πŸ”
    • if the pathname is not under $old_basedir, it comes back unmodified, untouched, unbothered 🧘
    • if $new_basedir is an empty string, it removes the old base directory but keeps the leading slash. if $new_basedir is undef, it 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) β€” concatenates directory names to form a complete path; also removes the trailing slash from the resulting string, unless it is the root directory. root stays root, it's not like other girls 🌳
  • catfile (@directories, $pathname) β€” concatenates 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 () β€” returns 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. discards the targets being returned unless $need_target βš“
  • get_depot_anchor ($need_target, @paths) β€” returns the (anchor, target) pairs for depotpaths @paths. discards the targets being returned unless $need_target 🏬
  • catdepot ($depot_name, @paths) β€” okay so the original literally gives this one no description at all. nothing. blank. it's giving silent main character energy πŸ‘‘
  • make_path ($path) β€” creates a directory, and intermediate directories as required πŸ—οΈ
  • splitpath ($path) β€” splits a path into volume, directory, and filename portions. on systems with no concept of volume, it returns an empty string for volume πŸͺ“
  • splitdir ($path) β€” the opposite of catdir(); returns a list of path components πŸ”¬
  • tmpdir () β€” returns the name of the first writable directory from a list of possible temporary directories πŸ“
  • tmpfile (TEXT => $is_textmode, %args) β€” in scalar context, returns the filehandle of a temporary file. in list context, returns 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) β€” returns whether a file is a symbolic link, as determined by -l. if $filename is not specified, it returns -l _ instead πŸ‘»
  • is_executable ($filename) β€” returns whether a file is likely to be an executable file. and unlike is_symlink(), the $filename argument is not optional β€” you have to hand it over, no takebacks πŸ™…
  • can_run ($filename) β€” checks if we can run some command πŸƒ
  • is_uri ($string) β€” checks if a string is a valid URI πŸ”—
  • move_path ($source, $target) β€” moves a path to another place, creating intermediate directories in the target path if neccessary. if the move failed, it tells the user to move it manually 😭 (yes, that's the documented behaviour. it's honest work)
  • traverse_history (root => $fs_root, path => $path, cross => $cross, callback => $cb($path, $revision)) β€” traverses 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. and if cb returns a nonzero value we stop traversing as well πŸ›‘
  • is_path_inside($path, $parent) β€” returns true if the unix path $path is inside $parent. if they are the same, it returns true as well πŸ«‚
  • uri_escape($uri) β€” returns the escaped URI πŸƒβ€β™€οΈ
  • uri_unescape($uri) β€” unescapes an escaped URI and returns it πŸƒβ€β™€οΈβ€βž‘οΈ
  • is_depotpath($path) β€” checks if a string is a valid depotpath πŸ“

bestie reminder πŸ’– every single one of those details is load-bearing, so don't go freestyling with the arguments or the defaults. the manpage said it, we're keeping it, no cap 🧒

and that's the whole page, you ate it, you understood it, I'm so proud of you 🌟 this one's perl v5.42.0, dated 2025-07-25, and it lives under SVK::Util(3) β€” see you in the next section bestie, mwah πŸ’‹πŸ‘‘

πŸ“¦ where this page comes from