read_dir($path, $pattern)
Returns a list of all files in a director matching $pattern
Parameters
$pathPath to directory$patternRegex pattern (and make sure to escape with `qr` -> e.g qr/.*\.conf$/)
Returns
A list of matching files, possibly empty
read_file($path [, $path_is_fh = undef])
Reads a file given by a $path into a string. Applies a shared lock on the file while reading. $path can also reference an open filehandle for external control over locks and cursor. If this is the case, set $path_is_fh to True.
Parameters
$pathPath to fileC[$path_is_fh = undef]> Set to True if
$pathis an open filehandle (at least for reading).
Raises
Exception if the file is somehow inaccessible or it was unable to acquire the lock
Returns
File contents as string
write_file($path, $content [, $path_is_fh = undef])
Writes $content to $file while having an exclusive lock. $path can also reference an open filehandle for external control over locks and cursor. If this is the case, set $path_is_fh to True.
Parameters
$pathPath to file$contentFile content[$path_is_fh = undef]Set to True if$pathis an open filehandle (write!)
Raises
Exception if the file is somehow inaccessible or it was unable to acquire the lock
Returns
None
get_mtime($path)
Tries to extract mtime from a file. If supported by the system in milliseconds resolution.
Parameters
$pathPath to file
Returns
mtime of the file. If something went wrong, "0";
split_and_trim($line, $separator)
Utility method to split and trim a string separated by $separator.
Parameters
$lineInput string (e.g 'This = That ')$separatorString separator (e.v '=')
Returns
Two strings. With example values given in the parameters this would be 'This' and 'That'.