Debian Codegraph @

bin/pmexp

raw
1 #!/usr/bin/env perl
2 # pmexp -- show a module's exports
3
4 # ------ pragmas
5 use strict;
6 use warnings;
7
8 our $VERSION = '2.0.0';
9
10 # ------ define variables
11 my $errors = 0; # error count
12 my @list = (); # list of module exports
13 my $module = undef; # module name
14 my %table = (); # module export tags
15 my $tag = undef; # module export tag
16
17 BEGIN { $^W = 1 }
18 BEGIN { die "usage: $0 module ...\n" unless @ARGV }
19
20 $errors = 0;
21
22 for $module (@ARGV) {
23 eval "local \$^W = 0; require $module";
24 if ($@) {
25 $@ =~ s/at \(eval.*$//;
26 warn "$0: $@";
27 $errors++;
28 next;
29 }
30
31 no strict 'refs';
32 if (@list = @{ $module . "::EXPORT" } ) {
33 use strict 'refs';
34 print "$module automatically exports ",
35 commify_series(@list), "\n";
36 }
37 if (@list = @{ $module . "::EXPORT_OK" } ) {
38 print "$module optionally exports ",
39 commify_series(@list), "\n";
40 }
41 if (%table = %{ $module . "::EXPORT_TAGS" } ) {
42 for $tag (sort keys %table) {
43 print "$module export tag '$tag' includes ", commify_series(@{$table{$tag}}), "\n";
44 }
45 }
46 }
47
48 exit($errors != 0);
49
50
51 sub commify_series {
52 (@_ == 0) ? '' :
53 (@_ == 1) ? $_[0] :
54 (@_ == 2) ? join(" and ", @_) :
55 join(", ", @_[0 .. ($#_-1)], "and $_[-1]");
56 }
57
58 __END__
59
60 =head1 NAME
61
62 pmexp - show a module's exports
63
64 =head1 DESCRIPTION
65
66 Given a module name, this program identifies which symbols are
67 automatically exported (in that package's @EXPORT), those which are
68 optionally exported (in that package's @EXPORT_OK), and also lists out
69 the import groups (in that package's %EXPORT_TAGS hash).
70
71 =head1 EXAMPLES
72
73 $ pmexp Text::ParseWords
74 Text::ParseWords automatically exports shellwords, quotewords, nested_quotewords, and parse_line
75 Text::ParseWords optionally exports old_shellwords
76
77 $ pmexp Text::Wrap
78 Text::Wrap automatically exports wrap and fill
79 Text::Wrap optionally exports $columns, $break, and $huge
80
81 $ pmexp Fcntl
82 Fcntl automatically exports FD_CLOEXEC, F_DUPFD, F_EXLCK, F_GETFD, F_GETFL, F_GETLK, F_GETLK64, F_GETOWN, F_POSIX, F_RDLCK, F_SETFD, F_SETFL, F_SETLK, F_SETLK64, F_SETLKW, F_SETLKW64, F_SETOWN, F_SHLCK, F_UNLCK, F_WRLCK, O_ACCMODE, O_APPEND, O_ASYNC, O_BINARY, O_CREAT, O_DEFER, O_DSYNC, O_EXCL, O_EXLOCK, O_LARGEFILE, O_NDELAY, O_NOCTTY, O_NONBLOCK, O_RDONLY, O_RDWR, O_RSYNC, O_SHLOCK, O_SYNC, O_TEXT, O_TRUNC, and O_WRONLY
83
84 Fcntl optionally exports FAPPEND, FASYNC, FCREAT, FDEFER, FEXCL, FNDELAY, FNONBLOCK, FSYNC, FTRUNC, LOCK_EX, LOCK_NB, LOCK_SH, and LOCK_UN
85 Fcntl export tag 'Fcompat' includes FAPPEND, FASYNC, FCREAT, FDEFER, FEXCL, FNDELAY, FNONBLOCK, FSYNC, and FTRUNC
86 Fcntl export tag 'flock' includes LOCK_SH, LOCK_EX, LOCK_NB, and LOCK_UN
87
88 =head1 BUGS
89
90 The output formatting should be nicer, perhaps using
91 C<format> and C<write>.
92
93 =head1 SEE ALSO
94
95 pmeth(1), perlmod(1), Exporter(3).
96
97 =head1 AUTHORS and COPYRIGHTS
98
99 Copyright (C) 1999 Tom Christiansen.
100
101 Copyright (C) 2006-2014, 2018 Mark Leighton Fisher.
102
103 =head1 LICENSE
104
105 This is free software; you can redistribute it and/or modify it
106 under the terms of either:
107 (a) the GNU General Public License as published by the Free
108 Software Foundation; either version 1, or (at your option) any
109 later version, or
110 (b) the Perl "Artistic License".
111 (This is the Perl 5 licensing scheme.)
112
113 Please note this is a change from the
114 original pmtools-1.00 (still available on CPAN),
115 as pmtools-1.00 were licensed only under the
116 Perl "Artistic License".