File Coverage

blib/lib/WWW/Shopify/Liquid/Operator/Or.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   15936 use strict;
  30         51  
  30         863  
3 30     30   110 use warnings;
  30         46  
  30         1101  
4              
5             package WWW::Shopify::Liquid::Operator::Or;
6 30     30   138 use base 'WWW::Shopify::Liquid::Operator';
  30         63  
  30         3195  
7 0     0 0   sub symbol { return ('||', 'or'); }
8 0     0 0   sub priority { return 4; }
9 30     30   162 use Scalar::Util qw(blessed);
  30         44  
  30         9147  
10              
11              
12             sub optimize {
13 0     0 0   my ($self, $optimizer, $hash) = @_;
14 0 0 0       die new WWW::Shopify::Liquid::Exception("Cannot optimize without a valid optimizer.")
      0        
15             unless $optimizer && blessed($optimizer) && $optimizer->isa('WWW::Shopify::Liquid::Optimizer');
16 0           my @ops = @{$self->{operands}};
  0            
17 0           $ops[$_] = $ops[$_]->optimize($optimizer, $hash) for (grep { !$self->is_processed($ops[$_]) } (0..$#ops));
  0            
18            
19 0 0         if (int(grep { !$self->is_processed($_) } @ops) > 0) {
  0            
20             # This is true, if any of the arguments are true.
21 0 0         return 1 if (int(grep { $self->is_processed($_) && $_ } @ops) > 0);
  0 0          
22             # All processed arguments, then should be eliminated, because they must be false.
23 0           @ops = grep { !$self->is_processed($_) } @ops;
  0            
24 0 0         return $ops[0] if (int(@ops) == 1);
25 0           $self->{operands} = \@ops;
26 0           return $self;
27             }
28 0           $optimizer->security->check_operate($self, $hash, "optimize", @ops);
29 0           return $self->operate($hash, "optimize", @ops);
30             }
31              
32 0   0 0 0   sub operate { return $_[3] || $_[4]; }
33              
34             1;