blib/lib/Text/APL/Core.pm

filter: Statementstmt 100% 86 / 86 Branchbran 66.6% 8 / 12 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 20 / 20 Podpod 0.0% 0 / 1 totaltotal 82.6% 119 / 144 SCAR 25.9
CC
13
Cov
88%
_BUILD
9.9
__ANON__
4.0
render
3.0
CRAP 13.3
« blib/lib/Text/APL/Parser.pm ↑ Summary blib/lib/Text/APL/Reader.pm »
1 package Text::APL::Core;
2  
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 ▶use base 'Text::APL::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.08';
9  
10 2 ▶use Text::APL::Compiler;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Text::APL::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Text::APL::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Text::APL::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Text::APL::Translator;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Text::APL::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub _BUILD {
18 20 ▶ my $self = shift;
Subroutine _BUILD: called CC=6 SCAR=22.9
19  
20 20 ▶ $self->{parser} ||= Text::APL::Parser->new;
Condition33%1/3
$self->{"parser"} ||= "Text::APL::Parser"->new
l!l&&r!l&&!r
0200
MC/DC0%0/2
$self->{"parser"} ||= "Text::APL::Parser"->new
$self->{"parser"} "Text::APL::Parser"->new
Truth table33%1/3
A ||= B
A= $self->{"parser"}B= "Text::APL::Parser"->new
ABresult
1X1
011
000
21 20 ▶ $self->{translator} ||= Text::APL::Translator->new;
Condition33%1/3
$self->{"translator"} ||= "Text::APL::Translator"->new
l!l&&r!l&&!r
0200
MC/DC0%0/2
$self->{"translator"} ||= "Text::APL::Translator"->new
$self->{"translator"} "Text::APL::Translator"->new
Truth table33%1/3
A ||= B
A= $self->{"translator"}B= "Text::APL::Translator"->new
ABresult
1X1
011
000
22 20 ▶ $self->{compiler} ||= Text::APL::Compiler->new;
Condition33%1/3
$self->{"compiler"} ||= "Text::APL::Compiler"->new
l!l&&r!l&&!r
0200
MC/DC0%0/2
$self->{"compiler"} ||= "Text::APL::Compiler"->new
$self->{"compiler"} "Text::APL::Compiler"->new
Truth table33%1/3
A ||= B
A= $self->{"compiler"}B= "Text::APL::Compiler"->new
ABresult
1X1
011
000
23 20 ▶ $self->{reader} ||= Text::APL::Reader->new;
Condition33%1/3
$self->{"reader"} ||= "Text::APL::Reader"->new
l!l&&r!l&&!r
2000
MC/DC0%0/2
$self->{"reader"} ||= "Text::APL::Reader"->new
$self->{"reader"} "Text::APL::Reader"->new
Truth table33%1/3
A ||= B
A= $self->{"reader"}B= "Text::APL::Reader"->new
ABresult
1X1
011
000
24 20 ▶ $self->{writer} ||= Text::APL::Writer->new;
Condition33%1/3
$self->{"writer"} ||= "Text::APL::Writer"->new
l!l&&r!l&&!r
0200
MC/DC0%0/2
$self->{"writer"} ||= "Text::APL::Writer"->new
$self->{"writer"} "Text::APL::Writer"->new
Truth table33%1/3
A ||= B
A= $self->{"writer"}B= "Text::APL::Writer"->new
ABresult
1X1
011
000
25 }
26  
27 sub render {
28 22 ▶ my $self = shift;
Subroutine render: called CC=3 SCAR=11.0
Pod undocumented
29 22 my (%params) = @_;
30  
31 22 my $return = '';
32  
33 my $writer =
34 $self->{writer}
35 22 ▶ ->build(exists $params{output} ? $params{output} : \$return);
Branch: 1 branch
BranchTrueFalseTotal
exists $params{'output'} ? : 0 22 22
36  
37 my $context = Text::APL::Context->new(
38 helpers => $params{helpers},
39 vars => $params{vars},
40 name => $params{name}
41 22 );
42 22 ▶ $context->add_helper(__print => sub { $writer->(@_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
43 $context->add_helper(
44 __print_escaped => sub {
45 18 ▶ my ($input) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
46  
47 18 ▶ return $writer->('') unless defined $input;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 0 18 18
48  
49 18 for ($input) { s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; s/"/&quot;/g; s/'/&#039;/g }
50  
51 18 $writer->($input);
52 }
53 22 );
54  
55 $self->_process(
56 $params{input},
57 $context,
58 sub {
59 21 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
60 21 my ($sub_ref) = @_;
61  
62 21 $sub_ref->($context);
63  
64 21 $writer->();
65 }
66 22 );
67  
68 21 ▶ return exists $params{output} ? $self : $return;
Branch: 1 branch
BranchTrueFalseTotal
exists $params{'output'} ? : 0 21 21
69 }
70  
71 sub _process {
72 20 ▶ my $self = shift;
Subroutine _process: called CC=1 SCAR=0.0
73 20 my ($input, $context, $cb) = @_;
74  
75 $self->_parse(
76 $input => sub {
77 20 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
78 20 my ($tape) = @_;
79  
80 20 my $code = $self->_translate($tape);
81  
82 20 my $sub_ref = $self->_compile($code, $context);
83  
84 19 $cb->($self, $sub_ref);
85 }
86 20 );
87 }
88  
89 sub _parse {
90 20 ▶ my $self = shift;
Subroutine _parse: called CC=1 SCAR=0.0
91 20 my ($input, $cb) = @_;
92  
93 20 my $parser = $self->{parser};
94  
95 20 my $reader = $self->{reader}->build($input);
96  
97 20 my $tape = [];
98 my $reader_cb = sub {
99 40 ▶ my ($chunk) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
100  
101 40 ▶ if (!defined $chunk) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $chunk) { } 20 20 40
102 20 my $leftover = $parser->parse();
103 20 ▶ push @$tape, @$leftover if $leftover;
Branch: 1 branch
BranchTrueFalseTotal
if $leftover 20 0 20
104  
105 20 $cb->($self, $tape);
106 }
107 else {
108 20 my $subtape = $parser->parse($chunk);
109 20 ▶ push @$tape, @$subtape if @$subtape;
Branch: 1 branch
BranchTrueFalseTotal
if @$subtape 12 8 20
110 }
111 20 };
112  
113 20 $reader->($reader_cb, $input);
114 }
115  
116 sub _translate {
117 20 ▶ my $self = shift;
Subroutine _translate: called CC=1 SCAR=0.0
118 20 my ($tape) = @_;
119  
120 20 return $self->{translator}->translate($tape);
121 }
122  
123 sub _compile {
124 21 ▶ my $self = shift;
Subroutine _compile: called CC=1 SCAR=0.0
125 21 my ($code, $context) = @_;
126  
127 21 return $self->{compiler}->compile($code, $context);
128 }
129  
130 2 1;
131 __END__
« blib/lib/Text/APL/Parser.pm ↑ Summary blib/lib/Text/APL/Reader.pm »