blib/lib/Text/APL/Compiler.pm

filter: Statementstmt 100% 153 / 153 Branchbran 100% 2 / 2 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 35 / 35 Podpod 100% 1 / 1 totaltotal 98.9% 195 / 197 SCAR 17.9
CC
6
Cov
99%
compile
3.0
_BUILD
2.1
_generate_vars
2.0
CRAP 6.0
« blib/lib/Text/APL/WithCaching.pm ↑ Summary blib/lib/Text/APL/Context.pm »
1 package Text::APL::Compiler;
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 21 ▶ my $self = shift;
Subroutine _BUILD: called CC=2 SCAR=7.2
10  
11 21 ▶ $self->{namespace} ||= 'Text::APL::';
Condition50%1/2
$self->{"namespace"} ||= "Text::APL::"
l!l
020
MC/DC0%0/1
$self->{"namespace"} ||= "Text::APL::"
$self->{"namespace"}
Truth table50%1/2
A
A= $self->{"namespace"}
Aresult
11
00
12 }
13  
14 sub compile {
15 22 ▶ my $self = shift;
Subroutine compile: called CC=3 SCAR=11.0
Pod documented
16 22 my ($code, $context) = @_;
17  
18 22 my $template_class = "$self->{namespace}";
19  
20 22 ▶ $template_class .= '_' . ($context->name || '__anon__') . $context->id;
Condition100%2/2
$context->name || '__anon__'
l!l
219
MC/DC100%1/1
$context->name || '__anon__'
$context->name
Truth table100%2/2
A
A= $context->name
Aresult
11
00
21 22 $template_class =~ s{[^A-Za-z0-9:]}{_}g;
22  
23 22 my $package = '';
24 22 $package .= qq/no strict 'refs'; %{"$template_class\::"} = ();/;
25 22 $package .= "package $template_class;";
26 22 $package .= 'sub {';
27 22 $package .= 'use strict; use warnings;';
28 22 $package .= 'my $__self = $_[0];';
29  
30 22 $package .= $self->_generate_vars($context);
31  
32 22 $package .= $self->_generate_helpers($context);
33  
34 22 $package .= $code . '}';
35  
36 3 ▶ eval $package or die $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval $package or die $@ 1 20 21
37 }
38  
39 sub _generate_vars {
40 22 ▶ my $self = shift;
Subroutine _generate_vars: called CC=2 SCAR=6.9
41 22 my ($context) = @_;
42  
43 22 my $string = '';
44 22 foreach my $var (keys %{$context->vars}) {
45 12 $string .= qq/my \$$var = \$__self->vars->{$var};/;
46 }
47  
48 22 return $string;
49 }
50  
51 sub _generate_helpers {
52 22 ▶ my $self = shift;
Subroutine _generate_helpers: called CC=2 SCAR=6.9
53 22 my ($context) = @_;
54  
55 22 my $string = '';
56  
57 22 $string .= "sub var; local *var = sub { \$__self->vars->{\$_[0]} };";
58 22 foreach my $key (keys %{$context->helpers}) {
59 44 $string .= "sub $key; local *$key = \$__self->helpers->{$key};";
60 }
61  
62 22 return $string;
63 }
64  
65 3 1;
66 __END__
« blib/lib/Text/APL/WithCaching.pm ↑ Summary blib/lib/Text/APL/Context.pm »