| 1 | 5 | ▶ | use 5.008; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | package Perl::PrereqScanner 1.100; | ||||||||||||
| 6 | # ABSTRACT: a tool to scan your Perl code for its prerequisites | ||||||||||||
| 7 | |||||||||||||
| 8 | 5 | ▶ | use Moo 2.000000; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 5 | ▶ | use Carp qw(confess); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 5 | ▶ | use List::Util qw(max); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 5 | ▶ | use Params::Util qw(_CLASS); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 5 | ▶ | use Perl::PrereqScanner::Scanner; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 5 | ▶ | use PPI 1.215; # module_version, bug fixes | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 5 | ▶ | use String::RewritePrefix 0.005 rewrite => { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | -as => '__rewrite_scanner', | ||||||||||||
| 17 | prefixes => { '' => 'Perl::PrereqScanner::Scanner::', '=' => '' }, | ||||||||||||
| 18 | 5 | }; | |||||||||||
| 19 | 5 | ▶ | use Types::Standard qw(ArrayRef ConsumerOf); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | |||||||||||||
| 21 | 5 | ▶ | use CPAN::Meta::Requirements 2.124; # normalized v-strings | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | |||||||||||||
| 23 | 5 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | |||||||||||||
| 25 | 5 | has scanners => ( | |||||||||||
| 26 | is => 'rwp', | ||||||||||||
| 27 | isa => ArrayRef[ConsumerOf['Perl::PrereqScanner::Scanner']], | ||||||||||||
| 28 | init_arg => undef, | ||||||||||||
| 29 | ); | ||||||||||||
| 30 | |||||||||||||
| 31 | 564 | ▶ | sub __scanner_from_str { | ||||||||||
|
Subroutine
__scanner_from_str: called CC=3 SCAR=11.4
| |||||||||||||
| 32 | 564 | my $class = __rewrite_scanner($_[0]); | |||||||||||
| 33 | 564 | ▶ | confess "illegal class name: $class" unless _CLASS($class); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 564 | ▶ | eval "require $class; 1" or die $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 564 | return $class->new; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 94 | ▶ | sub __prepare_scanners { | ||||||||||
|
Subroutine
__prepare_scanners: called CC=2 SCAR=7.0
| |||||||||||||
| 39 | 94 | my ($self, $specs) = @_; | |||||||||||
| 40 | 94 | ▶ | my @scanners = map {; ref $_ ? $_ : __scanner_from_str($_) } @$specs; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | |||||||||||||
| 42 | 94 | return \@scanners; | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 94 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||
| 46 | 94 | my ($self, $arg) = @_; | |||||||||||
| 47 | |||||||||||||
| 48 | 94 | ▶ | my @scanners = @{ $arg->{scanners} || [ qw(Perl5 Superclass TestMore Moose Aliased POE) ] }; | ||||||||||
|
Condition50%1/2
$arg->{'scanners'} || ['Perl5', 'Superclass', 'TestMore', 'Moose', 'Aliased', 'POE']
MC/DC0%0/1
$arg->{'scanners'} || ['Perl5', 'Superclass', 'TestMore', 'Moose', 'Aliased', 'POE']
$arg->{'scanners'}
Truth table50%1/2
A
A= $arg->{'scanners'}
| |||||||||||||
| 49 | 94 | ▶ | my @extra_scanners = @{ $arg->{extra_scanners} || [] }; | ||||||||||
|
Condition50%1/2
$arg->{'extra_scanners'} || []
MC/DC0%0/1
$arg->{'extra_scanners'} || []
$arg->{'extra_scanners'}
Truth table50%1/2
A
A= $arg->{'extra_scanners'}
| |||||||||||||
| 50 | |||||||||||||
| 51 | 94 | my $scanners = $self->__prepare_scanners([ @scanners, @extra_scanners ]); | |||||||||||
| 52 | |||||||||||||
| 53 | 94 | $self->_set_scanners($scanners); | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | #pod =method scan_string | ||||||||||||
| 57 | #pod | ||||||||||||
| 58 | #pod my $prereqs = $scanner->scan_string( $perl_code ); | ||||||||||||
| 59 | #pod | ||||||||||||
| 60 | #pod Given a string containing Perl source code, this method returns a | ||||||||||||
| 61 | #pod CPAN::Meta::Requirements object describing the modules it requires. | ||||||||||||
| 62 | #pod | ||||||||||||
| 63 | #pod This method will throw an exception if PPI fails to parse the code. | ||||||||||||
| 64 | #pod | ||||||||||||
| 65 | #pod B<Warning!> It isn't entirely clear whether PPI prefers to receive | ||||||||||||
| 66 | #pod strings as octet strings or character strings. For now, my advice | ||||||||||||
| 67 | #pod is to pass octet strings. | ||||||||||||
| 68 | #pod | ||||||||||||
| 69 | #pod =cut | ||||||||||||
| 70 | |||||||||||||
| 71 | 89 | ▶ | sub scan_string { | ||||||||||
|
Subroutine
scan_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 72 | 89 | my ($self, $str) = @_; | |||||||||||
| 73 | 89 | my $ppi = PPI::Document->new( \$str ); | |||||||||||
| 74 | 89 | ▶ | confess "PPI parse failed: " . PPI::Document->errstr unless defined $ppi; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | |||||||||||||
| 76 | 88 | return $self->scan_ppi_document( $ppi ); | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | #pod =method scan_file | ||||||||||||
| 80 | #pod | ||||||||||||
| 81 | #pod my $prereqs = $scanner->scan_file( $path ); | ||||||||||||
| 82 | #pod | ||||||||||||
| 83 | #pod Given a file path to a Perl document, this method returns a | ||||||||||||
| 84 | #pod CPAN::Meta::Requirements object describing the modules it requires. | ||||||||||||
| 85 | #pod | ||||||||||||
| 86 | #pod This method will throw an exception if PPI fails to parse the code. | ||||||||||||
| 87 | #pod | ||||||||||||
| 88 | #pod =cut | ||||||||||||
| 89 | |||||||||||||
| 90 | 93 | ▶ | sub scan_file { | ||||||||||
|
Subroutine
scan_file: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 91 | 93 | my ($self, $path) = @_; | |||||||||||
| 92 | 93 | my $ppi = PPI::Document->new( $path ); | |||||||||||
| 93 | 93 | ▶ | confess "PPI failed to parse '$path': " . PPI::Document->errstr | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | unless defined $ppi; | ||||||||||||
| 95 | |||||||||||||
| 96 | 93 | return $self->scan_ppi_document( $ppi ); | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | #pod =method scan_ppi_document | ||||||||||||
| 100 | #pod | ||||||||||||
| 101 | #pod my $prereqs = $scanner->scan_ppi_document( $ppi_doc ); | ||||||||||||
| 102 | #pod | ||||||||||||
| 103 | #pod Given a L<PPI::Document>, this method returns a CPAN::Meta::Requirements object | ||||||||||||
| 104 | #pod describing the modules it requires. | ||||||||||||
| 105 | #pod | ||||||||||||
| 106 | #pod =cut | ||||||||||||
| 107 | |||||||||||||
| 108 | 269 | ▶ | sub scan_ppi_document { | ||||||||||
|
Subroutine
scan_ppi_document: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 109 | 269 | my ($self, $ppi_doc) = @_; | |||||||||||
| 110 | |||||||||||||
| 111 | 269 | my $req = CPAN::Meta::Requirements->new; | |||||||||||
| 112 | |||||||||||||
| 113 | 269 | for my $scanner (@{ $self->{scanners} }) { | |||||||||||
| 114 | 1614 | $scanner->scan_for_prereqs($ppi_doc, $req); | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | 269 | return $req; | |||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | #pod =method scan_module | ||||||||||||
| 121 | #pod | ||||||||||||
| 122 | #pod my $prereqs = $scanner->scan_module( $module_name ); | ||||||||||||
| 123 | #pod | ||||||||||||
| 124 | #pod Given the name of a module, eg C<'PPI::Document'>, | ||||||||||||
| 125 | #pod this method returns a CPAN::Meta::Requirements object | ||||||||||||
| 126 | #pod describing the modules it requires. | ||||||||||||
| 127 | #pod | ||||||||||||
| 128 | #pod =cut | ||||||||||||
| 129 | |||||||||||||
| 130 | 1 | ▶ | sub scan_module { | ||||||||||
|
Subroutine
scan_module: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||
| 131 | 1 | my ($self, $module_name) = @_; | |||||||||||
| 132 | |||||||||||||
| 133 | # consider rewriting to use Module::Which -- rjbs, 2013-11-03 | ||||||||||||
| 134 | 1 | require Module::Path; | |||||||||||
| 135 | 1 | ▶ | if (defined(my $path = Module::Path::module_path($module_name))) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 136 | 1 | return $self->scan_file($path); | |||||||||||
| 137 | } | ||||||||||||
| 138 | |||||||||||||
| 139 | 0 | confess "Failed to find file for module '$module_name'"; | |||||||||||
| 140 | } | ||||||||||||
| 141 | |||||||||||||
| 142 | 5 | 1; | |||||||||||
| 143 | |||||||||||||
| 144 | =pod | ||||||||||||
| 145 | |||||||||||||
| 146 | =encoding UTF-8 | ||||||||||||
| 147 | |||||||||||||
| 148 | =head1 NAME | ||||||||||||
| 149 | |||||||||||||
| 150 | Perl::PrereqScanner - a tool to scan your Perl code for its prerequisites | ||||||||||||
| 151 | |||||||||||||
| 152 | =head1 VERSION | ||||||||||||
| 153 | |||||||||||||
| 154 | version 1.100 | ||||||||||||
| 155 | |||||||||||||
| 156 | =head1 SYNOPSIS | ||||||||||||
| 157 | |||||||||||||
| 158 | use Perl::PrereqScanner; | ||||||||||||
| 159 | my $scanner = Perl::PrereqScanner->new; | ||||||||||||
| 160 | my $prereqs = $scanner->scan_ppi_document( $ppi_doc ); | ||||||||||||
| 161 | my $prereqs = $scanner->scan_file( $file_path ); | ||||||||||||
| 162 | my $prereqs = $scanner->scan_string( $perl_code ); | ||||||||||||
| 163 | my $prereqs = $scanner->scan_module( $module_name ); | ||||||||||||
| 164 | |||||||||||||
| 165 | =head1 DESCRIPTION | ||||||||||||
| 166 | |||||||||||||
| 167 | The scanner will extract loosely your distribution prerequisites from your | ||||||||||||
| 168 | files. | ||||||||||||
| 169 | |||||||||||||
| 170 | The extraction may not be perfect but tries to do its best. It will currently | ||||||||||||
| 171 | find the following prereqs: | ||||||||||||
| 172 | |||||||||||||
| 173 | =over 4 | ||||||||||||
| 174 | |||||||||||||
| 175 | =item * | ||||||||||||
| 176 | |||||||||||||
| 177 | plain lines beginning with C<use> or C<require> in your perl modules and scripts, including minimum perl version | ||||||||||||
| 178 | |||||||||||||
| 179 | =item * | ||||||||||||
| 180 | |||||||||||||
| 181 | regular inheritance declared with the C<base> and C<parent> pragmata | ||||||||||||
| 182 | |||||||||||||
| 183 | =item * | ||||||||||||
| 184 | |||||||||||||
| 185 | L<Moose> inheritance declared with the C<extends> keyword | ||||||||||||
| 186 | |||||||||||||
| 187 | =item * | ||||||||||||
| 188 | |||||||||||||
| 189 | L<Moose> roles included with the C<with> keyword | ||||||||||||
| 190 | |||||||||||||
| 191 | =item * | ||||||||||||
| 192 | |||||||||||||
| 193 | OO namespace aliasing using the C<aliased> module | ||||||||||||
| 194 | |||||||||||||
| 195 | =back | ||||||||||||
| 196 | |||||||||||||
| 197 | =head2 Scanner Plugins | ||||||||||||
| 198 | |||||||||||||
| 199 | Perl::PrereqScanner works by running a series of scanners over a PPI::Document | ||||||||||||
| 200 | representing the code to scan. By default the "Perl5", "Moose", "TestMore", | ||||||||||||
| 201 | "POE", and "Aliased" scanners are run. You can supply your own scanners when | ||||||||||||
| 202 | constructing your PrereqScanner: | ||||||||||||
| 203 | |||||||||||||
| 204 | # Us only the Perl5 scanner: | ||||||||||||
| 205 | my $scanner = Perl::PrereqScanner->new({ scanners => [ qw(Perl5) ] }); | ||||||||||||
| 206 | |||||||||||||
| 207 | # Use any stock scanners, plus Example: | ||||||||||||
| 208 | my $scanner = Perl::PrereqScanner->new({ extra_scanners => [ qw(Example) ] }); | ||||||||||||
| 209 | |||||||||||||
| 210 | =head1 PERL VERSION | ||||||||||||
| 211 | |||||||||||||
| 212 | This library should run on perls released even a long time ago. It should work | ||||||||||||
| 213 | on any version of perl released in the last five years. | ||||||||||||
| 214 | |||||||||||||
| 215 | Although it may work on older versions of perl, no guarantee is made that the | ||||||||||||
| 216 | minimum required version will not be increased. The version may be increased | ||||||||||||
| 217 | for any reason, and there is no promise that patches will be accepted to lower | ||||||||||||
| 218 | the minimum required perl. | ||||||||||||
| 219 | |||||||||||||
| 220 | =head1 METHODS | ||||||||||||
| 221 | |||||||||||||
| 222 | =head2 scan_string | ||||||||||||
| 223 | |||||||||||||
| 224 | my $prereqs = $scanner->scan_string( $perl_code ); | ||||||||||||
| 225 | |||||||||||||
| 226 | Given a string containing Perl source code, this method returns a | ||||||||||||
| 227 | CPAN::Meta::Requirements object describing the modules it requires. | ||||||||||||
| 228 | |||||||||||||
| 229 | This method will throw an exception if PPI fails to parse the code. | ||||||||||||
| 230 | |||||||||||||
| 231 | B<Warning!> It isn't entirely clear whether PPI prefers to receive | ||||||||||||
| 232 | strings as octet strings or character strings. For now, my advice | ||||||||||||
| 233 | is to pass octet strings. | ||||||||||||
| 234 | |||||||||||||
| 235 | =head2 scan_file | ||||||||||||
| 236 | |||||||||||||
| 237 | my $prereqs = $scanner->scan_file( $path ); | ||||||||||||
| 238 | |||||||||||||
| 239 | Given a file path to a Perl document, this method returns a | ||||||||||||
| 240 | CPAN::Meta::Requirements object describing the modules it requires. | ||||||||||||
| 241 | |||||||||||||
| 242 | This method will throw an exception if PPI fails to parse the code. | ||||||||||||
| 243 | |||||||||||||
| 244 | =head2 scan_ppi_document | ||||||||||||
| 245 | |||||||||||||
| 246 | my $prereqs = $scanner->scan_ppi_document( $ppi_doc ); | ||||||||||||
| 247 | |||||||||||||
| 248 | Given a L<PPI::Document>, this method returns a CPAN::Meta::Requirements object | ||||||||||||
| 249 | describing the modules it requires. | ||||||||||||
| 250 | |||||||||||||
| 251 | =head2 scan_module | ||||||||||||
| 252 | |||||||||||||
| 253 | my $prereqs = $scanner->scan_module( $module_name ); | ||||||||||||
| 254 | |||||||||||||
| 255 | Given the name of a module, eg C<'PPI::Document'>, | ||||||||||||
| 256 | this method returns a CPAN::Meta::Requirements object | ||||||||||||
| 257 | describing the modules it requires. | ||||||||||||
| 258 | |||||||||||||
| 259 | =for Pod::Coverage::TrustPod new | ||||||||||||
| 260 | |||||||||||||
| 261 | =head1 SEE ALSO | ||||||||||||
| 262 | |||||||||||||
| 263 | L<scan-perl-prereqs>, in this distribution, is a command-line interface to the scanner | ||||||||||||
| 264 | |||||||||||||
| 265 | =head1 AUTHORS | ||||||||||||
| 266 | |||||||||||||
| 267 | =over 4 | ||||||||||||
| 268 | |||||||||||||
| 269 | =item * | ||||||||||||
| 270 | |||||||||||||
| 271 | Jerome Quelin | ||||||||||||
| 272 | |||||||||||||
| 273 | =item * | ||||||||||||
| 274 | |||||||||||||
| 275 | Ricardo Signes <cpan@semiotic.systems> | ||||||||||||
| 276 | |||||||||||||
| 277 | =back | ||||||||||||
| 278 | |||||||||||||
| 279 | =head1 CONTRIBUTORS | ||||||||||||
| 280 | |||||||||||||
| 281 | =for stopwords bowtie celogeek Christopher J. Madsen Dan Book David Golden Steinbrunner Ed J Florian Ragwitz Jakob Voss Jérôme Quelin John SJ Anderson Karen Etheridge Mark Gardner Neil Bowers Randy Stauner Ricardo Signes Tina Mueller Vyacheslav Matjukhin | ||||||||||||
| 282 | |||||||||||||
| 283 | =over 4 | ||||||||||||
| 284 | |||||||||||||
| 285 | =item * | ||||||||||||
| 286 | |||||||||||||
| 287 | bowtie <bowtie@cpan.org> | ||||||||||||
| 288 | |||||||||||||
| 289 | =item * | ||||||||||||
| 290 | |||||||||||||
| 291 | celogeek <me@celogeek.com> | ||||||||||||
| 292 | |||||||||||||
| 293 | =item * | ||||||||||||
| 294 | |||||||||||||
| 295 | Christopher J. Madsen <perl@cjmweb.net> | ||||||||||||
| 296 | |||||||||||||
| 297 | =item * | ||||||||||||
| 298 | |||||||||||||
| 299 | Dan Book <grinnz@grinnz.com> | ||||||||||||
| 300 | |||||||||||||
| 301 | =item * | ||||||||||||
| 302 | |||||||||||||
| 303 | David Golden <dagolden@cpan.org> | ||||||||||||
| 304 | |||||||||||||
| 305 | =item * | ||||||||||||
| 306 | |||||||||||||
| 307 | David Steinbrunner <dsteinbrunner@pobox.com> | ||||||||||||
| 308 | |||||||||||||
| 309 | =item * | ||||||||||||
| 310 | |||||||||||||
| 311 | Ed J <mohawk2@users.noreply.github.com> | ||||||||||||
| 312 | |||||||||||||
| 313 | =item * | ||||||||||||
| 314 | |||||||||||||
| 315 | Florian Ragwitz <rafl@debian.org> | ||||||||||||
| 316 | |||||||||||||
| 317 | =item * | ||||||||||||
| 318 | |||||||||||||
| 319 | Jakob Voss <voss@gbv.de> | ||||||||||||
| 320 | |||||||||||||
| 321 | =item * | ||||||||||||
| 322 | |||||||||||||
| 323 | Jérôme Quelin <jquelin@gmail.com> | ||||||||||||
| 324 | |||||||||||||
| 325 | =item * | ||||||||||||
| 326 | |||||||||||||
| 327 | John SJ Anderson <genehack@genehack.org> | ||||||||||||
| 328 | |||||||||||||
| 329 | =item * | ||||||||||||
| 330 | |||||||||||||
| 331 | Karen Etheridge <ether@cpan.org> | ||||||||||||
| 332 | |||||||||||||
| 333 | =item * | ||||||||||||
| 334 | |||||||||||||
| 335 | Mark Gardner <gardnerm@gsicommerce.com> | ||||||||||||
| 336 | |||||||||||||
| 337 | =item * | ||||||||||||
| 338 | |||||||||||||
| 339 | Neil Bowers <neil@bowers.com> | ||||||||||||
| 340 | |||||||||||||
| 341 | =item * | ||||||||||||
| 342 | |||||||||||||
| 343 | Randy Stauner <rwstauner@cpan.org> | ||||||||||||
| 344 | |||||||||||||
| 345 | =item * | ||||||||||||
| 346 | |||||||||||||
| 347 | Ricardo Signes <rjbs@semiotic.systems> | ||||||||||||
| 348 | |||||||||||||
| 349 | =item * | ||||||||||||
| 350 | |||||||||||||
| 351 | Tina Mueller <tinita@cpan.org> | ||||||||||||
| 352 | |||||||||||||
| 353 | =item * | ||||||||||||
| 354 | |||||||||||||
| 355 | Vyacheslav Matjukhin <mmcleric@yandex-team.ru> | ||||||||||||
| 356 | |||||||||||||
| 357 | =back | ||||||||||||
| 358 | |||||||||||||
| 359 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 360 | |||||||||||||
| 361 | This software is copyright (c) 2009 by Jerome Quelin. | ||||||||||||
| 362 | |||||||||||||
| 363 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 364 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 365 | |||||||||||||
| 366 | =cut | ||||||||||||
| 367 | |||||||||||||
| 368 | __END__ | ||||||||||||