Template/JSAdapter/JE.pm

filter: Statementstmt 100% 74 / 74 Branchbran 85.7% 12 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 20 / 20 Podpod 100% 2 / 2 totaltotal 98.1% 108 / 110 CC 9 SCAR 5.8
CC
9
Cov
98%
__ANON__
6.0
new
2.0
__ANON__
2.0
CRAP 1.8
« Template/Executor.pm ↑ Summary Template/Runtime.pm »
1 7 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 EJS::Template::JSAdapter::JE
8  
9 =cut
10  
11 package EJS::Template::JSAdapter::JE;
12 7 ▶use base 'EJS::Template::JSAdapter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 7 ▶use EJS::Template::Util qw(clean_text_ref);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 6 our $ENCODE_UTF8 = 0;
18 6 our $SANITIZE_UTF8 = 0;
19 6 our $FORCE_UNTAINT = 0;
20 6 our $PRESERVE_UTF8 = 1;
21  
22 =head1 Methods
23  
24 =head2 new
25  
26 Creates an adapter object.
27  
28 =cut
29  
30 56 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
31 56 my ($class) = @_;
32 7 ▶ eval 'use JE';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
33 56 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 55 55
34 56 my $engine = JE->new;
35 56 return bless {engine => $engine}, $class;
36 }
37  
38 =head2 bind
39  
40 Implements the bind method.
41  
42 =cut
43  
44 195 ▶sub bind {
Subroutine bind: called CC=1 SCAR=0.0
Pod documented
45 195 my ($self, $variables) = @_;
46 195 my $engine = $self->engine;
47
48 195 my $assign_value;
49 my $assign_hash;
50 195 my $assign_array;
51
52 1275 ▶ $assign_value = sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
53 1275 my ($target_ref, $source_ref) = @_;
54 1275 my $reftype = reftype $$source_ref;
55
56 1275 ▶ if ($reftype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reftype) { } 795 479 1274
57 796 ▶ if ($reftype eq 'HASH') {
Branch: 4 branches
BranchTrueFalseTotal
if ($reftype eq 'HASH') { } 141 654 795
elsif ($reftype eq 'ARRAY') { } 82 572 654
elsif ($reftype eq 'CODE') { } 568 4 572
elsif ($reftype eq 'SCALAR') { } 0 4 4
58 142 $assign_hash->($$target_ref = {}, $$source_ref);
59 } elsif ($reftype eq 'ARRAY') {
60 83 $assign_array->($$target_ref = [], $$source_ref);
61 } elsif ($reftype eq 'CODE') {
62 569 $$target_ref = $$source_ref;
63 } elsif ($reftype eq 'SCALAR') {
64 1 $assign_value->($target_ref, $$source_ref);
65 } else {
66 # ignore?
67 }
68 } else {
69 479 my $text_ref = clean_text_ref($source_ref, $ENCODE_UTF8, $SANITIZE_UTF8, $FORCE_UNTAINT);
70 479 $$target_ref = $$text_ref;
71 }
72 195 };
73
74 336 ▶ $assign_hash = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
75 335 my ($target, $source) = @_;
76
77 335 for my $name (keys %$source) {
78 980 $assign_value->(\$target->{$name}, \$source->{$name});
79 }
80 195 };
81
82 83 ▶ $assign_array = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
83 82 my ($target, $source) = @_;
84 82 my $len = scalar(@$source);
85
86 82 ▶ for (my $i = 0; $i < $len; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 294 82 376
87 294 $assign_value->(\$target->[$i], \$source->[$i]);
88 }
89 195 };
90
91 195 $assign_hash->($engine, $variables);
92 195 return $engine;
93 }
94  
95 =head1 SEE ALSO
96  
97 =over 4
98  
99 =item * L<EJS::Template>
100  
101 =item * L<EJS::Template::JSAdapter>
102  
103 =item * L<JE>
104  
105 =back
106  
107 =cut
108  
109 6 1;
« Template/Executor.pm ↑ Summary Template/Runtime.pm »