File Coverage

lib/Perl/PrereqScanner/Scanner/TestNeeds.pm
Criterion Covered Total %
statement 36 36 100.0
branch 6 8 75.0
condition 1 2 50.0
subroutine 8 8 100.0
pod 0 1 0.0
total 51 55 92.7


line stmt bran cond sub pod time code
1             package Perl::PrereqScanner::Scanner::TestNeeds;
2              
3 2     2   3476 use 5.006;
  2         9  
4 2     2   11 use strict;
  2         4  
  2         47  
5 2     2   9 use warnings;
  2         4  
  2         115  
6              
7             our $VERSION = '0.001';
8              
9 2     2   725 use Moose;
  2         541468  
  2         18  
10              
11             with 'Perl::PrereqScanner::Scanner';
12              
13 2     2   18443 use PPIx::Literal ();
  2         2278  
  2         62  
14 2     2   543 use version 0.77;
  2         2296  
  2         19  
15              
16 2     2   752 use namespace::autoclean;
  2         9434  
  2         18  
17              
18             sub scan_for_prereqs {
19 8     8 0 27127 my ( $self, $ppi_doc, $req ) = @_;
20              
21             # regular use, require, and no
22 8   50     51 my $includes = $ppi_doc->find('Statement::Include') || [];
23              
24             NODE:
25 8         5513 for my $node ( @{$includes} ) {
  8         34  
26 8 50       56 next NODE if $node->module ne 'Test::Needs';
27              
28 8         321 my @args = PPIx::Literal->convert( $node->arguments );
29 8 50       7068 next NODE if !@args;
30              
31 8         31 for my $arg (@args) {
32 10 100       237 if ( ref $arg eq ref {} ) {
33 6         15 for my $module ( keys %{$arg} ) {
  6         26  
34 7 100       168 if ( $module eq 'perl' ) {
35 3         106 $req->add_minimum( $module => version->parse( $arg->{$module} )->numify() );
36             }
37             else {
38 4         30 $req->add_minimum( $module => "$arg->{$module}" );
39             }
40             }
41             }
42             else {
43 4         18 $req->add_minimum( $arg => 0 );
44             }
45             }
46             }
47              
48 8         882 return;
49             }
50              
51             __PACKAGE__->meta->make_immutable;
52              
53             1;
54              
55             __END__
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =head1 NAME
62              
63             Perl::PrereqScanner::Scanner::TestNeeds - scan for modules loaded with Test::Needs
64              
65             =head1 VERSION
66              
67             Version 0.001
68              
69             =head1 SYNOPSIS
70              
71             use Perl::PrereqScanner;
72             my $scanner = Perl::PrereqScanner->new( { extra_scanners => ['TestNeeds'] } );
73             my $prereqs = $scanner->scan_ppi_document($ppi_doc);
74             my $prereqs = $scanner->scan_file($file_path);
75             my $prereqs = $scanner->scan_string($perl_code);
76             my $prereqs = $scanner->scan_module($module_name);
77              
78             =head1 DESCRIPTION
79              
80             This is a scanner for L<Perl::PrereqScanner> that finds modules used with
81             L<Test::Needs>.
82              
83             Note: The scanner currently does not detect modules loaded with the
84             C<test_needs> sub, only modules used with a use statement are detected.
85              
86             use Test::Needs 'Some::Module';
87              
88             =head1 SEE ALSO
89              
90             L<Perl::PrereqScanner>, L<Test::Needs>
91              
92             =head1 SUPPORT
93              
94             =head2 Bugs / Feature Requests
95              
96             Please report any bugs or feature requests through the issue tracker
97             at L<https://github.com/skirmess/Perl-PrereqScanner-Scanner-TestNeeds/issues>.
98             You will be notified automatically of any progress on your issue.
99              
100             =head2 Source Code
101              
102             This is open source software. The code repository is available for
103             public review and contribution under the terms of the license.
104              
105             L<https://github.com/skirmess/Perl-PrereqScanner-Scanner-TestNeeds>
106              
107             git clone https://github.com/skirmess/Perl-PrereqScanner-Scanner-TestNeeds.git
108              
109             =head1 AUTHOR
110              
111             Sven Kirmess <sven.kirmess@kzone.ch>
112              
113             =head1 COPYRIGHT AND LICENSE
114              
115             This software is Copyright (c) 2021 by Sven Kirmess.
116              
117             This is free software, licensed under:
118              
119             The (two-clause) FreeBSD License
120              
121             =cut
122              
123             # vim: ts=4 sts=4 sw=4 et: syntax=perl