NAME
Class::ReluctantORM::Utilities - Utility subroutines
SYNOPSIS
use Class::ReluctantORM::Utilities qw(:all);
install_method('Some::Class', 'method_name', $coderef);
conditional_load('Class::Name');
# Look for and load all modules under the location of Super::Class
# (handy for loading driver subclasses)
BEGIN {
@classes = conditional_load_subdir('Super::Class');
}
DESCRIPTION
An uncohesive set of utility methods. Several are for test manipulation; some are for class loading or interface manipulation.
No subroutines are exported by default, but all are available by request.
SUBROUTINES
install_method('Class', 'method_name', $coderef, $clobber);
Installs a new method in a class. The class need not exist.
$clobber determines what to do if the named method already exists. If clobber is true, the existing method is renamed to __orig_method_name, and $coderef is installed as method_name. If clobber is false, the existing method is untouched, and the $coderef is installed as __new_method_name .
If the named method does not exist, the coderef is installed and $clobber has no effect.
install_method_generator($class, $generator)
Installs a method generator for as-needed method creation. An AUTOLOAD hook will check to see if any generator can make a method by the given name. Multuple generators can be installed for each class.
$class is a Class::ReluctantORM subclass.
$generator is a coderef. It will be called with two args: the class name, and the proposed method name. If the generator can generate a method body, it should do so, and return a coderef which will then be installed under that name. If no candidate can be created, it should return undef.
conditional_load('Class::Name');
Loads Class::Name if it hasn't already been loaded.
@classes = conditional_load_subdir('Super::Class', $depth);
Finds Super::Class on the filesystem, then looks for and loads all modules Super/Class/*.pm If $depth is present, directories are searched up to $depth deep (so $depth =2 gives Super/Class/*.pm Super/Class/*/*.pm Super/Class/*/*/*.pm)
It's best to call this from within a BEGIN block, if you are trying to find driver modules.
Returns a list of loaded classes.
%args = check_args(%opts);
Given the args list (which is assumed to have $self or $class already shifted off), check the args list for required, optional, and mutually exclusive options.
- args => [] or args => {} (required)
-
If a arrayref, checks to make sure it is even-numbered. If a hashref, used as-is.
- required => []
-
List of args that are required.
- optional => []
-
List of args that are permitted but optional.
- mutex => [ \@set1, \@set2, ...]
-
Listref of listrefs. Each inner listref is a set of parameters that is mutually exclusive, that is, AT MOST one the params may appear.
- one_of => [ \@set1, \@set2, ...]
-
Like mutex, but EXACTLY ONE of the params of each set must appear.
- frames => 2
-
When throwing an exception, the number of frames to jump back. Default is 2.
$usc = camel_case_to_underscore_case($camelCaseString);
Converts a string in camel case (LikeThis) to one in underscore case (like_this).
my $plural = pluralize($singular);
Returns the plural form of a word.
$output = nz($input, $output_if_undef);
If $input is defined, $outout = $input.
If $input is undef, $output = $output_if_undef.
Named after the same function in Visual Basic, where all good ideas originate.
$bool = array_shallow_eq($ary1, $ary2);
Returns true if the arrays referred to by the arrayrefs $ary1 and $ary2 are identical in a shallow sense, using 'eq'.
$info = last_non_cro_stack_frame();
@frames = last_non_cro_stack_frame();
Returns information about the the last call stack frame outside of Class::ReluctantORM.
In scalar context, returns only the last call frame. In list context, returns the last stack frame and up.
$info will contain keys 'file', 'package', 'line', and 'frames'. Frames indicates the value passed to caller() to obtain the information, which is the number of frames to unwind.
$int = row_size($hashref);
Calculates the size, in bytes, of the values of the given hashref. This is used by the RowSize and QuerySize Monitors.
deprecated($message);
read_file($filename)
File::Slurp::read_file workalike, but far crappier.
write_file($filename, $content)
File::Slurp::write_file workalike, but far crappier.
$json_string = json_encode($perl_ref);
Version-blind JSON encoder.
$perl_ref = json_decode($json_string);
Version-blind JSON decoder.