/usr/bin/pmfunc is in pmtools 2.0.0-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #!/usr/bin/env perl
# pmfunc -- show a function
# ------ pragmas
use strict;
use warnings;
our $VERSION = '2.0';
# ------ define variables
my $errors = 0; # error count
my $file = undef; # module file path
my $function = undef; # function name
my $module = undef; # module name
my $ok = undef; # OK count
BEGIN { $^W = 1 }
BEGIN { die "usage: $0 module ...\n" unless @ARGV }
use FindBin qw($Bin);
$errors = 0;
for my $arg (@ARGV) {
($module, $function) = $arg =~ /(\w.*)::(\w+)$/;
if (!defined($module)) {
print STDERR "Sorry, '$arg' is not the name of a function in a module.\n";
next;
}
$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-2014 Mark Leighton Fisher.
=head1 LICENSE
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".
|