diff options
Diffstat (limited to 'lib/Reply/Util.pm')
-rw-r--r-- | lib/Reply/Util.pm | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/Reply/Util.pm b/lib/Reply/Util.pm index 5f22ecd..e6d193a 100644 --- a/lib/Reply/Util.pm +++ b/lib/Reply/Util.pm @@ -2,8 +2,23 @@ package Reply::Util; use strict; use warnings; +BEGIN { + if ($] < 5.010) { + require MRO::Compat; + } + else { + require mro; + } +} + +use Package::Stash; +use Scalar::Util 'blessed'; + use Exporter 'import'; -our @EXPORT_OK = qw($ident_rx $varname_rx $fq_ident_rx $fq_varname_rx); +our @EXPORT_OK = qw( + $ident_rx $varname_rx $fq_ident_rx $fq_varname_rx + methods +); # XXX this should be updated for unicode our $varstart_rx = qr/[A-Z_a-z]/; @@ -14,4 +29,24 @@ our $varname_rx = qr/$sigil_rx\s*$ident_rx/; our $fq_ident_rx = qr/$ident_rx(?:::$varcont_rx+)*/; our $fq_varname_rx = qr/$varname_rx(?:::$varcont_rx+)*/; +sub methods { + my ($invocant) = @_; + + my $class = blessed($invocant) || $invocant; + + my @mro = ( + @{ mro::get_linear_isa('UNIVERSAL') }, + @{ mro::get_linear_isa($class) }, + ); + + my @methods; + for my $package (@mro) { + my $stash = eval { Package::Stash->new($package) }; + next unless $stash; + push @methods, $stash->list_all_symbols('CODE'); + } + + return @methods; +} + 1; |