File Coverage

lib/Perl/PrereqScanner/NotQuiteLite/Parser/PackageVariant.pm
Criterion Covered Total %
statement 37 39 94.8
branch 23 32 71.8
condition 16 21 76.1
subroutine 5 5 100.0
pod 0 2 0.0
total 81 99 81.8


line stmt bran cond sub pod time code
1             package Perl::PrereqScanner::NotQuiteLite::Parser::PackageVariant;
2              
3 82     82   1301 use strict;
  82         161  
  82         2091  
4 82     82   371 use warnings;
  82         150  
  82         1624  
5 82     82   371 use Perl::PrereqScanner::NotQuiteLite::Util;
  82         160  
  82         36645  
6              
7             sub register {{
8 81     81 0 413 use => {
9             'Package::Variant' => 'parse_package_variant_args',
10             },
11             }}
12              
13             sub parse_package_variant_args {
14 7     7 0 12 my ($class, $c, $used_module, $raw_tokens) = @_;
15              
16 7         16 my $tokens = convert_string_tokens($raw_tokens);
17              
18 7         19 while(my $token = shift @$tokens) {
19 21 100 100     103 if (ref $token and $token->[0] eq 'importing') {
    100 100        
      100        
20 5 50 33     19 shift @$tokens if @$tokens && $tokens->[0][1] eq 'COMMA';
21 5 50       12 my $next_token = shift @$tokens or last;
22 5 100       21 if (!ref $next_token) {
    100          
    50          
23 1         70 my $module = $next_token;
24 1 50       5 if (is_module_name($module)) {
25 1         4 $c->add($module);
26 1 50       29 if ($c->has_callback_for(use => $module)) {
27 0         0 $c->run_callback_for('use', $module, [["use", "KEYWORD"], [$module, "WORD"], [";", ";"]]);
28             }
29             }
30             }
31             elsif ($next_token->[1] eq '[]') {
32 3         10 my $modules = convert_string_token_list($next_token->[0]);
33 3         7 while(my $module = shift @$modules) {
34 5 100       11 next unless is_module_name($module);
35 4         12 $c->add($module);
36 4 100       109 if ($c->has_callback_for(use => $module)) {
37 2         8 $c->run_callback_for('use', $module, [["use", "KEYWORD"], [$module, "WORD"], [";", ";"]]);
38             }
39             }
40             } elsif ($next_token->[1] eq '{}') {
41 1         5 my $hash_tokens = convert_string_token_list($next_token->[0]);
42 1         3 while(my $module = shift @$hash_tokens) {
43 1         2 my $arg = shift @$hash_tokens;
44 1 50       4 my @args = $arg->[1] eq '[]' ? @{$arg->[0]} : $arg;
  0         0  
45 1         4 $c->add($module);
46 1 50       46 if ($c->has_callback_for(use => $module)) {
47 1         7 $c->run_callback_for('use', $module, [["use", "KEYWORD"], [$module, "WORD"], @args, [";", ";"]]);
48             }
49             }
50             }
51             }
52             elsif (ref $token && !ref $token->[0] && $token->[1] eq 'WORD') {
53 4 50 33     12 shift @$tokens if @$tokens && $tokens->[0][1] eq 'COMMA';
54 4 50       9 shift @$tokens if @$tokens;
55             }
56 21 100 66     119 shift @$tokens if @$tokens && ref $tokens->[0] && $tokens->[0][1] eq 'COMMA';
      100        
57             }
58             }
59              
60             1;
61              
62             __END__