blib/lib/Localizer/Scanner/Xslate.pm

filter: Statementstmt 98.4% 62 / 63 Branchbran 70.0% 14 / 20 Conditioncond 50.0% 13 / 26 MC/DCmcdc 26.6% 4 / 15 Subroutinesub 100% 11 / 11 Podpod 66.6% 2 / 3 totaltotal 76.8% 106 / 138 CC 21 SCAR 25.8
CC
21
Cov
82%
_walker
22.6
new
3.2
scan_file
2.0
CRAP 13.2
↑ Summary
1 package Localizer::Scanner::Xslate;
2 2 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = "0.05";
7  
8 sub DEBUG () { 0 }
9  
10 2 ▶use Localizer::Dictionary;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Class::Accessor::Lite 0.05 (
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ro => [qw(parser)],
14 2 );
15  
16 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.6
Pod undocumented
17 1 my $class = shift;
18 0 ▶ my %args = @_==1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 1 1
19  
20 1 my $self = bless { }, $class;
21 1 ▶ my $syntax = $args{syntax} || 'TTerse';
Condition50%1/2
$args{'syntax'} || 'TTerse'
l!l
10
MC/DC0%0/1
$args{'syntax'} || 'TTerse'
$args{'syntax'}
Truth table50%1/2
A
A= $args{'syntax'}
Aresult
11
00
22 1 $self->{parser} = $self->_build_parser($syntax);
23  
24 1 return $self;
25 }
26  
27 2 our $RESULT;
28 2 our $FILENAME;
29  
30 1 ▶sub _build_parser {
Subroutine _build_parser: called CC=2 SCAR=7.0
31 1 my ($self, $syntax) = @_;
32  
33 1 ▶ eval "use Text::Xslate::Syntax::${syntax};"; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
35  
36 1 "Text::Xslate::Syntax::${syntax}"->new(),
37 }
38  
39 1 ▶sub scan {
Subroutine scan: called CC=1 SCAR=0.0
Pod documented
40 1 my($self, $result, $filename, $data) = @_;
41 1 my $ast = $self->parser->parse($data);
42 1 local $FILENAME = $filename;
43 1 local $RESULT = $result;
44 1 $self->_walker($ast);
45 1 return $result;
46 }
47  
48 1 ▶sub scan_file {
Subroutine scan_file: called CC=2 SCAR=7.0
Pod documented
49 1 my ($self, $result, $filename) = @_;
50 1 ▶ open my $fh, '<:encoding(utf-8)', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:encoding(utf-8)", $filename or die "Cannot open file '${filename}' for reading: $!" 1 0 1
51 or die "Cannot open file '$filename' for reading: $!";
52 1 my $data = do { local $/; <$fh> };
53 1 return $self->scan($result, $filename, $data);
54 }
55  
56 2 my $sp = '';
57 241 ▶sub _walker {
Subroutine _walker: called CC=17 SCAR=31.2
58 241 my($self, $ast) = @_;
59 241 ▶ $ast = [ $ast ] if $ast && ref($ast) eq 'Text::Xslate::Symbol';
Branch: 1 branch
BranchTrueFalseTotal
if $ast and ref $ast eq "Text::Xslate::Symbol" 18 223 241
Condition100%3/3
$ast and ref $ast eq "Text::Xslate::Symbol"
!ll&&!rl&&r
1863718
MC/DC100%2/2
$ast and ref $ast eq "Text::Xslate::Symbol"
$ast ref $ast eq "Text::Xslate::Symbol"
Truth table100%3/3
A and B
A= $astB= ref $ast eq "Text::Xslate::Symbol"
ABresult
0X0
100
111
60 241 ▶ return unless $ast && ref($ast) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $ast and ref $ast eq "ARRAY" 186 55 241
Condition66%2/3
$ast and ref $ast eq "ARRAY"
!ll&&!rl&&r
186055
MC/DC50%1/2
$ast and ref $ast eq "ARRAY"
$ast ref $ast eq "ARRAY"
Truth table66%2/3
A and B
A= $astB= ref $ast eq "ARRAY"
ABresult
0X0
100
111
61  
62 55 for my $sym (@{ $ast }) {
63  
64 80 ▶ if ($sym->arity eq 'call' && $sym->value eq '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym->arity eq "call" and $sym->value eq "(") 11 69 80
Condition66%2/3
$sym->arity eq "call" and $sym->value eq "("
!ll&&!rl&&r
69011
MC/DC50%1/2
$sym->arity eq "call" and $sym->value eq "("
$sym->arity eq "call" $sym->value eq "("
Truth table66%2/3
A and B
A= $sym->arity eq "call"B= $sym->value eq "("
ABresult
0X0
100
111
65 11 my $first = $sym->first;
66 11 ▶ if ($first && ref($first) eq 'Text::Xslate::Symbol') {
Branch: 1 branch
BranchTrueFalseTotal
if ($first and ref $first eq "Text::Xslate::Symbol") 11 0 11
Condition33%1/3
$first and ref $first eq "Text::Xslate::Symbol"
!ll&&!rl&&r
0011
MC/DC0%0/2
$first and ref $first eq "Text::Xslate::Symbol"
$first ref $first eq "Text::Xslate::Symbol"
Truth table33%1/3
A and B
A= $firstB= ref $first eq "Text::Xslate::Symbol"
ABresult
0X0
100
111
67 11 ▶ if ($first->arity eq 'variable' && $first->value eq 'l') {
Branch: 1 branch
BranchTrueFalseTotal
if ($first->arity eq "variable" and $first->value eq "l") 11 0 11
Condition33%1/3
$first->arity eq "variable" and $first->value eq "l"
!ll&&!rl&&r
0011
MC/DC0%0/2
$first->arity eq "variable" and $first->value eq "l"
$first->arity eq "variable" $first->value eq "l"
Truth table33%1/3
A and B
A= $first->arity eq "variable"B= $first->value eq "l"
ABresult
0X0
100
111
68 11 my $second = $sym->second;
69 11 ▶ if ($second && ref($second) eq 'ARRAY' && $second->[0] && ref($second->[0]) eq 'Text::Xslate::Symbol') {
Branch: 1 branch
BranchTrueFalseTotal
if ($second and ref $second eq "ARRAY" and $second->[0] and ref $second->[0] eq "Text::Xslate::Symbol") 11 0 11
Condition33%3/9
$second and ref $second eq "ARRAY" and $second->[0] and ref $second->[0] eq "Text::Xslate::Symbol"
!ll&&!rl&&r
0011
$second and ref $second eq "ARRAY" and $second->[0]
!ll&&!rl&&r
0011
$second and ref $second eq "ARRAY"
!ll&&!rl&&r
0011
MC/DC0%0/4
$second and ref $second eq "ARRAY" and $second->[0] and ref $second->[0] eq "Text::Xslate::Symbol"
$second ref $second eq "ARRAY" $second->[0] ref $second->[0] eq "Text::Xslate::Symbol"
Truth table20%1/5
A and B and C and D
A= $secondB= ref $second eq "ARRAY"C= $second->[0]D= ref $second->[0] eq "Text::Xslate::Symbol"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
70 11 my $value = $second->[0];
71 11 ▶ if ($value->arity eq 'literal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->arity eq "literal") 10 1 11
72 10 $RESULT->add_entry_position($value->value, $FILENAME, $value->line);
73 }
74 }
75 }
76 }
77 }
78  
79 80 unless (DEBUG) {
80 80 $self->_walker($sym->first);
81 80 $self->_walker($sym->second);
82 80 $self->_walker($sym->third);
83 } else {
84 warn "$sp id: " . $sym->id;
85 warn "$sp line: " . $sym->line;
86 warn "$sp ldp: ". $sym->lbp;
87 warn "$sp udp: ". $sym->ubp;
88 warn "$sp type: ". $sym->type;
89  
90 warn "$sp arity: ". $sym->arity;
91 warn "$sp assignment: ". $sym->assignment;
92 warn "$sp value: ". $sym->value;
93  
94 warn "$sp first: " . $sym->first;
95 $sp .= ' ';
96 $self->_walker($sym->first);
97 $sp =~ s/^.//;
98  
99 warn "$sp second: " . $sym->second;
100 $sp .= ' ';
101 $self->_walker($sym->second);
102 $sp =~ s/^.//;
103  
104 warn "$sp third: " . $sym->third;
105 $sp .= ' ';
106 $self->_walker($sym->third);
107 $sp =~ s/^.//;
108  
109 warn $sp . '----------';
110 }
111 }
112 }
113  
114 2 1;
115 __END__
↑ Summary