Lazy-Utils
view release on metacpan or search on metacpan
# NAME
Lazy::Utils - Utility functions
# VERSION
version 1.22
# SYNOPSIS
use Lazy::Utils;
trim($str);
ltrim($str);
rtrim($str);
file_get_contents($path, $prefs);
file_put_contents($path, $contents, $prefs);
shellmeta($s, $nonquoted);
system2($cmd, @argv);
bash_readline($prompt);
cmdargs($prefs, @argv);
whereis($name, $path);
file_cache($tag, $expiry, $coderef);
get_pod_text($file_name, $section, $exclude_section);
array_to_hash(@array);
# DESCRIPTION
Collection of utility functions all of exported by default.
# FUNCTIONS
## trim($str)
trims given string
$str: _string will be trimmed_
return value: _trimmed string_
## ltrim($str)
trims left given string
$str: _string will be trimmed_
return value: _trimmed string_
## rtrim($str)
trims right given string
$str: _string will be trimmed_
return value: _trimmed string_
## file\_get\_contents($path, $prefs)
gets all contents of file in string type
$path: _path of file_
$prefs: _preferences in HashRef, by default undef_
> utf8: _opens file-handle as :utf8 mode, by default 0_
return value: _file contents in string type, otherwise undef because of errors_
## file\_put\_contents($path, $contents, $prefs)
puts all contents of file in string type
$path: _path of file_
$contents: _file contents in string type_
$prefs: _preferences in HashRef, by default undef_
> utf8: _opens file-handle as :utf8 mode, by default 0_
return value: _success 1, otherwise undef_
## shellmeta($s, $nonquoted)
escapes metacharacters of interpolated shell string
$s: _interpolated shell string_
$nonquoted: _also escapes whitespaces and \* character for non-quoted interpolated shell string, by default 0_
return value: _escaped string_
## system2($cmd, @argv)
**\_system($cmd, @argv)** _OBSOLETE_
alternative implementation of perls core system subroutine that executes a system command
$cmd: _command_
@argv: _command line arguments_
return value: _exit code of command. -1 if fatal error occurs_
returned $!: _system error message_
returned $?: _return code of wait call like on perls system call_
## bash\_readline($prompt)
**bashReadLine($prompt)** _OBSOLETE_
reads a line from STDIN using Bash
$prompt: _prompt, by default ''_
return value: _line_
## cmdargs(\[$prefs, \]@argv)
**commandArgs(\[$prefs, \]@argv)** _OBSOLETE_
**cmdArgs(\[$prefs, \]@argv)** _OBSOLETE_
resolves command line arguments
$prefs: _preferences in HashRef, optional_
> valuableArgs: _accepts option value after option if next argument is not an option, by default 0_
>
> noCommand: _use first parameter instead of command, by default 0_
>
> optionAtAll: _accepts options after command or first parameter otherwise evaluates as parameter, by default 1_
@argv: _command line arguments_
-a -b=c -d e --f g --h --i=j k l -- m n
by default, return value:
{ -a => '', -b => 'c', -d => '', --f => '', --h => '', --i => 'j', command => 'e', parameters => ['g', 'k', 'l'], late_parameters => ['m', 'n'] }
if valuableArgs is on, return value;
{ -a => '', -b => 'c', -d => 'e', --f => 'g', --h => '', --i => 'j', command => 'k', parameters => ['l'], late_parameters => ['m', 'n'] }
if noCommand is on, return value:
{ -a => '', -b => 'c', -d => '', --f => '', --h => '', --i => 'j', command => undef, parameters => ['e', 'g', 'k', 'l'], late_parameters => ['m', 'n'] }
if optionAtAll is off, return value:
{ -a => '', -b => 'c', -d => '', command => 'e', parameters => ['--f', 'g', '--h', '--i=j', 'k', 'l', '--','m', 'n'], late_parameters => [] }
## whereis($name, $path)
**whereisBin($name, $path)** _OBSOLETE_
searches valid binary in search path
$name: _binary name_
$path: _search path, by default "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"_
return value: _array of binary path founded in search path_
## file\_cache($tag, $expiry, $coderef)
**fileCache($tag, $expiry, $coderef)** _OBSOLETE_
gets most recent cached value in file cache by given tag and caller function if there is cached value in expiry period. Otherwise tries to get current value using $coderef, puts value in cache and cleanups old cache values.
$tag: _tag for cache_
$expiry: _cache expiry period_
> <0: _always gets most recent cached value if there is any cached value. Otherwise tries to get current value using $coderef, puts and cleanups._
>
> =0: _never gets cached value. Always tries to get current value using $coderef, puts and cleanups._
>
> >0: _gets most recent cached value in cache if there is cached value in expiry period. Otherwise tries to get current value using $coderef, puts and cleanups._
$coderef: _code reference to get current value_
return value: _cached or current value, otherwise undef if there isn't cached value and current value doesn't get_
## get\_pod\_text($file\_name, $section, $exclude\_section)
( run in 0.750 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )