Template/Executor.pm

filter: Statementstmt 93.1% 41 / 44 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 88.2% 60 / 68 CC 5 SCAR 6.8
CC
5
Cov
89%
adapter
3.8
__ANON__
3.0
execute
1.0
CRAP 2.0
« Template/Base.pm ↑ Summary Template/JSAdapter/JE.pm »
1 8 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 EJS::Template::Executor - Executes JavaScript generated by EJS::Template
8  
9 =cut
10  
11 package EJS::Template::Executor;
12 8 ▶use base qw(EJS::Template::Base EJS::Template::IO);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶use EJS::Template::JSAdapter;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use EJS::Template::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 Methods
18  
19 =head2 execute
20  
21 Executes JavaScript code.
22  
23 $executor->execute($input, $variables, $output);
24  
25 The C<$input> is used as the JavaScript source code, C<$variables> is a hash
26 ref of variables for JavaScript, and C<$output> is the output destination
27  
28 =cut
29  
30 63 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.0
Pod documented
31 63 my ($self, $input, $variables, $output) = @_;
32
33 63 my $js;
34  
35 63 ▶ $self->input($input, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 63 my ($in) = @_;
37 63 local $/;
38 63 $js = <$in>;
39 63 });
40  
41 63 my $ret;
42  
43 63 ▶ $self->output($output, sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
44 63 my ($out) = @_;
45  
46 63 my $runtime = EJS::Template::Runtime->new($self);
47 63 my $adapter = $self->adapter;
48 63 ▶ $adapter->bind({print => sub { print $out @_ }});
Subroutine __ANON__: called CC=1 SCAR=0.0
49 63 $adapter->bind({EJS => $runtime->make_map()});
50 63 $adapter->bind($variables);
51  
52 63 ▶ if (defined($js)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $js) { } 62 1 63
53 62 $ret = $adapter->eval($js);
54 62 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 62 62
55 } else {
56 1 $ret = 1;
57 }
58 63 });
59
60 63 return $ret;
61 }
62  
63 =head2 adapter
64  
65 Usage:
66  
67 # Getter
68 $executor->adapter;
69  
70 # Setter
71 $executor->adapter(EJS::Template::JSAdapter->create('JE'));
72  
73 Gets or sets an C<EJS::Template::JSAdapter> object.
74  
75 =cut
76  
77 68 ▶sub adapter {
Subroutine adapter: called CC=3 SCAR=13.5
Pod documented
78 68 my $self = shift;
79  
80 68 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 68 68
81 0 my $old = $self->{adapter};
82 0 $self->{adapter} = shift;
83 0 return $old;
84 } else {
85 68 ▶ return $self->{adapter} ||= EJS::Template::JSAdapter->create($self->{config}{engine});
Condition66%2/3
$self->{"adapter"} ||= "EJS::Template::JSAdapter"->create($self->{"config"}{"engine"})
l!l&&r!l&&!r
14540
MC/DC0%0/2
$self->{"adapter"} ||= "EJS::Template::JSAdapter"->create($self->{"config"}{"engine"})
$self->{"adapter"} "EJS::Template::JSAdapter"->create($self->{"config"}{"engine"})
Truth table66%2/3
A ||= B
A= $self->{"adapter"}B= "EJS::Template::JSAdapter"->create($self->{"config"}{"engine"})
ABresult
1X1
011
000
86 }
87 }
88  
89  
90 =head1 SEE ALSO
91  
92 =over 4
93  
94 =item * L<EJS::Template>
95  
96 =back
97  
98 =cut
99  
100 8 1;
« Template/Base.pm ↑ Summary Template/JSAdapter/JE.pm »