| 1 | 1 | ▶ | use 5.006; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | EJS::Template::JSAdapter::JavaScript::V8 | ||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | =cut | ||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | package EJS::Template::JSAdapter::JavaScript::V8; | ||||||||||||||||||||||
| 12 | 1 | ▶ | use base 'EJS::Template::JSAdapter'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | 1 | ▶ | use EJS::Template::Util qw(clean_text_ref); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 1 | ▶ | use Scalar::Util qw(reftype tainted); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | 1 | our $ENCODE_UTF8 = 0; | |||||||||||||||||||||
| 18 | 1 | our $SANITIZE_UTF8 = 0; | |||||||||||||||||||||
| 19 | 1 | our $FORCE_UNTAINT = 1; | |||||||||||||||||||||
| 20 | 1 | our $PRESERVE_UTF8 = 1; | |||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | =head1 Methods | ||||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | =head2 new | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | Creates an adapter object. | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | 1 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||
| 31 | 1 | my ($class) = @_; | |||||||||||||||||||||
| 32 | 0 | ▶ | eval 'use JavaScript::V8'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||
| 33 | 1 | ▶ | die $@ if $@; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 34 | 0 | my $engine = JavaScript::V8::Context->new(); | |||||||||||||||||||||
| 35 | 0 | return bless {engine => $engine}, $class; | |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | =head2 bind | ||||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | Implements the bind method. | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 0 | ▶ | sub bind { | ||||||||||||||||||||
|
Subroutine
bind: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 45 | 0 | my ($self, $variables) = @_; | |||||||||||||||||||||
| 46 | 0 | my $engine = $self->engine; | |||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | 0 | my $assign_value; | |||||||||||||||||||||
| 49 | my $assign_hash; | ||||||||||||||||||||||
| 50 | 0 | my $assign_array; | |||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 0 | ▶ | $assign_value = sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||
| 53 | 0 | my ($target_ref, $source_ref) = @_; | |||||||||||||||||||||
| 54 | 0 | my $reftype = reftype $$source_ref; | |||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | 0 | ▶ | if ($reftype) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 57 | 0 | ▶ | if ($reftype eq 'HASH') { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 58 | 0 | $assign_hash->($$target_ref = {}, $$source_ref); | |||||||||||||||||||||
| 59 | } elsif ($reftype eq 'ARRAY') { | ||||||||||||||||||||||
| 60 | 0 | $assign_array->($$target_ref = [], $$source_ref); | |||||||||||||||||||||
| 61 | } elsif ($reftype eq 'CODE') { | ||||||||||||||||||||||
| 62 | 0 | $$target_ref = $$source_ref; | |||||||||||||||||||||
| 63 | } elsif ($reftype eq 'SCALAR') { | ||||||||||||||||||||||
| 64 | 0 | $assign_value->($target_ref, $$source_ref); | |||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||
| 66 | # ignore? | ||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||
| 69 | 0 | my $text_ref = clean_text_ref($source_ref, $ENCODE_UTF8, $SANITIZE_UTF8, $FORCE_UNTAINT); | |||||||||||||||||||||
| 70 | 0 | $$target_ref = $$text_ref; | |||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||
| 72 | 0 | }; | |||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | 0 | ▶ | $assign_hash = sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 75 | 0 | my ($target, $source) = @_; | |||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | 0 | for my $name (keys %$source) { | |||||||||||||||||||||
| 78 | 0 | $assign_value->(\$target->{$name}, \$source->{$name}); | |||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | 0 | }; | |||||||||||||||||||||
| 81 | |||||||||||||||||||||||
| 82 | 0 | ▶ | $assign_array = sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 83 | 0 | my ($target, $source) = @_; | |||||||||||||||||||||
| 84 | 0 | my $len = scalar(@$source); | |||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | 0 | ▶ | for (my $i = 0; $i < $len; $i++) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 87 | 0 | $assign_value->(\$target->[$i], \$source->[$i]); | |||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||
| 89 | 0 | }; | |||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | 0 | my $clone = {}; | |||||||||||||||||||||
| 92 | 0 | $assign_hash->($clone, $variables); | |||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | 0 | for my $name (keys %$clone) { | |||||||||||||||||||||
| 95 | 0 | $engine->bind($name, $clone->{$name}); | |||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | 0 | return $engine; | |||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | =head1 SEE ALSO | ||||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | =over 4 | ||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | =item * L<EJS::Template> | ||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | =item * L<EJS::Template::JSAdapter> | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | =item * L<JavaScript::V8> | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | =back | ||||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | 1 | 1; | |||||||||||||||||||||