| 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::"
MC/DC0%0/1
$self->{"namespace"} ||= "Text::APL::"
$self->{"namespace"}
Truth table50%1/2
A
A= $self->{"namespace"}
| |||||||||||||
| 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__'
MC/DC100%1/1
$context->name || '__anon__'
$context->name
Truth table100%2/2
A
A= $context->name
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||