« lib/Perl/PrereqScanner/NotQuiteLite/Parser/ClassLoad.pm
↑ Summary
blib/lib/Perl/PrereqScanner/NotQuiteLite/Parser/Plack.pm »
| 1 | package Perl::PrereqScanner::NotQuiteLite::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 96 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 96 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 96 | ▶ | use Exporter 5.57 qw/import/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 96 | our %FLAGS; BEGIN { | |||||||||||||||||||||||||||||||||||||||||
| 8 | 96 | ▶ | my $i = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 96 | %FLAGS = map {$_ => 1 << $i++} qw/ | |||||||||||||||||||||||||||||||||||||||||
| 10 | F_KEEP_TOKENS | ||||||||||||||||||||||||||||||||||||||||||
| 11 | F_EVAL | ||||||||||||||||||||||||||||||||||||||||||
| 12 | F_STRING_EVAL | ||||||||||||||||||||||||||||||||||||||||||
| 13 | F_EXPECTS_BRACKET | ||||||||||||||||||||||||||||||||||||||||||
| 14 | F_CONDITIONAL | ||||||||||||||||||||||||||||||||||||||||||
| 15 | F_SIDEFF | ||||||||||||||||||||||||||||||||||||||||||
| 16 | F_SCOPE_END | ||||||||||||||||||||||||||||||||||||||||||
| 17 | F_STATEMENT_END | ||||||||||||||||||||||||||||||||||||||||||
| 18 | F_EXPR_END | ||||||||||||||||||||||||||||||||||||||||||
| 19 | F_EXPR | ||||||||||||||||||||||||||||||||||||||||||
| 20 | /; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 96 | ▶ | use constant \%FLAGS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | use constant { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 96 | MASK_KEEP_TOKENS => ~(F_KEEP_TOKENS), | |||||||||||||||||||||||||||||||||||||||||
| 26 | MASK_EXPR_END => ~(F_EXPR_END|F_EXPR), | ||||||||||||||||||||||||||||||||||||||||||
| 27 | MASK_STATEMENT_END => ~(F_KEEP_TOKENS|F_STATEMENT_END|F_EXPR|F_EXPR_END|F_SIDEFF), | ||||||||||||||||||||||||||||||||||||||||||
| 28 | MASK_EVAL => ~(F_EVAL), | ||||||||||||||||||||||||||||||||||||||||||
| 29 | MASK_SIDEFF => ~(F_SIDEFF), | ||||||||||||||||||||||||||||||||||||||||||
| 30 | F_RESCAN => (F_KEEP_TOKENS|F_EVAL|F_STRING_EVAL|F_CONDITIONAL), | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 96 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 96 | our @EXPORT = ((keys %FLAGS), qw/ | |||||||||||||||||||||||||||||||||||||||||
| 34 | is_module_name | ||||||||||||||||||||||||||||||||||||||||||
| 35 | is_version | ||||||||||||||||||||||||||||||||||||||||||
| 36 | convert_string_tokens | ||||||||||||||||||||||||||||||||||||||||||
| 37 | convert_string_token_list | ||||||||||||||||||||||||||||||||||||||||||
| 38 | MASK_KEEP_TOKENS | ||||||||||||||||||||||||||||||||||||||||||
| 39 | MASK_EXPR_END | ||||||||||||||||||||||||||||||||||||||||||
| 40 | MASK_STATEMENT_END | ||||||||||||||||||||||||||||||||||||||||||
| 41 | MASK_EVAL | ||||||||||||||||||||||||||||||||||||||||||
| 42 | MASK_SIDEFF | ||||||||||||||||||||||||||||||||||||||||||
| 43 | F_RESCAN | ||||||||||||||||||||||||||||||||||||||||||
| 44 | /); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | sub is_module_name { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 2702 | ▶ | my $name = shift or return; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_module_name: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 2700 | ▶ | return 1 if $name =~ /^[A-Za-z_][A-Za-z0-9_]*(?:(?:::|')[A-Za-z0-9_]+)*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 99 | return; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | sub is_version { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 440 | ▶ | my $version = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_version: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 440 | ▶ | return unless defined $version; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 439 | ▶ | return 1 if $version =~ /\A | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 57 | [0-9]+(?:\.[0-9]+)? | ||||||||||||||||||||||||||||||||||||||||||
| 58 | | | ||||||||||||||||||||||||||||||||||||||||||
| 59 | v[0-9]+(?:\.[0-9]+)* | ||||||||||||||||||||||||||||||||||||||||||
| 60 | | | ||||||||||||||||||||||||||||||||||||||||||
| 61 | [0-9]+(?:\.[0-9]+){2,} | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ) (?:_[0-9]+)? | ||||||||||||||||||||||||||||||||||||||||||
| 63 | \z/x; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 255 | return; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | sub convert_string_tokens { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 447 | ▶ | my $org_tokens = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_string_tokens: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 447 | my @tokens; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 447 | my @copied_tokens = @$org_tokens; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 447 | my $prev = ''; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 447 | ▶ | while(my $copied_token = shift @copied_tokens) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1799 | my ($token, $desc) = @$copied_token; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1799 | ▶ | if ($desc and $desc eq '()' and $prev ne 'WORD') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$desc and $desc eq "()" and $prev ne "WORD"
$desc and $desc eq "()"
MC/DC100%3/3
$desc and $desc eq "()" and $prev ne "WORD"
$desc
$desc eq "()"
$prev ne "WORD"
Truth table100%4/4
A and B and C
A= $descB= $desc eq "()"C= $prev ne "WORD"
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 61 | unshift @copied_tokens, @$token; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 61 | next; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1738 | ▶ | if (!$desc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | push @tokens, $copied_token; | |||||||||||||||||||||||||||||||||||||||||
| 81 | ▶ | } elsif ($desc eq 'VERSION_STRING' or $desc eq 'NUMBER') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$desc eq "VERSION_STRING" or $desc eq "NUMBER"
MC/DC100%2/2
$desc eq "VERSION_STRING" or $desc eq "NUMBER"
$desc eq "VERSION_STRING"
$desc eq "NUMBER"
Truth table100%3/3
A or B
A= $desc eq "VERSION_STRING"B= $desc eq "NUMBER"
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 94 | push @tokens, $token; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } elsif ($desc eq 'STRING') { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 287 | push @tokens, $token->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } elsif ($desc eq 'QUOTED_WORD_LIST') { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 25 | ▶ | push @tokens, grep {defined $_ and $_ ne ''} split /\s/, $token->[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 1325 | push @tokens, $copied_token; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 1738 | $prev = $desc; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 447 | \@tokens; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | sub convert_string_token_list { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 11 | ▶ | my $org_tokens = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert_string_token_list: called CC=17 SCAR=29.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | my @list; | |||||||||||||||||||||||||||||||||||||||||
| 98 | my @tokens; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 11 | my @copied_tokens = @$org_tokens; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 11 | my $prev = ''; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 11 | ▶ | while(my $copied_token = shift @copied_tokens) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 40 | my ($token, $desc) = @$copied_token; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 40 | ▶ | if ($desc and $desc eq '()' and $prev ne 'WORD') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$desc and $desc eq "()" and $prev ne "WORD"
$desc and $desc eq "()"
MC/DC0%0/3
$desc and $desc eq "()" and $prev ne "WORD"
$desc
$desc eq "()"
$prev ne "WORD"
Truth table25%1/4
A and B and C
A= $descB= $desc eq "()"C= $prev ne "WORD"
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | unshift @copied_tokens, @$token; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 40 | ▶ | if (!$desc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | push @tokens, $copied_token; | |||||||||||||||||||||||||||||||||||||||||
| 110 | ▶ | } elsif ($desc eq 'VERSION_STRING' or $desc eq 'NUMBER') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$desc eq "VERSION_STRING" or $desc eq "NUMBER"
MC/DC50%1/2
$desc eq "VERSION_STRING" or $desc eq "NUMBER"
$desc eq "VERSION_STRING"
$desc eq "NUMBER"
Truth table66%2/3
A or B
A= $desc eq "VERSION_STRING"B= $desc eq "NUMBER"
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | push @tokens, $token; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } elsif ($desc eq 'STRING') { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 9 | push @tokens, $token->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } elsif ($desc eq 'QUOTED_WORD_LIST') { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | push @list, grep {defined $_ and $_ ne ''} split /\s/, $token->[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | ▶ | } elsif ($token eq ',' or $token eq '=>') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$token eq "," or $token eq "=>"
MC/DC100%2/2
$token eq "," or $token eq "=>"
$token eq ","
$token eq "=>"
Truth table100%3/3
A or B
A= $token eq ","B= $token eq "=>"
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 13 | ▶ | push @list, @tokens == 1 ? $tokens[0] : \@tokens; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 13 | @tokens = (); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 13 | $prev = ''; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } elsif ($desc eq ';') { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | last; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 10 | push @tokens, $copied_token; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 34 | $prev = $desc; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 11 | ▶ | if (@tokens) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 7 | ▶ | push @list, @tokens == 1 ? $tokens[0] : \@tokens; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 11 | \@list; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 96 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||||||||||||||||