Name
CatalystX::Usul::Functions - Globally accesible functions
Version
0.5.$Revision: 1139 $
Synopsis
package MyBaseClass;
use CatalystX::Usul::Functions;
Description
Provides global functions
Subroutines/Methods
app_prefix
$prefix = app_prefix __PACKAGE__;
Takes a class name and returns it lower cased with :: changed to _, e.g. App::Munchies
becomes app_munchies
arg_list
$args = arg_list @rest;
Returns a hash ref containing the passed parameter list. Enables methods to be called with either a list or a hash ref as it's input parameters
assert
assert $ioc_object, $condition, $message;
By default does nothing. Does not evaluate the passed parameters. The assert constant can be set via an inherited class attribute to do something useful with whatever parameters are passed to it
class2appdir
$appdir = class2appdir __PACKAGE__;
Returns lower cased "distname", e.g. App::Munchies
becomes app-munchies
create_token
$random_hex = create_token $seed;
Create a random string token using the first available Digest algorithm. If $seed
is defined then add that to the digest, otherwise add some random data. Returns a hexadecimal string
data_dumper
data_dumper $thing;
Uses Data::Printer to dump $thing
in colour to stderr
distname
$distname = distname __PACKAGE__;
Takes a class name and returns it with :: changed to -, e.g. App::Munchies
becomes App-Munchies
elapsed
$elapsed_seconds = elapsed;
Returns the number of seconds elapsed since the process started
env_prefix
$prefix = env_prefix $class;
Returns upper cased app_prefix
. Suitable as prefix for environment variables
escape_TT
$text = escape_TT q([% some_stash_key %]);
The left square bracket causes problems in some contexts. Substitute a less than symbol instead. Also replaces the right square bracket with greater than for balance. Template::Toolkit will work with these sequences too, so unescaping isn't absolutely necessary
exception
$e = exception $error;
Expose the catch
method in the exception class CatalystX::Usul::Exception. Returns a new error object
fold
*sum = fold { $a + $b } 0;
Classic reduce function with optional base value
home2appl
$appldir = home2appl $home_dir;
Strips the trailing lib/my_package
from the supplied directory path
is_arrayref
$bool = is_arrayref $scalar_variable
Tests to see if the scalar variable is an array ref
is_hashref
$bool = is_hashref $scalar_variable
Tests to see if the scalar variable is a hash ref
is_member
$bool = is_member q(test_value), qw(a_value test_value b_value);
Tests to see if the first parameter is present in the list of remaining parameters
merge_attributes
$dest = merge_attributes $dest, $src, $defaults, $attr_list_ref;
Merges attribute hashes. The $dest
hash is updated and returned. The $dest
hash values take precedence over the $src
hash values which take precedence over the $defaults
hash values. The $src
hash may be an object in which case its accessor methods are called
my_prefix
$prefix = my_prefix $PROGRAM_NAME;
Takes the basename of the supplied arg and returns the first _ (underscore) separated field
product
$product = produce( 1, 2, 3, 4 );
Returns the product of the list of numbers
say
say @lines_of_text;
Prints to STDOUT the lines of text passed to it. Lines are chomp
ed and then have newlines appended. Throws on IO errors
split_on__
$field = split_on__ $string, $field_no;
Splits string by _ (underscore) and returns the requested field. Defaults to field zero
squeeze
$string = squeeze $string_containing_muliple_spacesd);
Squeezes multiple whitespace down to a single space
strip_leader
$stripped = strip_leader q(my_program: Error message);
Strips the leading "program_name: whitespace" from the passed argument
sub_name
$sub_name = sub_name $level;
Returns the name of the method that calls it
sum
$total = sum 1, 2, 3, 4;
Adds the list of values
throw
throw error => q(error_key), args => [ q(error_arg) ];
Expose "throw" in CatalystX::Usul::Exception. CX::Usul::Functions
has a class attribute Exception_Class which can be set via a call to set_inherited
trim
$trimmed_string = trim $string_with_leading_and trailing_whitespace;
Remove leading and trailing whitespace
unescape_TT
$text = unescape_TT q(<% some_stash_key %>);
Do the reverse of escape_TT
untaint_identifier
$untainted_identifier = untaint_identifier $maybe_tainted_identifier;
Returns an untainted identifier string. Calls "untaint_string" with the matching regex from CatalystX::Usul::Constants
untaint_path
$untainted_path = untaint_path $maybe_tainted_path;
Returns an untainted file path. Calls "untaint_string" with the matching regex from CatalystX::Usul::Constants
untaint_string
$untainted_string = untaint_string $regex, $maybe_tainted_string;
Returns an untainted string or throws
Diagnostics
None
Configuration and Environment
None
Dependencies
Incompatibilities
The home2appl
method is dependent on the installation path containing a lib
Bugs and Limitations
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Author
Peter Flanigan, <Support at RoxSoft.co.uk>
License and Copyright
Copyright (c) 2012 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE