Add built local::lib
[catagits/Gitalist.git] / local-lib5 / bin / corelist
1 #!/usr/bin/perl
2
3 eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
4     if 0; # not running under some shell
5
6 =head1 NAME
7
8 corelist - a commandline frontend to Module::CoreList
9
10 =head1 DESCRIPTION
11
12 See L<Module::CoreList> for one.
13
14 =head1 SYNOPSIS
15
16     corelist -v
17     corelist [-a|-d] <ModuleName> | /<ModuleRegex>/ [<ModuleVersion>] ...
18     corelist [-v <PerlVersion>] [ <ModuleName> | /<ModuleRegex>/ ] ...
19
20 =head1 OPTIONS
21
22 =over
23
24 =item -a
25
26 lists all versions of the given module (or the matching modules, in case you
27 used a module regexp) in the perls Module::CoreList knows about.
28
29     corelist -a utf8
30
31     utf8 was first released with perl 5.006
32       5.006      undef
33       5.006001   undef
34       5.006002   undef
35       5.007003   1.00
36       5.008      1.00
37       5.008001   1.02
38       5.008002   1.02
39       5.008003   1.02
40       5.008004   1.03
41       5.008005   1.04
42       5.008006   1.04
43       5.008007   1.05
44       5.008008   1.06
45       5.009      1.02
46       5.009001   1.02
47       5.009002   1.04
48       5.009003   1.06
49
50 =item -d
51
52 finds the first perl version where a module has been released by
53 date, and not by version number (as is the default).
54
55 =item -? or -help
56
57 help! help! help! to see more help, try --man.
58
59 =item -man
60
61 all of the help
62
63 =item -v
64
65 lists all of the perl release versions we got the CoreList for.
66
67 If you pass a version argument (value of C<$]>, like C<5.00503> or C<5.008008>),
68 you get a list of all the modules and their respective versions.
69 (If you have the C<version> module, you can also use new-style version numbers,
70 like C<5.8.8>.)
71
72 In module filtering context, it can be used as Perl version filter.
73
74 =back
75
76 As a special case, if you specify the module name C<Unicode>, you'll get
77 the version number of the Unicode Character Database bundled with the
78 requested perl versions.
79
80 =cut
81
82 use Module::CoreList;
83 use Getopt::Long;
84 use Pod::Usage;
85 use strict;
86 use warnings;
87
88 my %Opts;
89
90 GetOptions(\%Opts, qw[ help|?! man! v|version:f a! d ] );
91
92 pod2usage(1) if $Opts{help};
93 pod2usage(-verbose=>2) if $Opts{man};
94
95 if(exists $Opts{v} ){
96     if( !$Opts{v} ) {
97         print "\nModule::CoreList has info on the following perl versions:\n";
98         print "$_\n" for sort keys %Module::CoreList::version;
99         print "\n";
100         exit 0;
101     }
102
103     $Opts{v} = numify_version( $Opts{v} );
104     my $version_hash = Module::CoreList->find_version($Opts{v});
105     if( !$version_hash ) {
106         print "\nModule::CoreList has no info on perl v$Opts{v}\n\n";
107         exit 1;
108     }
109
110     if ( !@ARGV ) {
111         print "\nThe following modules were in perl v$Opts{v} CORE\n";
112         print "$_ ", $version_hash->{$_} || " ","\n"
113         for sort keys %$version_hash;
114         print "\n";
115         exit 0;
116     }
117 }
118
119 if ( !@ARGV ) {
120     pod2usage(0);
121 }
122
123 while (@ARGV) {
124         my ($mod, $ver);
125         if ($ARGV[0] =~ /=/) {
126             ($mod, $ver) = split /=/, shift @ARGV;
127         } else {
128             $mod = shift @ARGV;
129             $ver = (@ARGV && $ARGV[0] =~ /^\d/) ? shift @ARGV : "";
130         }
131
132         if ($mod !~ m|^/(.*)/([imosx]*)$|) { # not a regex
133             module_version($mod,$ver);
134         } else {
135             my $re;
136             eval { $re = $2 ? qr/(?$2)($1)/ : qr/$1/; }; # trap exceptions while building regex
137             if ($@) {
138                 # regex errors are usually like 'Quantifier follow nothing in regex; marked by ...'
139                 # then we drop text after ';' to shorten message
140                 my $errmsg = $@ =~ /(.*);/ ? $1 : $@;
141                 warn "\n$mod  is a bad regex: $errmsg\n";
142                 next;
143             }
144             my @mod = Module::CoreList->find_modules($re);
145             if (@mod) {
146                 module_version($_, $ver) for @mod;
147             } else {
148                 $ver |= '';
149                 print "\n$mod $ver has no match in CORE (or so I think)\n";
150             }
151
152         }
153 }
154
155 exit();
156
157 sub module_version {
158     my($mod,$ver) = @_;
159
160     if ( $Opts{v} ) {
161         my $version_hash = Module::CoreList->find_version($Opts{v});
162         if ($version_hash) {
163             print $mod, " ", $version_hash->{$mod} || 'undef', "\n";
164             return;
165         }
166         else { die "Shouldn't happen" }
167     }
168
169     my $ret = $Opts{d}
170         ? Module::CoreList->first_release_by_date(@_)
171         : Module::CoreList->first_release(@_);
172     my $msg = $mod;
173     $msg .= " $ver" if $ver;
174
175     if( defined $ret ) {
176         $msg .= " was ";
177         $msg .= "first " unless $ver;
178         $msg .= "released with perl $ret"
179     } else {
180         $msg .= " was not in CORE (or so I think)";
181     }
182
183     print "\n",$msg,"\n";
184
185     if(defined $ret and exists $Opts{a} and $Opts{a}){
186         for my $v(
187             sort keys %Module::CoreList::version ){
188
189             printf "  %-10s %-10s\n",
190                 $v,
191                 $Module::CoreList::version{$v}{$mod}
192                     || 'undef'
193                     if exists $Module::CoreList::version{$v}{$mod};
194         }
195         print "\n";
196     }
197 }
198
199 sub numify_version {
200     my $ver = shift;
201     if ($ver =~ /\..+\./) {
202         eval { require version ; 1 }
203             or die "You need to install version.pm to use dotted version numbers\n";
204         $ver = version->new($ver)->numify;
205     }
206     $ver += 0;
207     return $ver;
208 }
209
210 =head1 EXAMPLES
211
212     $ corelist File::Spec
213
214     File::Spec was first released with perl 5.005
215
216     $ corelist File::Spec 0.83
217
218     File::Spec 0.83 was released with perl 5.007003
219
220     $ corelist File::Spec 0.89
221
222     File::Spec 0.89 was not in CORE (or so I think)
223
224     $ corelist File::Spec::Aliens
225
226     File::Spec::Aliens  was not in CORE (or so I think)
227
228     $ corelist /IPC::Open/
229
230     IPC::Open2 was first released with perl 5
231
232     IPC::Open3 was first released with perl 5
233
234     $ corelist /MANIFEST/i
235
236     ExtUtils::Manifest was first released with perl 5.001
237
238     $ corelist /Template/
239
240     /Template/  has no match in CORE (or so I think)
241
242     $ corelist -v 5.8.8 B
243
244     B                        1.09_01
245
246     $ corelist -v 5.8.8 /^B::/
247
248     B::Asmdata               1.01
249     B::Assembler             0.07
250     B::Bblock                1.02_01
251     B::Bytecode              1.01_01
252     B::C                     1.04_01
253     B::CC                    1.00_01
254     B::Concise               0.66
255     B::Debug                 1.02_01
256     B::Deparse               0.71
257     B::Disassembler          1.05
258     B::Lint                  1.03
259     B::O                     1.00
260     B::Showlex               1.02
261     B::Stackobj              1.00
262     B::Stash                 1.00
263     B::Terse                 1.03_01
264     B::Xref                  1.01
265
266 =head1 COPYRIGHT
267
268 Copyright (c) 2002-2007 by D.H. aka PodMaster
269
270 Currently maintained by the perl 5 porters E<lt>perl5-porters@perl.orgE<gt>.
271
272 This program is distributed under the same terms as perl itself.
273 See http://perl.org/ or http://cpan.org/ for more info on that.
274
275 =cut