line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
24201
|
use strict; |
|
12
|
|
|
|
|
33
|
|
|
12
|
|
|
|
|
372
|
|
4
|
12
|
|
|
12
|
|
53
|
use warnings; |
|
12
|
|
|
|
|
23
|
|
|
12
|
|
|
|
|
311
|
|
5
|
|
|
|
|
|
|
|
6
|
12
|
|
|
12
|
|
435
|
use WWW::Shopify::Liquid; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Designed to wrap objects in the hash taht shoudln't be cloned. Only works for top level. |
9
|
|
|
|
|
|
|
package WWW::Shopify::Liquid::Renderer::NoClone; |
10
|
|
|
|
|
|
|
sub new { return bless { inner => $_[0] }; } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package WWW::Shopify::Liquid::Renderer; |
13
|
|
|
|
|
|
|
use base 'WWW::Shopify::Liquid::Pipeline'; |
14
|
|
|
|
|
|
|
use WWW::Shopify::Liquid::Security; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# WATCH THIS CLONING. IT CAN CAUSE SEGFAULTS DEPENDING ON WHAT'S CLONED. |
17
|
|
|
|
|
|
|
sub new { my $package = shift; return bless { clone_hash => 1, silence_exceptions => 1, timeout => undef, max_inclusion_depth => 5, inclusion_context => undef, inclusion_depth => 0, security => WWW::Shopify::Liquid::Security->new, @_ }, $package; } |
18
|
|
|
|
|
|
|
sub clone_hash { $_[0]->{clone_hash} = $_[1] if defined $_[1]; return $_[0]->{clone_hash}; } |
19
|
|
|
|
|
|
|
sub security { $_[0]->{security} = $_[1] if defined $_[1]; return $_[0]->{security}; } |
20
|
|
|
|
|
|
|
sub silence_exceptions { $_[0]->{silence_exceptions} = $_[1] if defined $_[1]; return $_[0]->{silence_exceptions}; } |
21
|
|
|
|
|
|
|
sub timeout { $_[0]->{timeout} = $_[1] if defined $_[1]; return $_[0]->{timeout}; } |
22
|
|
|
|
|
|
|
sub max_inclusion_depth { $_[0]->{max_inclusion_depth} = $_[1] if defined $_[1]; return $_[0]->{max_inclusion_depth}; } |
23
|
|
|
|
|
|
|
sub inclusion_context { $_[0]->{inclusion_context} = $_[1] if defined $_[1]; return $_[0]->{inclusion_context}; } |
24
|
|
|
|
|
|
|
sub inclusion_depth { $_[0]->{inclusion_depth} = $_[1] if defined $_[1]; return $_[0]->{inclusion_depth}; } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Clone qw(clone); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub render { |
29
|
|
|
|
|
|
|
my ($self, $hash, $ast) = @_; |
30
|
|
|
|
|
|
|
return '' if !$ast && !wantarray; |
31
|
|
|
|
|
|
|
my $hash_clone = $self->clone_hash && $self->clone_hash == 1 ? clone($hash) : $hash; |
32
|
|
|
|
|
|
|
return ('', $hash_clone) unless $ast; |
33
|
|
|
|
|
|
|
my $result; |
34
|
|
|
|
|
|
|
eval { |
35
|
|
|
|
|
|
|
local $SIG{ALRM} = sub { die new WWW::Shopify::Liquid::Exception::Timeout(); }; |
36
|
|
|
|
|
|
|
alarm $self->timeout if $self->timeout; |
37
|
|
|
|
|
|
|
$result = $ast->isa('WWW::Shopify::Liquid::Element') ? $ast->render($self, $hash_clone) : "$ast"; |
38
|
|
|
|
|
|
|
alarm 0; |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
if (my $exp = $@) { |
41
|
|
|
|
|
|
|
die $exp; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
return $result unless wantarray; |
44
|
|
|
|
|
|
|
return ($result, $hash_clone); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |