MRP::Introspection - powerful introspection
Provides introspection support without you breaking strict.
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.
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'}
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.
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);
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;
Returns all of the functions that match a given regex.
$sets = MRP::Introspection($package, '^set.*$'); # all the functions in # package $package matching ^set.*$
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.
Same as recursiveFunction, but throws away results that could not be reached because they are masked by inheritance. Again, just try it.
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.
Matthew Pocock mrp@sanger.ac.uk
To install MRP::Text, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MRP::Text
CPAN shell
perl -MCPAN -e shell install MRP::Text
For more information on module installation, please visit the detailed CPAN module installation guide.