#!/usr/bin/env perl
# pmfunc -- show a function
# tchrist@perl.com
BEGIN { $^W = 1 }
BEGIN { die "usage: $0 module ...\n" unless @ARGV }
use FindBin qw($Bin);
$errors = 0;
for $arg (@ARGV) {
my($module, $function) = $arg =~ /(\w.*)::(\w+)$/;
$file = `$^X -S $Bin/pmpath $module`;
if ($?) {
$errors++;
next;
}
chomp $file;
system $^X, '-ne',
'$ok++,print if /^sub\s+' . $function . '\b/ .. /^}\s*$/;'
. ' END { $? = ($ok == 0) }',
$file;
$errors++ if $?;
}
exit ($errors != 0);
__END__
=head1 NAME
pmfunc - cat out a function from a module
=head1 DESCRIPTION
Given a fully-qualified function, this program opens
up the file and attempts to cat out the source for
that function.
=head1 EXAMPLES
$ pmfunc Cwd::getcwd
sub getcwd
{
abs_path('.');
}
=head1 RESTRICTIONS
Only subroutines that are defined in the normal fashion are seen, since
a simple pattern-match is what does the extraction. Those loaded other
ways, such as via AUTOLOAD, typeglob aliasing, or in an C<eval>, will
all necessarily be missed.
This is mostly here for people who are too lazy to type
sed '/^sub getcwd/,/}/p' `pmpath Cwd`
or
perl -ne 'print if /^sub\s+getcwd\b/ .. /}/' `pmpath Cwd`
=head1 RESTRICTIONS
=head1 SEE ALSO
=head1 AUTHORS and COPYRIGHTS
Copyright (C) 1999 Tom Christiansen.
Copyright (C) 2006-2008 Mark Leighton Fisher.
This is free software; you can redistribute it and/or modify it
under the terms of either:
(a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
(b) the Perl "Artistic License".
(This is the Perl 5 licensing scheme.)
Please note this is a change from the
original pmtools-1.00 (still available on CPAN),
as pmtools-1.00 were licensed only under the
Perl "Artistic License".