Debian Codegraph @

bin/pmdesc

raw
1 #!/usr/bin/env perl
2 # pmdesc -- show NAME section
3
4 # ------ pragmas
5 use strict;
6 use warnings;
7 use FindBin qw($Bin);
8 use Getopt::Long;
9
10 our $VERSION = '2.1.0';
11
12 # ------ define variables
13 my $errors; # error count
14 my $fullpath; # full module path
15 my $module; # module name
16 my $use_pod; # use .pod instead of .pm file for systems with split POD/pm
17 my $vers; # module version
18
19 BEGIN { $^W = 1 }
20
21 GetOptions ("splitpod" => \$use_pod);
22
23 $errors = 0;
24
25 MODULE: for $module (@ARGV) {
26 if ($use_pod) {
27 $fullpath = `$^X $Bin/podpath $module`;
28 } else {
29 $fullpath = `$^X $Bin/pmpath $module`;
30 }
31 if ($?) {
32 $errors++;
33 next;
34 }
35 chomp $fullpath;
36 unless (open(POD, "< $fullpath")) {
37 warn "$0: cannot open $fullpath: $!";
38 $errors++;
39 next;
40 }
41
42 local $/ = '';
43 local $_;
44 while (<POD>) {
45 if (/=head\d\s+NAME/) {
46 chomp($_ = <POD>);
47 s/^.*?-\s+//s;
48 s/\n/ /g;
49 #write;
50 my $v;
51 if (defined ($vers = getversion($module))) {
52 print "$module ($vers) ";
53 } else {
54 print "$module ";
55 }
56 print "- $_\n";
57
58 next MODULE;
59 }
60 }
61 print "no description found\n";
62 $errors++;
63 }
64
65 sub getversion {
66 my $module = shift;
67
68 my $vers;
69 if ( $^O eq "MSWin32" ) {
70 $vers = `$^X -S $Bin/pmvers $module 2>NUL`;
71 } else {
72 $vers = `$^X -S $Bin/pmvers $module 2>/dev/null`;
73 }
74 return if $?;
75 chomp $vers;
76 return $vers;
77 }
78
79 exit ($errors != 0);
80
81 __END__
82
83 =head1 NAME
84
85 pmdesc - print out version and whatis description of perl modules
86
87 =head1 DESCRIPTION
88
89 Given one or more module names, show the version number (if known)
90 and the 'whatis' line, that is, the NAME section's description,
91 typically used for generation of whatis databases.
92
93 =head1 EXAMPLES
94
95 $ pmdesc IO::Socket
96 IO::Socket (1.25) - Object interface to socket communications
97
98 $ oldperl pmdesc IO::Socket
99 IO::Socket (1.1603) - Object interface to socket communications
100
101 $ pmdesc `pminst -s | perl -lane 'print $F[1] if $F[0] =~ /site/'`
102 XML::Parser::Expat (2.19) - Lowlevel access to James Clark's expat XML parser
103 XML::Parser (2.19) - A perl module for parsing XML documents
104
105 =head1 RESTRICTIONS
106
107 This only works on modules. It should also work on filenames, but then
108 it's a bit tricky finding out the package to call the VERSION method on.
109
110 =head1 SEE ALSO
111
112 pmdesc(1)
113 pminst(1)
114 pmpath(1)
115 pmvers(1)
116
117 =head1 AUTHORS and COPYRIGHTS
118
119 Copyright (C) 1999 Tom Christiansen.
120
121 Copyright (C) 2006-2014, 2018 Mark Leighton Fisher.
122
123 =head1 LICENSE
124
125 This is free software; you can redistribute it and/or modify it
126 under the terms of either:
127 (a) the GNU General Public License as published by the Free
128 Software Foundation; either version 1, or (at your option) any
129 later version, or
130 (b) the Perl "Artistic License".
131 (This is the Perl 5 licensing scheme.)
132
133 Please note this is a change from the
134 original pmtools-1.00 (still available on CPAN),
135 as pmtools-1.00 were licensed only under the
136 Perl "Artistic License".