#!/usr/bin/perl
use strict;
no strict 'refs';
use warnings;
use Getopt::Long qw( GetOptions :config pass_through );
use B qw( walksymtable svref_2object );
use B::Concise;
GetOptions( 'root=s' => \my($root),
'rx=s' => \my($rx),
help => sub { pod2usage( -verbose => 1 ) },
man => sub { pod2usage( -verbose => 2 ) } )
or pod2usage( -verbose => 0 );
if ( not keys %{ $root . '::' } ) {
die "NAMESPACE $root doesn't seem to exist.\n";
}
if ( defined $rx ) {
$rx = qr/$rx/;
}
walksymtable( \%{ "${root}::" },
'concise_cv',
( defined $rx ? \®EX_RECURSE : \&ALWAYS_RECURSE ),
"${root}::");
exit;
sub ALWAYS_RECURSE { 1 }
sub REGEX_RECURSE { shift( @_ ) =~ $rx }
sub B::GV::concise_cv {
my $gv = shift @_;
my $name = $gv->STASH->NAME . '::' . $gv->NAME;
$name =~ s/^main:://;
return unless defined &$name;
my $code = \&$name;
return unless ${ svref_2object($code)->START };
print "$name\n";
B::Concise::compile( @ARGV, \&$name )->();
print "\n";
}
__END__
=head1 NAME
decompile-perl
=head1 SYNOPSIS
decompile-perl --root NAMESPACE
Options:
--root NAMESPACE TO WALK
--rx
|