blib/lib/Perl/PrereqScanner/NotQuiteLite/Parser/Core.pm untested

filter: Statementstmt 0.0% 0 / 98 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 58 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 231 SCAR 68.4
CC
30
Cov
0%
parse_parent_args
90.0
parse_base_args
42.0
parse_if_args
30.0
CRAP 930.0
1 package Perl::PrereqScanner::NotQuiteLite::Parser::Core;
2  
3 use strict;
4 use warnings;
5 use Perl::PrereqScanner::NotQuiteLite::Util;
6  
7 my %feature_since = (
8 say => '5.010',
9 state => '5.010',
10 switch => '5.010',
11 unicode_strings => '5.012',
12 current_sub => '5.016',
13 evalbytes => '5.016',
14 fc => '5.016',
15 arybase => '5.016',
16 unicode_eval => '5.016',
17 lexical_subs => '5.018',
18 postderef => '5.020',
19 postderef_qq => '5.020',
20 signatures => '5.020',
21 bitwise => '5.022',
22 refaliasing => '5.022',
23 declared_refs => '5.026',
24 );
25  
26 sub register { return {
27 use => {
28 if => 'parse_if_args',
29 base => 'parse_base_args',
30 parent => 'parse_parent_args',
31 feature => 'parse_feature_args',
32 },
33 keyword => {
34 package => 'parse_package',
35 exit => 'parse_begin_exit',
36 },
37 }}
38  
39 sub parse_if_args {
40 my ($class, $c, $used_module, $raw_tokens) = @_;
41  
42 while(my $token = shift @$raw_tokens) {
43 last if $token->[1] eq 'COMMA';
44 }
45  
46 my $tokens = convert_string_tokens($raw_tokens);
47 my $module = shift @$tokens;
48 if (ref $module and ($module->[1] eq 'WORD' or $module->[1] eq 'KEYWORD')) {
49 $module = $module->[0];
50 }
51 if (is_module_name($module)) {
52 if (is_version($tokens->[0])) {
53 my $version = shift @$tokens;
54 $c->add_recommendation($module => $version);
55 } else {
56 $c->add_recommendation($module => 0);
57 }
58 } else {
59 push @{$c->{errors}}, "use if module not found";
60 }
61 }
62  
63 sub parse_base_args {
64 my ($class, $c, $used_module, $raw_tokens) = @_;
65  
66 my $tokens = convert_string_tokens($raw_tokens);
67 if (is_version($tokens->[0])) {
68 $c->add($used_module => shift @$tokens);
69 }
70 while(my $token = shift @$tokens) {
71 my $module = $token;
72 if (ref $module and ($module->[1] || '') eq 'WORD') {
73 # allow bareword, but disallow function()
74 $module = $module->[0];
75 next if @$tokens and ref $tokens->[0] and ($tokens->[0][1] || '') eq '()';
76 }
77 # bareword in parentheses
78 if (ref $module and ref $module->[0]) {
79 $module = $module->[0][0];
80 }
81 if (is_module_name($module)) {
82 $c->add($module => 0);
83 }
84 }
85 }
86  
87 sub parse_parent_args {
88 my ($class, $c, $used_module, $raw_tokens) = @_;
89  
90 my $tokens = convert_string_tokens($raw_tokens);
91 if (is_version($tokens->[0])) {
92 $c->add($used_module => shift @$tokens);
93 }
94 while(my $token = shift @$tokens) {
95 last if $token eq '-norequire';
96 my $module = $token;
97 if (ref $token) {
98 last if $token->[0] eq '-norequire';
99 }
100 if (ref $module and ($module->[1] || '') eq 'WORD') {
101 # allow bareword, but disallow function()
102 $module = $module->[0];
103 next if @$tokens and ref $tokens->[0] and ($tokens->[0][1] || '') eq '()';
104 }
105 # bareword in parentheses
106 if (ref $module and ref $module->[0]) {
107 $module = $module->[0][0];
108 }
109 $c->add($module => 0) if is_module_name($module);
110 }
111 }
112  
113 sub parse_feature_args {
114 my ($class, $c, $used_module, $raw_tokens) = @_;
115  
116 $c->add_perl('5.010', 'feature');
117 my $tokens = convert_string_tokens($raw_tokens);
118 if (is_version($tokens->[0])) {
119 $c->add($used_module => shift @$tokens);
120 }
121 while(my $token = shift @$tokens) {
122 next if ref $token;
123 if (exists $feature_since{$token}) {
124 $c->add_perl($feature_since{$token} => "feature $token");
125 next;
126 }
127 if ($token =~ /^:5\.([0-9]+)(\.\[0-9]+)?/) {
128 my $version = sprintf '5.%03d', $1;
129 $c->add_perl($version, $token);
130 next;
131 }
132 }
133 }
134  
135 sub parse_begin_exit {
136 my ($class, $c, $raw_tokens) = @_;
137  
138 my @stack = @{$c->{stack} || []};
139 if (grep {$_->[0] eq '{' and $_->[2] eq 'BEGIN'} @stack) {
140 if (grep {$c->token_is_conditional($_->[0])} @$raw_tokens) {
141 $c->{force_cond} = 1;
142 } elsif (grep {$_->[0] eq '{' and $c->token_is_conditional($_->[2])} @stack) {
143 $c->{force_cond} = 1;
144 } else {
145 $c->{ended} = 1;
146 @{$c->{stack}} = ();
147 }
148 }
149 }
150  
151 sub parse_package {
152 my ($class, $c, $raw_tokens) = @_;
153  
154 my $tokens = convert_string_tokens($raw_tokens);
155 shift @$tokens; # drop "package"
156 my $token = shift @$tokens;
157 if (ref $token && $token->[1] && $token->[1] eq 'WORD') {
158 $c->add_package($token->[0]);
159 }
160 if (@$tokens) {
161 $token = shift @$tokens;
162 if (is_version($token)) {
163 $c->add_perl("5.012", "package PACKAGE VERSION");
164 $token = shift @$tokens;
165 }
166 if (ref $token && $token->[1] && $token->[1] =~ /^\{/) {
167 $c->add_perl("5.014", "package PACKAGE (VERSION) {}");
168 }
169 }
170 }
171  
172 1;
173  
174 __END__