NAME

XAS::Utils - A Perl extension for the XAS environment

SYNOPSIS

use XAS::Class
  version => '0.01',
  base    => 'XAS::Base',
  utils   => 'db2dt dt2db'
;

printf("%s\n", dt2db($dt));

DESCRIPTION

This module provides utility routines that can by loaded into your current namespace.

METHODS

db2dt($datestring)

This routine will take a date format of YYYY-MM-DD HH:MM:SS and convert it into a DateTime object.

dt2db($datetime)

This routine will take a DateTime object and convert it into the following string: YYYY-MM-DD HH:MM:SS

trim($string)

Trim the whitespace from the beginning and end of $string.

ltrim($string)

Trim the whitespace from the end of $string.

rtrim($string)

Trim the whitespace from the beginning of $string.

compress($string)

Reduces multiple whitespace to a single space in $string.

left($string, $offset)

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.

right($string, $offset)

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.

mid($string, $offset, $length)

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.

instr($start, $string, $compare)

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.

spawn

Run a cli command with timeout. Returns output from that command.

-command

The command string to run.

-timeout

An optional timeout in seconds. Default is none.

exitcode

Decodes Perls version of the exit code from a cli process. Returns two items.

Example:

    my @output = spawn(-command => "ls -l");
    my ($rc, $sig) = exitcode();

run_cmd($command)

Run a command and capture the output and exit code, stderr is merged with stdout.

Example:

    my (@output, $rc) = run_cmd("ls -l");

daemonize

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.

glob2regx($glob)

This method will take a shell glob pattern and convert it into a Perl regex. This also works with DOS/Windows wildcards.

$glob

The wildcard to convert.

hash_walk

This routine will walk a HOH and does a callback on the key/values that are found. It takes these parameters:

-hash

The hashref of the HOH.

-keys

An arrayref of the key levels.

-callback

The routine to call with these parameters:

$key

The current hash key.

$value

The value of that key.

$key_list

A list of the key depth.

dir_walk

This will walk a directory structure and execute a callback for the found files. It takes these parameters:

-directory

The root directory to start from.

-filter

A compiled regex to compare files against.

-callback

The callback to execute when matching files are found.

init_module($module, $options)

This routine will load and initialize a module. It takes one required parameter and one optinal parameter.

$module

The name of the module.

$options

A hashref of optional options to use with the module.

load_module($module)

This routine will load a module.

$module

The name of the module.

env_store

Remove all items from the $ENV variable and store them in a hash variable.

Example:
  my $env = env_store();

env_restore

Remove all items from $ENV variable and restore it back to a saved hash variable.

Example:
  env_restore($env);

env_create

Store all the items from a hash variable into the $ENV varable.

Example:
  env_create($env);

env_parse

Take a formated 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);

env_dump

Take the items from the current $ENV variable and create a formated string.

Example:
  my $string = env_dump();
  my $env = env_create($string);

SEE ALSO

XAS
Badger::Utils

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (C) 2014 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.