The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MRP::Introspection - powerful introspection

DESCRIPTION

Provides introspection support without you breaking strict.

SYNOPSIS

These functions perform introspection into a package to avoid you having to tamper with the symbol table directly. They use MAJOR wizardry to make sure that things behave just as you would expect. Use with caution, particularly if you use them to alter variables.

Package symbols

In a scalar context, these functions return a reference to a hash. In a list context, they return a list of key/value pairs. The keys are all of the items found in the symbol table of a given type. The values are references to these items. Call using something like:

 $arrayHash = MRP::Interface->_arrays($obj);
 print "Got ISA ", $arrayHash->{ISA}, "\n";
 %arrayHash = MRP::Interface->_functions(MyPackage);
 print "Found ISA" if exists $arrayHash{'ISA'}
_functions
_scalars
_arrays
_hashes
Accessing individual symbol table elements

These functions all return either a reference to to the item within the package or undef if it doesn't exist. For example,

 $func = MRP::Interface->_function($thingy, 'printme');

will put a reference to the function 'printme' in $func. If there is no such function within the package that $thingy is blessed into (or the package named by $thingy), then $func will be undef. These functions do not deal with inheritance. They only look in a single package.

_function
_scalar
_array
_hash
Other functions
symTable

Returns a hash ref to the symbol table of a package (or the package that an object is blessed into).

 $symTable = MRP::Introspection->symTable($obj);
ISA

Returns the @ISA array for a package or object. Returned as an array or a reference to the actual ISA array depending on wantarray.

 $isaRef = MRP::Introspection->ISA($package);
 push @$isaRef, $newBaseClass;
functionsMatching

Returns all of the functions that match a given regex.

 $sets = MRP::Introspection($package, '^set.*$'); # all the functions in
                                     # package $package matching ^set.*$
recursiveFunction

MRP::Introspection->recursiveFunction($package, $funcRef);

Recursively applies a function throughout an objects inheritance hierachy. Returns a hash or hashref of all of the function return values pre-catonated with the package name. You will have to just try this one out.

recursiveInheritance

Same as recursiveFunction, but throws away results that could not be reached because they are masked by inheritance. Again, just try it.

superAUTOLOAD

use:

  $autref = MRP::Interface->superAutoload($thisPackage, $AUTOLOAD);
  $autref->(@paramlist);

For those stickey moments when you have entered an AUTOLOAD method, but it needs to allow some superclasses AUTOLOAD to do some processing. The method sets $AUTOLOAD in the package that is first reached by inheritance that has an AUTOLOAD method, and returns a reference to that function. You just have to use the reference and pass it the relevant arguments.

AUTHOR

Matthew Pocock mrp@sanger.ac.uk