Perlito5/Grammar/Attribute.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 46 CC 7 SCAR 39.0
CC
7
Cov
0%
opt_attribute
56.0
BEGIN
2.0
CRAP 49.2
1 use v5;
2  
3 package Perlito5::Grammar::Attribute;
4  
5 sub opt_attribute {
6 my $str = $_[0];
7 my $pos = $_[1];
8  
9 my @attributes;
10 my $ws = Perlito5::Grammar::Space::opt_ws( $str, $pos );
11 if ($str->[ $ws->{to} ] ne ':') {
12 # no colon, return an empty list
13 return { to => $pos, capture => [] }
14 }
15 $ws = Perlito5::Grammar::Space::opt_ws( $str, $ws->{to} + 1 );
16 my $p = $ws->{to};
17 my $m = Perlito5::Grammar::ident($str, $p);
18 Perlito5::Compiler::error( "syntax error" ) if !$m;
19  
20 my $to;
21 while (1) {
22  
23 my $attr = [ Perlito5::Match::flat($m), undef ];
24 $to = $m->{to};
25 my $delimiter = $str->[$to];
26 if ($delimiter eq '(') {
27 # "ident(params)"
28 my $params = Perlito5::Grammar::String::string_interpolation_parse($str, $m->{to} + 1, '(', ')', 0);
29 Perlito5::Compiler::error( "syntax error" ) if !$params;
30 $attr->[1] = Perlito5::Match::flat($params)->{buf};
31 $to = $params->{to};
32 }
33 push @attributes, $attr;
34  
35 # check if the attribute list continues
36 $ws = Perlito5::Grammar::Space::opt_ws( $str, $to );
37 if ($str->[$ws->{to}] eq ':') {
38 $ws = Perlito5::Grammar::Space::opt_ws( $str, $ws->{to} + 1 );
39 }
40 $p = $ws->{to};
41 $m = Perlito5::Grammar::ident($str, $p);
42  
43 return { to => $to, capture => \@attributes }
44 if ! $m;
45 }
46 }
47  
48 1;
49