NAME
Exodist::Util::Sub - Subroutines with advanced information attached.
DESCRIPTION
This package allows you to enhance subs such that they can be directly queried for information. You can also directly create enhanced subs.
SYNOPSYS
package MyPackage;
use strict;
use warnings;
use Exodist::Util::Sub;
esub print_hi {
print "hi\n";
}
enhanced_sub print_bye {
print "bye\n";
}
sub print_ps {
print "ps\n";
}
enhance_sub 'print_ps';
sub print_pps {
print "pps\n"
}
enhance_sub \&print_pps;
sub print_ppps {
print "ppps\n"
}
enhance_sub 'MyPackage::print_ppps';
my $code = esub {
print "code\n"
}
$code->(); # prints 'code'
print $code->start_line(); # prints the approximate line on which the sub
# definition started.
print $code->end_line(); # Same but the lane where the definition ended
(\&print_hi)->start_line();
(\&print_hi)->original_name;
(\&print_hi)->original_package;
(\&print_hi)->is_anon;
CREATING ENHANCED SUBS
esub print_hi {
print "hi\n";
}
enhanced_sub print_bye {
print "bye\n";
}
ENHANCING EXISTING SUBS
sub print_ps {
print "ps\n";
}
enhance_sub 'print_ps';
METHODS ATTACHED TO ENHANCED SUBS
- (\&sub)->start_line()
-
Get the starting line on which the sub was defined (from B)
- (\&sub)->end_line()
-
Get the last line on which the sub was defined. (Only available for subs created as enhanced.)
- (\&sub)->original_name()
-
Returns the original name given to the sub. (Only available on subs enhanced after the fact.)
- (\&sub)->is_anon()
-
Returns true if the sub was declared as an anonymous sub.
- (\&sub)->original_package()
-
Returns the name of the package in which the sub was defined.
AUTHORS
Chad Granum exodist7@gmail.com
COPYRIGHT
Copyright (C) 2010 Chad Granum
Exodist-Util is free software; Standard perl licence.
Exodist-Util is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.