File Coverage

blib/lib/WWW/Shopify/Liquid/Operator/Or.pm
Criterion Covered Total %
statement 30 32 93.7
branch 8 10 80.0
condition 4 9 44.4
subroutine 8 8 100.0
pod 0 4 0.0
total 50 63 79.3


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2 37     37   14389 use strict;
  37         101  
  37         1169  
3 37     37   225 use warnings;
  37         93  
  37         1403  
4              
5             package WWW::Shopify::Liquid::Operator::Or;
6 37     37   238 use base 'WWW::Shopify::Liquid::Operator';
  37         94  
  37         5141  
7 1318     1318 0 4908 sub symbol { return ('||', 'or'); }
8 12410     12410 0 35946 sub priority { return 4; }
9 37     37   295 use Scalar::Util qw(blessed);
  37         99  
  37         12148  
10              
11              
12             sub optimize {
13 3     3 0 12 my ($self, $optimizer, $hash) = @_;
14 3 50 33     37 die new WWW::Shopify::Liquid::Exception("Cannot optimize without a valid optimizer.")
      33        
15             unless $optimizer && blessed($optimizer) && $optimizer->isa('WWW::Shopify::Liquid::Optimizer');
16 3         7 my @ops = @{$self->{operands}};
  3         16  
17 3         14 $ops[$_] = $ops[$_]->optimize($optimizer, $hash) for (grep { !$self->is_processed($ops[$_]) } (0..$#ops));
  6         24  
18            
19 3 50       11 if (int(grep { !$self->is_processed($_) } @ops) > 0) {
  6         23  
20             # This is true, if any of the arguments are true.
21 3 100       10 return 1 if (int(grep { $self->is_processed($_) && $_ } @ops) > 0);
  6 100       21  
22             # All processed arguments, then should be eliminated, because they must be false.
23 2         10 @ops = grep { !$self->is_processed($_) } @ops;
  4         19  
24 2 100       17 return $ops[0] if (int(@ops) == 1);
25 1         15 $self->{operands} = \@ops;
26 1         6 return $self;
27             }
28 0         0 $optimizer->security->check_operate($self, $hash, "optimize", @ops);
29 0         0 return $self->operate($hash, "optimize", @ops);
30             }
31              
32 239   66 239 0 1382 sub operate { return $_[3] || $_[4]; }
33              
34             1;