File Coverage

blib/lib/WWW/Shopify/Liquid/Operator/And.pm
Criterion Covered Total %
statement 28 32 87.5
branch 7 10 70.0
condition 4 9 44.4
subroutine 8 8 100.0
pod 0 4 0.0
total 47 63 74.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2 37     37   15302 use strict;
  37         112  
  37         1174  
3 37     37   247 use warnings;
  37         99  
  37         1442  
4              
5             package WWW::Shopify::Liquid::Operator::And;
6 37     37   292 use base 'WWW::Shopify::Liquid::Operator';
  37         206  
  37         5218  
7 1318     1318 0 5018 sub symbol { return ('&&', 'and'); }
8 1190     1190 0 2776 sub priority { return 3; }
9 37     37   309 use Scalar::Util qw(blessed);
  37         103  
  37         12578  
10              
11             sub optimize {
12 3     3 0 13 my ($self, $optimizer, $hash) = @_;
13 3 50 33     44 die new WWW::Shopify::Liquid::Exception("Cannot optimize without a valid optimizer.")
      33        
14             unless $optimizer && blessed($optimizer) && $optimizer->isa('WWW::Shopify::Liquid::Optimizer');
15 3         10 my @ops = @{$self->{operands}};
  3         14  
16 3         11 $ops[$_] = $ops[$_]->optimize($optimizer, $hash) for (grep { !$self->is_processed($ops[$_]) } (0..$#ops));
  6         25  
17            
18 3 50       11 if (int(grep { !$self->is_processed($_) } @ops) > 0) {
  6         27  
19             # This is false, if any of the arguments are false.
20 3 100       8 return 0 if (int(grep { $self->is_processed($_) && !$_ } @ops) > 0);
  6 100       22  
21             # All processed arguments, then should be eliminated, because they must be true.
22 2         7 @ops = grep { !$self->is_processed($_) } @ops;
  4         15  
23 2 50       15 return $ops[0] if (int(@ops) == 1);
24 0         0 $self->{operands} = \@ops;
25 0         0 return $self;
26             }
27 0         0 $optimizer->security->check_operate($self, $hash, "optimize", @ops);
28 0         0 return $self->operate($hash, "optimize", @ops);
29             }
30              
31 24   66 24 0 116 sub operate { return $_[3] && $_[4]; }
32              
33             1;