XAS::Utils - A Perl extension for the XAS environment
use XAS::Class version => '0.01', base => 'XAS::Base', utils => 'db2dt dt2db' ; printf("%s\n", dt2db($dt));
This module provides utility routines that can by loaded into your current namespace.
This method is used to validate parameters. Internally this uses Params::Validate::validate_with() for the parameter validation.
By convention, all named parameters have a leading dash. This method will strip off that dash and lower case the parameters name.
If an validation exception is thrown, the parameter name will have the dash stripped.
Based on the $spec, this can return an array or a hashref of validated parameters and values.
An array ref to a set of parameters.
A validation spec as defined by Params::Validate.
An optional class that is calling this method. If one is not provided then caller() is used to determine the calling method.
This is a package level sub routine. It exists to provide a uniform exception error message. It takes these parameters:
The error message returned by Params::Validate.
The routine that the error occurred in.
This routine will take a date format of YYYY-MM-DD HH:MM:SS and convert it into a DateTime object.
This routine will take a DateTime object and convert it into the following string: YYYY-MM-DD HH:MM:SS
Trim the whitespace from the beginning and end of $string.
Trim the whitespace from the end of $string.
Trim the whitespace from the beginning of $string.
Reduces multiple whitespace to a single space in $string.
Return the left chunk of $string up to $offset. Useful for porting VBS code. Makes allowances that VBS strings are ones based while Perls are zero based.
Return the right chunk of $string starting at $offset. Useful for porting VBS code. Makes allowances that VBS strings are ones based while Perls are zero based.
Return the chunk of $string starting at $offset for $length characters. Useful for porting VBS code. Makes allowances that VBS strings are ones based while Perls are zero based.
Return the position in $string of $compare. You may offset within the string with $start. Useful for porting VBS code. Makes allowances that VBS strings are one based while Perls are zero based.
Break up a "CamelCase" string into a "camel_case" string. The opposit of camel_case() from Badger::Utils.
Decodes Perls version of the exit code from a cli process. Returns three items.
Example: my @output = `ls -l`; my ($rc, $sig, $cored) = exitcode();
Run a command and capture the output, exit code and exit signal, stderr is merged with stdout.
Example: my ($output, $rc, $sig) = run_cmd("ls -l"); if ($rc == 0) { foreach my $line (@$output) { print $line; } }
Become a daemon. This will set the process as a session lead, change to '/', clear the protection mask and redirect stdin, stdout and stderr to /dev/null.
This method will take a shell glob pattern and convert it into a Perl regex. This also works with DOS/Windows wildcards.
The wildcard to convert.
This routine will walk a HOH and does a callback on the key/values that are found. It takes these parameters:
The hashref of the HOH.
An arrayref of the key levels.
The routine to call with these parameters:
The current hash key.
The value of that key.
A list of the key depth.
This will walk a directory structure and execute a callback for the found files. It takes these parameters:
The root directory to start from.
A compiled regex to compare files against.
The callback to execute when matching files are found.
This routine will load a module.
The name of the module.
This will convert the numeric process status to a text string.
A number between 0 and 6.
0 = 'unknown' 1 = 'other' 2 = 'ready' 3 = 'running' 4 = 'blocked' 5 = 'suspended blocked' 6 = 'suspended ready'
This will convert a XAS log level to an appropriate syslog priority.
A XAS log level, it should be lower cased.
info = 'info', error = 'err', warn = 'warning', fatal = 'alert', trace = 'notice', debug = 'debug'
Remove all items from the $ENV variable and store them in a hash variable.
Example: my $env = env_store();
Remove all items from $ENV variable and restore it back to a saved hash variable.
Example: env_restore($env);
Store all the items from a hash variable into the $ENV varable.
Example: env_create($env);
Take a formatted string and parse it into a hash variable. The string must have this format: "item=value;;item2=value2";
Example: my $string = "item=value;;item2=value2"; my $env = env_parse($string); env_create($env);
Take the items from the current $ENV variable and create a formatted string.
Example: my $string = env_dump(); my $env = env_create($string);
Kevin L. Esteb, <kevin@kesteb.us>
Copyright (c) 2012-2015 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.
To install XAS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XAS
CPAN shell
perl -MCPAN -e shell install XAS
For more information on module installation, please visit the detailed CPAN module installation guide.