File Coverage

blib/lib/WWW/Shopify/Liquid/Operator/And.pm
Criterion Covered Total %
statement 12 32 37.5
branch 0 10 0.0
condition 0 9 0.0
subroutine 4 8 50.0
pod 0 4 0.0
total 16 63 25.4


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2 30     30   16075 use strict;
  30         53  
  30         1104  
3 30     30   128 use warnings;
  30         47  
  30         1055  
4              
5             package WWW::Shopify::Liquid::Operator::And;
6 30     30   142 use base 'WWW::Shopify::Liquid::Operator';
  30         56  
  30         3198  
7 0     0 0   sub symbol { return ('&&', 'and'); }
8 0     0 0   sub priority { return 3; }
9 30     30   173 use Scalar::Util qw(blessed);
  30         51  
  30         9802  
10              
11             sub optimize {
12 0     0 0   my ($self, $optimizer, $hash) = @_;
13 0 0 0       die new WWW::Shopify::Liquid::Exception("Cannot optimize without a valid optimizer.")
      0        
14             unless $optimizer && blessed($optimizer) && $optimizer->isa('WWW::Shopify::Liquid::Optimizer');
15 0           my @ops = @{$self->{operands}};
  0            
16 0           $ops[$_] = $ops[$_]->optimize($optimizer, $hash) for (grep { !$self->is_processed($ops[$_]) } (0..$#ops));
  0            
17            
18 0 0         if (int(grep { !$self->is_processed($_) } @ops) > 0) {
  0            
19             # This is false, if any of the arguments are false.
20 0 0         return 0 if (int(grep { $self->is_processed($_) && !$_ } @ops) > 0);
  0 0          
21             # All processed arguments, then should be eliminated, because they must be true.
22 0           @ops = grep { !$self->is_processed($_) } @ops;
  0            
23 0 0         return $ops[0] if (int(@ops) == 1);
24 0           $self->{operands} = \@ops;
25 0           return $self;
26             }
27 0           $optimizer->security->check_operate($self, $hash, "optimize", @ops);
28 0           return $self->operate($hash, "optimize", @ops);
29             }
30              
31 0   0 0 0   sub operate { return $_[3] && $_[4]; }
32              
33             1;