Name
CatalystX::Usul::Base - Base class utility methods
Version
0.1.$Revision: 402 $
Synopsis
package MyBaseClass;
use base qw(CatalystX::Usul::Base);
sub new {
my ($self, $app, @rest) = @_;
my $new = $self->next::method( $app, @rest );
my $app_conf = $app->config || {};
$new->debug ( $app->debug || 0 );
$new->encoding( $app_conf->{encoding} || q(UTF-8) );
$new->log ( $app->log || Class::Null->new() );
$new->tempdir ( $app_conf->{tempdir} || File::Spec->tmpdir );
return $new;
}
Description
Provides utility methods to the application base class
Subroutines/Methods
app_prefix
$prefix = $self->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 = $self->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
basename
$basename = $self->basename( $path, @suffixes );
Returns the base name of the passed path
catch
$e = $self->catch;
Expose the catch
method in the error class CatalystX::Usul::Exception
catdir
$dir_path = $self->catdir( $part1, $part2 );
Expose "catdir" in File::Spec
catfile
$file_path = $self->catfile( $dir_path, $file_name );
Expose "catfile" in File::Spec
class2appdir
$appdir = $self->class2appdir( __PACKAGE__ );
Takes a class name and returns it lower cased with :: changed to -, e.g. App::Munchies
becomes app-munchies
classfile
$path = $self->classfile( __PACKAGE__ );
Returns the path/file name plus extension of a given class. Uses File::Spec for portability, e.g. App::Munchies
becomes App/Munchies.pm
create_token
$random_hex = $self->create_token( $seed );
Create a random string token using the first available Digest algorithmn. If $seed
is defined then add that to the digest, otherwise add some random data. Returns a hexadecimal string
delete_tmp_files
$self->delete_tmp_files( $dir );
Delete this processes temporary files. Files are in the $dir
directory which defaults to $self->tempdir
dirname
$dirname = $self->dirname( $path );
Returns the directory name of the passed path
ensure_class_loaded
$self->ensure_class_loaded( $some_class );
Require the requested class, throw an error if it doesn't load
env_prefix
$prefix = $self->env_prefix( $class );
Returns upper cased app_prefix
. Suitable as prefix for environment variables
escape_TT
$text = $self->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
find_source
$path = $self->find_source( $module_name );
Find the source code for the given module
home2appl
$appldir = $self->home2appl( $home_dir );
Strips the trailing lib/my_package
from the supplied directory path
io
$io_obj = $self->io( $pathname );
Expose the methods in CatalystX::Usul::File::IO
is_member
$bool = $self->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
load_component
$self->load_component( $child, @parents );
Ensures that each component is loaded then fixes @ISA for the child so that it inherits from the parents
nap
$self->nap( $time_in_seconds );
Exposes the nap method which sleeps for (possibly fractional) periods of time
stamp
$time_date_string = $self->stamp( $time );
Exposes the stamp method which returns an ISO format date/time string. Defaults to the current time if $time
is omitted
status_for
$stat_ref = $self->status_for( $path );
Return a hash for the given path containing it's inode status information
str2date_time
$date_time_obj = $self->str2date_time( $date_time_string );
Exposes the str2date_time method which returns a DateTime object representing the supplied date/time string
str2time
$seconds = $self->str2time( $date_time_string );
Exposes str2time method which returns the number of seconds elapsed since the epoch for the supplied date/time string
strip_leader
$stripped = $self->strip_leader( q(my_program: Error message) );
Strips the leading "program_name: whitespace" from the passed argument
sub_name
$sub_name = $self->sub_name( $level );
Returns the name of the method that calls it
supports
$bool = $self->supports( @spec );
Returns true if the hash returned by our get_features attribute contains all the elements of the required specification
tempfile
$tempfile_obj = $self->tempfile( $dir );
Returns a File::Temp object in the $dir
directory which defaults to $self->tempdir
. File is automatically deleted if the $tempfile_obj
reference goes out of scope
tempname
$pathname = $self->tempname( $dir );
Returns the pathname of a temporary file in the given directory which defaults to $self->tempdir
. The file will be deleted by "delete_tmp_files" if it is called otherwise it will persist
throw
$self->throw( error => q(error_key), arg1 => q(error_arg) );
Expose the throw
method in the error class CatalystX::Usul::Exception
time2str
$date_time_string = $self->time2str( $format, $time );
Returns a date time string in the specified format
unescape_TT
$text = $self->unescape_TT( q(<% some_stash_key %>) );
Do the reverse of escape_TT
uuid
$uuid = $self->uuid;
Return the contents of /proc/sys/kernel/random/uuid
Diagnostics
None
Configuration and Environment
None
Dependencies
- CatalystX::Usul::Encoding
- CatalystX::Usul::Exception
- CatalystX::Usul::File::IO
- Class::Accessor::Fast
- Class::Accessor::Grouped
- Class::Inspector
- Digest
- File::Temp
- List::Util
- Path::Class::Dir
Incompatibilities
The home2appl
method is dependent on the installation path containing a lib
The /uuid
method with only work on a OS with a /proc filesystem
Bugs and Limitations
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
TODO
The load_components/ensure_class_loaded and delete_tmp_file/tempfile methods have side effects (nap and throw are also suspect). These prevent this class from containing only functions
Author
Peter Flanigan, <Support at RoxSoft.co.uk>
License and Copyright
Copyright (c) 2008 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