blib/lib/Text/APL/Parser.pm

filter: Statementstmt 100% 65 / 65 Branchbran 100% 30 / 30 Conditioncond 73.3% 11 / 15 MC/DCmcdc 55.5% 5 / 9 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 93.8% 121 / 129 SCAR 31.8
CC
24
Cov
96%
parse
13.0
_BUILD
4.2
_build_token
4.0
CRAP 24.0
↑ Summary blib/lib/Text/APL/Core.pm »
1 package Text::APL::Parser;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base 'Text::APL::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub _BUILD {
9 37 ▶ my $self = shift;
Subroutine _BUILD: called CC=4 SCAR=14.5
10  
11 37 ▶ $self->{start_token} ||= '<%';
Condition50%1/2
$self->{"start_token"} ||= "<%"
l!l
037
MC/DC0%0/1
$self->{"start_token"} ||= "<%"
$self->{"start_token"}
Truth table50%1/2
A
A= $self->{"start_token"}
Aresult
11
00
12 37 ▶ $self->{end_token} ||= '%>';
Condition50%1/2
$self->{"end_token"} ||= "%>"
l!l
037
MC/DC0%0/1
$self->{"end_token"} ||= "%>"
$self->{"end_token"}
Truth table50%1/2
A
A= $self->{"end_token"}
Aresult
11
00
13  
14 37 ▶ $self->{line_token} ||= '%';
Condition50%1/2
$self->{"line_token"} ||= "%"
l!l
037
MC/DC0%0/1
$self->{"line_token"} ||= "%"
$self->{"line_token"}
Truth table50%1/2
A
A= $self->{"line_token"}
Aresult
11
00
15  
16 37 $self->{leftover_token} = $self->_build_leftover_pattern;
17  
18 37 return $self;
19 }
20  
21 sub parse {
22 63 ▶ my $self = shift;
Subroutine parse: called CC=13 SCAR=25.7
Pod documented
23 63 my ($input) = @_;
24  
25 63 my $TOKEN_START = qr/$self->{start_token}/;
26 63 my $TOKEN_END = qr/$self->{end_token}/;
27 63 my $TOKEN = qr/$TOKEN_START(==?)? [ ] (.*?) \s* $TOKEN_END/xms;
28  
29 63 my $LINE_TOKEN_START = qr/^ \s* $self->{line_token} /xms;
30 63 my $LINE_TOKEN = qr/$LINE_TOKEN_START(==?)? \s* ([^\n]*)/xms;
31  
32 63 my $LEFTOVER_TOKEN = $self->{leftover_token};
33  
34 63 ▶ if (!defined $input) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $input) 24 39 63
35 24 ▶ return [] unless defined $self->{buffer};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"buffer"} 12 12 24
36  
37 12 my $buffer = delete $self->{buffer};
38 12 ▶ return [$buffer =~ m/$LINE_TOKEN/xms
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ /$LINE_TOKEN/msx ? : 9 3 12
39 ? $self->_build_line_token($1, $2)
40 : $self->_build_text($buffer)
41 ];
42 }
43  
44 39 ▶ if (defined $self->{buffer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"buffer"}) 2 37 39
45 2 $input = delete($self->{buffer}) . $input;
46 }
47  
48 39 my $tape = [];
49  
50 39 pos $input = 0;
51 39 ▶ while (pos $input < length $input) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $input < length $input) 62 18 80
52 62 ▶ if ($input =~ m/\G $TOKEN/gcxms) {
Branch: 3 branches
BranchTrueFalseTotal
if ($input =~ /\G $TOKEN/cgmsx) { } 16 46 62
elsif ($input =~ /\G $LINE_TOKEN \n/cgmsx) { } 14 32 46
elsif ($input =~ /\G (.+?) (?=$TOKEN_START | $LINE_TOKEN_START)/cgmsx) { } 11 21 32
53 16 push @$tape, $self->_build_token($1, $2);
54 }
55 elsif ($input =~ m/\G $LINE_TOKEN \n/gcxms) {
56 14 push @$tape, $self->_build_line_token($1, $2);
57 }
58 elsif ($input =~ m/\G (.+?) (?=$TOKEN_START | $LINE_TOKEN_START)/gcxms) {
59 11 push @$tape, $self->_build_text($1);
60 }
61 else {
62 21 ▶ if ($input =~ m/( (?:$TOKEN_START | $LINE_TOKEN_START) .* )/gcxms) {
Branch: 2 branches
BranchTrueFalseTotal
if ($input =~ /( (?:$TOKEN_START | $LINE_TOKEN_START) .* )/cgmsx) { } 13 8 21
elsif ($input =~ /( $LEFTOVER_TOKEN ) $/cgmsx) { } 1 7 8
63 13 $self->{buffer} = $1;
64 }
65 elsif ($input =~ m/( $LEFTOVER_TOKEN ) $/gcxms) {
66 1 $self->{buffer} = $1;
67 }
68  
69 21 my $value = substr($input, pos($input));
70  
71 21 ▶ if (defined $value && $value ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value ne "") 7 14 21
Condition66%2/3
defined $value and $value ne ""
!ll&&!rl&&r
0147
MC/DC50%1/2
defined $value and $value ne ""
defined $value $value ne ""
Truth table66%2/3
A and B
A= defined $valueB= $value ne ""
ABresult
0X0
100
111
72 7 push @$tape, $self->_build_text($value);
73 }
74  
75 21 last;
76 }
77 }
78  
79 39 $tape;
80 }
81  
82 sub _build_token {
83 16 ▶ my $self = shift;
Subroutine _build_token: called CC=4 SCAR=13.9
84 16 my ($modifier, $value) = @_;
85  
86 16 ▶ my $token = {type => defined $modifier ? 'expr' : 'exec', value => $value};
Branch: 1 branch
BranchTrueFalseTotal
defined $modifier ? : 12 4 16
87 16 ▶ $token->{as_is} = 1 if defined $modifier && length $modifier == 2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $modifier and length $modifier == 2 3 13 16
Condition100%3/3
defined $modifier and length $modifier == 2
!ll&&!rl&&r
493
MC/DC100%2/2
defined $modifier and length $modifier == 2
defined $modifier length $modifier == 2
Truth table100%3/3
A and B
A= defined $modifierB= length $modifier == 2
ABresult
0X0
100
111
88  
89 16 return $token;
90 }
91  
92 sub _build_line_token {
93 23 ▶ my $self = shift;
Subroutine _build_line_token: called CC=4 SCAR=13.9
94 23 my ($modifier, $value) = @_;
95  
96 23 ▶ my $token = {type => defined $modifier ? 'expr' : 'exec', value => $value, line => 1};
Branch: 1 branch
BranchTrueFalseTotal
defined $modifier ? : 12 11 23
97 23 ▶ $token->{as_is} = 1 if defined $modifier && length $modifier == 2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $modifier and length $modifier == 2 5 18 23
Condition100%3/3
defined $modifier and length $modifier == 2
!ll&&!rl&&r
1175
MC/DC100%2/2
defined $modifier and length $modifier == 2
defined $modifier length $modifier == 2
Truth table100%3/3
A and B
A= defined $modifierB= length $modifier == 2
ABresult
0X0
100
111
98  
99 23 return $token;
100 }
101  
102 sub _build_text {
103 21 ▶ my $self =shift;
Subroutine _build_text: called CC=1 SCAR=0.0
104 21 my ($value) = @_;
105  
106 21 return {type => 'text', value => $value};
107 }
108  
109 sub _build_leftover_pattern {
110 37 ▶ my $self = shift;
Subroutine _build_leftover_pattern: called CC=3 SCAR=11.0
111  
112 37 my @token = split //, $self->{start_token};
113  
114 37 my $pattern = '';
115 37 $pattern .= '(?:' . $_ for @token;
116 37 $pattern .= ')?' for @token;
117 37 $pattern =~ s{\?$}{};
118  
119 37 return qr/$pattern/;
120 }
121  
122 3 1;
123 __END__
↑ Summary blib/lib/Text/APL/Core.pm »