blib/lib/Inline/denter.pm

filter: Statementstmt 68.4% 154 / 225 Branchbran 37.9% 47 / 124 Conditioncond 23.9% 11 / 46 MC/DCmcdc 4.0% 1 / 25 Subroutinesub 82.6% 19 / 23 Podpod 0.0% 0 / 8 totaltotal 51.4% 232 / 451 CC 80 SCAR 31.3
CC
80
Cov
54%
indent_data
65.0
_undent_value
31.8
_get_key
30.5
CRAP 22.8
« blib/lib/Inline/MakeMaker.pm ↑ Summary blib/lib/Inline/C/ParseRecDescent.pm »
1 package Inline::denter;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use AutoLoader 'AUTOLOAD';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub new {
8 35 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 35 bless {width => 4,
10 comma => " : ",
11 level => 0,
12 tabwidth => 8,
13 }, $class;
14 }
15  
16 # Prevent a taint exception being thrown by AutoLoader.pm.
17 # Serves no other purpose.
18 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
19 }
20  
21 sub undent {
22 20 ▶ local $/ = "\n";
Subroutine undent: called CC=6 SCAR=18.0
Pod undocumented
23 20 my ($o, $text) = @_;
24 20 my ($comma) = $o->{comma};
25 20 my $package = caller;
26 20 ▶ $package = caller(1) if $package eq 'Inline::denter';
Branch: 1 branch
BranchTrueFalseTotal
if $package eq "Inline::denter" 0 20 20
27 20 %{$o->{xref}} = ();
28 20 @{$o->{objects}} = ();
29 20 @{$o->{context}} = ();
30 20 my $glob = '';
31 20 chomp $text;
32 20 @{$o->{lines}} = split $/, $text;
33 20 $o->{level} = 0;
34 20 ▶ $o->{line} ||= 1;
Condition50%1/2
$o->{"line"} ||= 1
l!l
020
MC/DC0%0/1
$o->{"line"} ||= 1
$o->{"line"}
Truth table50%1/2
A
A= $o->{"line"}
Aresult
11
00
35 20 $o->_setup_line;
36 20 ▶ while (not $o->{done}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o->{"done"}) 100 20 120
37 100 ▶ if ($o->{level} == 0 and
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"level"} == 0 and $o->{"content"} =~ /^(\w+)\s*$comma\s*(.*)$/) 100 0 100
Condition33%1/3
$o->{"level"} == 0 and $o->{"content"} =~ /^(\w+)\s*$comma\s*(.*)$/
!ll&&!rl&&r
00100
MC/DC0%0/2
$o->{"level"} == 0 and $o->{"content"} =~ /^(\w+)\s*$comma\s*(.*)$/
$o->{"level"} == 0 $o->{"content"} =~ /^(\w+)\s*$comma\s*(.*)$/
Truth table33%1/3
A and B
A= $o->{"level"} == 0B= $o->{"content"} =~ /^(\w+)\s*$comma\s*(.*)$/
ABresult
0X0
100
111
38 $o->{content} =~ /^(\w+)\s*$comma\s*(.*)$/) {
39 100 $o->{content} = $2;
40 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 100 push @{$o->{objects}}, "$1";
42 }
43 100 push @{$o->{objects}}, $o->_undent_data;
44 }
45 20 return @{$o->{objects}};
46 }
47  
48 sub _undent_data {
49 280 ▶ my $o = shift;
Subroutine _undent_data: called CC=12 SCAR=33.6
50 280 my ($obj, $class) = ('', '');
51 280 my @refs;
52 my %refs;
53 280 ▶ while ($o->{content} =~ s/^\\(?:\((\w+)\))?((\%|\@|\$|\\).*)/$2/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"content"} =~ s/^\\(?:\((\w+)\))?((\%|\@|\$|\\).*)/$2/) 0 280 280
54 0 push @refs, $1;
55 0 $refs{$1} = scalar @refs;
56 }
57 280 ▶ if ($o->{content} =~ /^([\%\@\$])
Branch: 2 branches
BranchTrueFalseTotal
if ($o->{'content'} =~ /^([\%\@\$]) (\w(?:\w|::)*)? \s*$/x) { } 80 200 280
elsif ($o->{'content'} =~ /^\?\s*$/) { } 0 200 200
58 (\w(?:\w|::)*)?
59 \s*$/x
60 ) {
61 80 my $foo;
62 80 ▶ $obj = ($1 eq '%') ? {} : ($1 eq '@') ? [] : \$foo;
Branch: 2 branches
BranchTrueFalseTotal
$1 eq '%' ? : 80 0 80
$1 eq '@' ? : 0 0 0
63 80 ▶ $class = $2 || '';
Condition50%1/2
$2 || ''
l!l
080
MC/DC0%0/1
$2 || ''
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
64 80 ▶ if ($1 eq '%') {
Branch: 2 branches
BranchTrueFalseTotal
if ($1 eq '%') { } 80 0 80
elsif ($1 eq '@') { } 0 0 0
65 80 %$obj = $o->_undent_hash;
66 }
67 elsif ($1 eq '@') {
68 0 @$obj = $o->_undent_array;
69 }
70 else {
71 0 $$obj = $o->_undent_scalar;
72 }
73 80 ▶ bless $obj, $class if length $class;
Branch: 1 branch
BranchTrueFalseTotal
if length $class 0 80 80
74 }
75 elsif ($o->{content} =~ /^\?\s*$/) {
76 0 $obj = $o->_undent_undef;
77 }
78 else {
79 200 $obj = $o->_undent_value;
80 }
81 280 ▶ while (@refs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@refs) 0 280 280
82 0 my $ref = pop @refs;
83 0 my $copy = $obj;
84 0 $obj = \ $copy;
85 0 ▶ $o->{xref}{$ref} = $obj if $ref;
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
86 }
87 280 return $obj;
88 }
89  
90 sub _undent_value {
91 200 ▶ my $o = shift;
Subroutine _undent_value: called CC=8 SCAR=34.6
92 200 my $value = '';
93 200 ▶ if ($o->{content} =~ /^\<\<(\w+)(\-?)\s*$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->{'content'} =~ /^\<\<(\w+)(\-?)\s*$/) { } 0 200 200
elsif ($o->{'content'} =~ /^\"/) { } 0 200 200
94 0 my ($marker, $chomp) = ($1, $2);
95 0 my $line = $o->{line};
96 0 $o->_next_line;
97 0 ▶ while (not $o->{done} and
Branch: 1 branch
BranchTrueFalseTotal
if (not $o->{"done"} and $o->{"lines"}[0] ne $marker) 0 0 0
Condition0%0/3
not $o->{"done"} and $o->{"lines"}[0] ne $marker
!ll&&!rl&&r
000
MC/DC0%0/2
not $o->{"done"} and $o->{"lines"}[0] ne $marker
not $o->{"done"} $o->{"lines"}[0] ne $marker
Truth table0%0/3
not(A) and B
A= not $o->{"done"}B= $o->{"lines"}[0] ne $marker
ABresult
0X0
100
111
98 $o->{lines}[0] ne $marker) {
99 0 $value .= $o->{lines}[0] . "\n";
100 0 $o->_next_line;
101 }
102 0 ▶ croak M03_no_value_end_marker($marker, $line) if $o->{done};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"done"} 0 0 0
103 0 ▶ chomp $value if $chomp;
Branch: 1 branch
BranchTrueFalseTotal
if $chomp 0 0 0
104 }
105 elsif ($o->{content} =~ /^\"/) {
106 0 ▶ croak $o->M04_mismatched_quotes unless $o->{content} =~ /^\".*\"\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"content"} =~ /^\".*\"\s*$/ 0 0 0
107 0 ($value = $o->{content}) =~ s/^\"|\"\s*$//g;
108 }
109 else {
110 200 $value = $o->{content};
111 }
112 200 $o->_next_line;
113 200 $o->_setup_line;
114 200 return $value;
115 }
116  
117 sub _undent_hash {
118 80 ▶ my @values;
Subroutine _undent_hash: called CC=5 SCAR=16.4
119 80 my $o = shift;
120 80 my $level = $o->{level} + 1;
121 80 $o->_next_line;
122 80 $o->_setup_line;
123 80 ▶ while ($o->{level} == $level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"level"} == $level) 180 80 260
124 180 my ($key, $value) = split $o->{comma}, $o->{content};
125 180 ▶ croak $o->M05_invalid_key_value unless (defined $key and defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and defined $value 0 180 180
Condition33%1/3
defined $key and defined $value
!ll&&!rl&&r
00180
MC/DC0%0/2
defined $key and defined $value
defined $key defined $value
Truth table33%1/3
A and B
A= defined $keyB= defined $value
ABresult
0X0
100
111
126 180 $o->{content} = $value;
127 180 push @values, $o->_get_key($key), $o->_undent_data;;
128 }
129 80 ▶ croak $o->M06_invalid_indent_level if $o->{level} > $level;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"level"} > $level 0 80 80
130 80 return @values;
131 }
132  
133 sub _get_key {
134 180 ▶ my ($o, $key) = @_;
Subroutine _get_key: called CC=6 SCAR=34.2
135 180 ▶ return $key unless $key =~ /^\<\<(\w+)(\-?)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /^\<\<(\w+)(\-?)/ 180 0 180
136 0 my ($marker, $chomp) = ($1, $2);
137 0 $key = '';
138 0 my $line = $o->{line};
139 0 $o->_next_line;
140 0 ▶ while (not $o->{done} and
Branch: 1 branch
BranchTrueFalseTotal
if (not $o->{"done"} and $o->{"lines"}[0] ne $marker) 0 0 0
Condition0%0/3
not $o->{"done"} and $o->{"lines"}[0] ne $marker
!ll&&!rl&&r
000
MC/DC0%0/2
not $o->{"done"} and $o->{"lines"}[0] ne $marker
not $o->{"done"} $o->{"lines"}[0] ne $marker
Truth table0%0/3
not(A) and B
A= not $o->{"done"}B= $o->{"lines"}[0] ne $marker
ABresult
0X0
100
111
141 $o->{lines}[0] ne $marker) {
142 0 $key .= $o->{lines}[0] . "\n";
143 0 $o->_next_line;
144 }
145 0 ▶ croak M02_no_key_end_marker($marker, $line) if $o->{done};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"done"} 0 0 0
146 0 ▶ chomp $key if $chomp;
Branch: 1 branch
BranchTrueFalseTotal
if $chomp 0 0 0
147 0 $o->_next_line;
148 0 $o->_setup_line;
149 0 return $key;
150 }
151  
152 sub _undent_array {
153 0 ▶ my @values;
Subroutine _undent_array: not called CC=3 SCAR=24.8
154 0 my $o = shift;
155 0 my $level = $o->{level} + 1;
156 0 $o->_next_line;
157 0 $o->_setup_line;
158 0 ▶ while ($o->{level} == $level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"level"} == $level) 0 0 0
159 0 push @values, $o->_undent_data;
160 }
161 0 ▶ croak $o->M06_invalid_indent_level if $o->{level} > $level;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"level"} > $level 0 0 0
162 0 return @values;
163 }
164  
165 sub _undent_scalar {
166 0 ▶ my $values;
Subroutine _undent_scalar: not called CC=4 SCAR=30.0
167 0 my $o = shift;
168 0 my $level = $o->{level} + 1;
169 0 $o->_next_line;
170 0 $o->_setup_line;
171 0 ▶ croak $o->M06_invalid_indent_level if $o->{level} != $level;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"level"} != $level 0 0 0
172 0 ▶ croak $o->M07_invalid_scalar_value if $o->{content} =~ /^[\%\@\$\\]/;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"content"} =~ /^[\%\@\$\\]/ 0 0 0
173 0 ▶ return $o->_undent_undef if $o->{content} =~ /^\?/;
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"content"} =~ /^\?/ 0 0 0
174 0 return $o->_undent_value;
175 }
176  
177 sub _undent_undef {
178 0 ▶ my $o = shift;
Subroutine _undent_undef: not called CC=1 SCAR=6.9
179 0 $o->_next_line;
180 0 $o->_setup_line;
181 0 return undef;
182 }
183  
184 sub _next_line {
185 280 ▶ my $o = shift;
Subroutine _next_line: called CC=2 SCAR=7.0
186 280 ▶ $o->{done}++, $o->{level} = -1, return unless @{$o->{lines}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$o->{"lines"};} 0 280 280
187 280 local $_ = shift @{$o->{lines}};
188 280 $o->{line}++;
189 }
190  
191 sub _setup_line {
192 300 ▶ my $o = shift;
Subroutine _setup_line: called CC=5 SCAR=16.4
193 300 ▶ $o->{done}++, $o->{level} = -1, return unless @{$o->{lines}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$o->{"lines"};} 20 280 300
194 280 my ($width, $tabwidth) = @{$o}{qw(width tabwidth)};
195 280 while (1) {
196 280 local $_ = $o->{lines}[0];
197 # expand tabs in leading whitespace;
198 280 ▶ $o->next_line, next if /^(\s*$|\#)/; # skip comments and blank lines
Branch: 1 branch
BranchTrueFalseTotal
if /^(\s*$|\#)/ 0 280 280
199 280 ▶ while (s{^( *)(\t+)}
Branch: 1 branch
BranchTrueFalseTotal
if (s/^( *)(\t+)/" " x (length($1) + length($2) * $tabwidth - length($1) % $tabwidth);/e) 0 280 280
200 0 {' ' x (length($1) + length($2) * $tabwidth -
201 length($1) % $tabwidth)}e){}
202 280 ▶ croak $o->M01_invalid_indent_width unless /^(( {$width})*)(\S.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^(( {$width})*)(\S.*)$/ 0 280 280
203 280 $o->{level} = length($1) / $width;
204 280 $o->{content} = $3;
205 280 last;
206 }
207 }
208  
209 5 1;
210 __END__
« blib/lib/Inline/MakeMaker.pm ↑ Summary blib/lib/Inline/C/ParseRecDescent.pm »