File Coverage

blib/lib/WWW/Shopify/Liquid/Pipeline.pm
Criterion Covered Total %
statement 33 44 75.0
branch 13 30 43.3
condition 13 30 43.3
subroutine 13 15 86.6
pod 0 12 0.0
total 72 131 54.9


line stmt bran cond sub pod time code
1              
2 37     37   335 use strict;
  37         102  
  37         1229  
3 37     37   248 use warnings;
  37         103  
  37         1614  
4              
5             package WWW::Shopify::Liquid::Pipeline;
6 37     37   273 use Scalar::Util qw(weaken blessed looks_like_number);
  37         195  
  37         33572  
7       5403 0   sub register_tag { }
8             sub register_operator {
9 9548 50 66 9548 0 40951 die new WWW::Shopify::Liquid::Exception("Cannot have a unary operator, that has infix notation.") if $_[1]->arity eq "unary" && $_[1]->fixness eq "infix";
10             }
11       15739 0   sub register_filter { }
12       0 0   sub deregister_operator { }
13       3 0   sub deregister_tag { }
14       1 0   sub deregister_filter { }
15 0 0   0 0 0 sub strict { $_[0]->{strict} = $_[1] if defined $_[1]; return $_[0]->{strict}; }
  0         0  
16 4003 100   4003 0 9623 sub file_context { $_[0]->{file_context} = $_[1] if @_ > 1; return $_[0]->{file_context}; }
  4003         13282  
17             sub parent {
18 413 100   413 0 1098 if (defined $_[1]) {
19 340         858 $_[0]->{parent} = $_[1];
20 340         1035 weaken($_[0]->{parent});
21             }
22 413         1041 return $_[0]->{parent};
23             }
24              
25             sub is_processed {
26             return !ref($_[1]) ||
27             (ref($_[1]) eq "ARRAY" && int(grep { !$_[0]->is_processed($_) } @{$_[1]}) == 0) ||
28 30660   66 30660 0 242374 (ref($_[1]) eq "HASH" && int(grep { !$_[0]->is_processed($_[1]->{$_}) } keys(%{$_[1]})) == 0) ||
29             (blessed($_[1]) && ref($_[1]) !~ m/^WWW::Shopify::Liquid/ && !$_[1]->isa('WWW::Shopify::Liquid::Element'));
30             }
31              
32             # If static is true, we do not create new indices, we return null.
33             sub variable_reference {
34 6     6 0 25 my ($self, $hash, $indices, $static) = @_;
35            
36 6 100 66     40 if (blessed($indices) && $indices->isa('WWW::Shopify::Liquid::Token::Variable')) {
37 1         3 $indices = [map { $_->{core} } @{$indices->{core}}];
  2         5  
  1         2  
38             }
39            
40 6         24 my @vars = @$indices;
41 6         15 my $inner_hash = $hash;
42 6         26 for (0..$#vars-1) {
43 1 50 33     9 if (looks_like_number($vars[$_]) && ref($inner_hash) && ref($inner_hash) eq "ARRAY") {
      33        
44 0 0       0 if (!defined $inner_hash->[$vars[$_]]) {
45 0 0       0 return () if $static;
46 0         0 $inner_hash->[$vars[$_]] = {};
47             }
48 0         0 $inner_hash = $inner_hash->[$vars[$_]];
49             } else {
50 1 50 33     5 if (blessed($inner_hash) && $inner_hash->isa('WWW::Shopify::Liquid::Resolver')) {
51 0         0 $inner_hash = $inner_hash->resolver->($inner_hash, $hash, $vars[$_]);
52             } else {
53 1 50       4 if (!exists $inner_hash->{$vars[$_]}) {
54 0 0       0 return () if $static;
55 0         0 $inner_hash->{$vars[$_]} = {};
56             }
57 1         2 $inner_hash = $inner_hash->{$vars[$_]};
58             }
59             }
60             }
61 6 50 33     51 if (looks_like_number($vars[-1]) && ref($inner_hash) && ref($inner_hash) eq "ARRAY") {
      33        
62 0 0 0     0 return (\$inner_hash->[$vars[-1]], $inner_hash, $vars[-1]) if int(@$inner_hash) > $vars[-1] || !$static;
63             } else {
64 6 50 66     54 return (\$inner_hash->{$vars[-1]}, $inner_hash, $vars[-1]) if exists $inner_hash->{$vars[-1]} || !$static;
65             }
66 0         0 return ();
67             }
68              
69 177 50   177 0 525 sub make_method_calls { $_[0]->{make_method_calls} = $_[1] if @_ > 1; return $_[0]->{make_method_calls}; }
  177         758  
70              
71             1;