File: pmfunc

package info (click to toggle)
pmtools 1.10%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 188 kB
  • ctags: 14
  • sloc: perl: 505; makefile: 11
file content (85 lines) | stat: -rwxr-xr-x 1,859 bytes parent folder | download
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
#!/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".