File Coverage

blib/lib/WWW/Shopify/Liquid/Filter.pm
Criterion Covered Total %
statement 34 49 69.3
branch 5 12 41.6
condition 4 9 44.4
subroutine 12 15 80.0
pod 0 9 0.0
total 55 94 58.5


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 21     21   122 use strict;
  21         31  
  21         746  
4 21     21   98 use warnings;
  21         33  
  21         518  
5              
6 21     21   106 use WWW::Shopify::Liquid;
  21         34  
  21         790  
7              
8             package WWW::Shopify::Liquid::Filter;
9 21     21   94 use base 'WWW::Shopify::Liquid::Element';
  21         38  
  21         6173  
10              
11 21     21   124 use List::Util qw(first);
  21         38  
  21         13258  
12              
13 29     29 0 52 sub new { my $package = shift; return bless { line => shift, operand => shift, arguments => [@_] }, $package; }
  29         242  
14             # Determines whether or not this acts as a variable with no arguments, when used in conjucntion to a dot on a variable.
15 1242     1242 0 3904 sub transparent { return 0; }
16 1381 50   1381 0 2410 sub name { my $package = ref($_[0]) ? ref($_[0]) : $_[0]; $package =~ s/^.*:://; $package =~ s/([a-z])([A-Z])/$1_$2/g; return lc($package); }
  1381         5038  
  1381         4928  
  1381         11396  
17 20     20 0 148 sub min_arguments { return 0; }
18 20     20 0 96 sub max_arguments { return undef; }
19             sub verify {
20 29     29 0 52 my ($self) = @_;
21 29         36 my $count = int(@{$self->{arguments}});
  29         196  
22 29 100 66     148 die new WWW::Shopify::Liquid::Exception::Parser::Arguments($self) if
      66        
23             $count < $self->min_arguments || (defined $self->max_arguments && $count > $self->max_arguments);
24             }
25              
26 0     0 0 0 sub tokens { return map { $_->tokens } (@{$_[0]->{arguments}}, $_[0]->{operand}->tokens) }
  0         0  
  0         0  
27              
28             sub render {
29 2     2 0 4 my ($self, $hash) = @_;
30 2 50       16 my $operand = !$self->is_processed($self->{operand}) ? $self->{operand}->render($hash) : $self->{opreand};
31 2 50       4 my @arguments = map { !$self->is_processed($_) ? $_->render($hash) : $_ } @{$self->{arguments}};
  2         7  
  2         5  
32 2         11 return $self->operate($hash, $operand, @arguments);
33             }
34              
35             sub optimize {
36 0     0 0   my ($self, $hash) = @_;
37 0           my $operand = $self->{operand};
38 0 0         $operand = $self->{operand}->optimize($hash) unless $self->is_processed($self->{operand});
39 0           for (grep { !$self->is_processed($self->{arguments}->[$_]) } 0..int(@{$self->{arguments}})-1) {
  0            
  0            
40 0           $self->{arguments}->[$_] = $self->{arguments}->[$_]->optimize($hash);
41             }
42 0 0 0 0     return $self if (!$self->is_processed($self->{operand}) || (defined first { !$self->is_processed($_) } @{$self->{arguments}}));
  0            
  0            
43 0           return $self->operate($hash, $operand, @{$self->{arguments}});
  0            
44             }
45              
46             1;