| CatalystX-Usul documentation | view source | Contained in the CatalystX-Usul distribution. |
CatalystX::Usul::Base - Base class utility methods
0.3.$Revision: 611 $
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;
}
Provides utility methods to the application base class
$prefix = $self->app_prefix( __PACKAGE__ );
Takes a class name and returns it lower cased with :: changed to
_, e.g. App::Munchies becomes app_munchies
$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 = $self->basename( $path, @suffixes );
Returns the base name of the passed path
$e = $self->catch;
Expose the catch method in the error class CatalystX::Usul::Exception
$dir_path = $self->catdir( $part1, $part2 );
Expose catdir in File::Spec
$file_path = $self->catfile( $dir_path, $file_name );
Expose catfile in File::Spec
$appdir = $self->class2appdir( __PACKAGE__ );
Returns lower cased distname, e.g. App::Munchies becomes
app-munchies
$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
$random_hex = $self->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
$self->delete_tmp_files( $dir );
Delete this processes temporary files. Files are in the $dir directory
which defaults to $self->tempdir
$dirname = $self->dirname( $path );
Returns the directory name of the passed path
$distname = $self->distname( __PACKAGE__ );
Takes a class name and returns it with :: changed to
-, e.g. App::Munchies becomes App-Munchies
$self->ensure_class_loaded( $some_class );
Require the requested class, throw an error if it doesn't load
$prefix = $self->env_prefix( $class );
Returns upper cased app_prefix. Suitable as prefix for environment
variables
$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
Return the exception class. Used by the action class to process exceptions
$path = $self->find_source( $module_name );
Find the source code for the given module
$appldir = $self->home2appl( $home_dir );
Strips the trailing lib/my_package from the supplied directory path
$io_obj = $self->io( $pathname );
Expose the methods in CatalystX::Usul::File::IO
$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
$self->load_component( $child, @parents );
Ensures that each component is loaded then fixes @ISA for the child so that it inherits from the parents
$self->nap( $time_in_seconds );
Exposes the nap method which sleeps for (possibly fractional) periods of time
$self->say( @lines_of_text );
Prints to STDOUT the lines of text passed to it. Lines are chomped
and then have newlines appended. Throws on IO errors
$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
$stat_ref = $self->status_for( $path );
Return a hash for the given path containing it's inode status information
$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
$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
$stripped = $self->strip_leader( q(my_program: Error message) );
Strips the leading "program_name: whitespace" from the passed argument
$sub_name = $self->sub_name( $level );
Returns the name of the method that calls it
$bool = $self->supports( @spec );
Returns true if the hash returned by our get_features attribute contains all the elements of the required specification
$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
$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
$self->throw( error => q(error_key), args => [ q(error_arg) ] );
Expose the throw method in the error class CatalystX::Usul::Exception
$date_time_string = $self->time2str( $format, $time );
Returns a date time string in the specified format
$text = $self->unescape_TT( q(<% some_stash_key %>) );
Do the reverse of escape_TT
$uuid = $self->uuid;
Return the contents of /proc/sys/kernel/random/uuid
None
None
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
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
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
Peter Flanigan, <Support at RoxSoft.co.uk>
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
| CatalystX-Usul documentation | view source | Contained in the CatalystX-Usul distribution. |