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