File Coverage

lib/Perl/PrereqScanner/NotQuiteLite/Parser/SyntaxCollector.pm
Criterion Covered Total %
statement 33 34 97.0
branch 12 16 75.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 2 0.0
total 52 60 86.6


line stmt bran cond sub pod time code
1             package Perl::PrereqScanner::NotQuiteLite::Parser::SyntaxCollector;
2              
3 94     94   92088 use strict;
  94         174  
  94         3174  
4 94     94   563 use warnings;
  94         215  
  94         3818  
5 94     94   806 use Perl::PrereqScanner::NotQuiteLite::Util;
  94         232  
  94         59490  
6              
7             sub register { return {
8 93     93 0 484 use => {
9             'Syntax::Collector' => 'parse_syntax_collector_args',
10             },
11             }}
12              
13             sub parse_syntax_collector_args {
14 3     3 0 7 my ($class, $c, $used_module, $raw_tokens) = @_;
15              
16 3         15 my $tokens = convert_string_token_list($raw_tokens);
17              
18 3 50       8 if (is_version($tokens->[0])) {
19 0         0 $c->add($used_module => shift @$tokens);
20             }
21              
22 3         4 my $spec;
23 3 100       7 if (!(@$tokens % 2)) {
24 1         4 while(my ($key, $value) = splice @$tokens, 0, 2) {
25 1 50       3 my $keystr = ref $key ? $key->[0] : $key;
26 1 50       2 if ($keystr eq '-collect') {
27 1         2 $spec = $value;
28 1         2 last;
29             }
30             }
31             } else {
32 2         5 $spec = $tokens->[0];
33             }
34 3 100       5 if (ref $spec) {
35 1         3 $spec = $spec->[0];
36             }
37 3 100 66     18 return if !$spec or ref $spec;
38              
39             my @features =
40             map {
41 6 100       241 m{^
    50          
42             (use|no) \s+ # "use" or "no"
43             (\S+) \s+ # module name
44             ([\d\._v]+) # module version
45             (?: # everything else
46             \s* (.+)
47             )? # ... perhaps
48             [;] \s* # semicolon
49             $}x
50             ? [$1, $2, $3, [ defined($4) ? eval "($4)" : ()] ]
51             : die("Line q{$_} doesn't conform to 'use MODULE VERSION [ARGS];'")
52             }
53 6         9 grep { ! m/^#/ } # not a comment
54 16         45 grep { m/[A-Z0-9]/i } # at least one alphanum
55 16         29 map { s/(^\s+)|(\s+$)//; $_ } # trim
  16         22  
56 2         4 map { split /(\r?\n|\r)/ } # split lines
  2         43  
57             $spec;
58              
59 2         28 for my $feature (@features) {
60 6         136 $c->add($feature->[1], $feature->[2]);
61             }
62             }
63              
64             1;
65              
66             __END__