File Coverage

blib/lib/WWW/Shopify/Liquid/Filter.pm
Criterion Covered Total %
statement 44 44 100.0
branch 6 8 75.0
condition 6 9 66.6
subroutine 17 17 100.0
pod 0 10 0.0
total 73 88 82.9


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 37     37   111329 use strict;
  37         118  
  37         1064  
4 37     37   216 use warnings;
  37         166  
  37         1043  
5              
6 37     37   619 use WWW::Shopify::Liquid;
  37         103  
  37         902  
7 37     37   272 use WWW::Shopify::Liquid::Element;
  37         88  
  37         1372  
8              
9             package WWW::Shopify::Liquid::Filter;
10 37     37   229 use base 'WWW::Shopify::Liquid::Element';
  37         105  
  37         22089  
11 74     74 0 294 sub subelements { qw(operand arguments) }
12              
13 143     143 0 424 sub new { my $package = shift; my $parser = shift; return bless { line => shift, core => shift, operand => shift, arguments => [@_] }, $package; }
  143         318  
  143         1088  
14             # Determines whether or not this acts as a variable with no arguments, when used in conjucntion to a dot on a variable.
15 4575     4575 0 20890 sub transparent { return 0; }
16 5838 50   5838 0 16165 sub name { my $package = ref($_[0]) ? ref($_[0]) : $_[0]; $package =~ s/^.*:://; $package =~ s/([a-z])([A-Z])/$1_$2/g; return lc($package); }
  5838         25116  
  5838         23044  
  5838         33273  
17 71     71 0 518 sub min_arguments { return 0; }
18 65     65 0 366 sub max_arguments { return undef; }
19             sub verify {
20 143     143 0 440 my ($self) = @_;
21 143         284 my $count = int(@{$self->{arguments}});
  143         699  
22 143 100 66     815 die new WWW::Shopify::Liquid::Exception::Parser::Arguments($self, [$count, $self->min_arguments, $self->max_arguments]) if
      66        
23             $count < $self->min_arguments || (defined $self->max_arguments && $count > $self->max_arguments);
24             }
25              
26             sub tokens {
27 8     8 0 20 my ($self) = @_;
28 8 50       15 return ($self, map { $self->is_processed($_) ? $_ : $_->tokens } (@{$_[0]->{arguments}}, $_[0]->{operand}));
  8         27  
  8         22  
29             }
30              
31             sub process {
32 74     74 0 266 my ($self, $hash, $action, $pipeline) = @_;
33 74         442 my ($operand, $arguments) = $self->process_subelements($hash, $action, $pipeline);
34 74 100 66     297 return $self unless $self->is_processed($operand) && int(grep { !$self->is_processed($_) } @$arguments) == 0;
  40         142  
35 64         375 return $self->operate($hash, $operand, @$arguments);
36             }
37              
38             sub stringify {
39 1     1 0 23 return $_[0]->{core};
40             }
41              
42             package WWW::Shopify::Liquid::Filter::Unknown;
43 37     37   344 use base 'WWW::Shopify::Liquid::Filter';
  37         193  
  37         4457  
44              
45             # Don't optimize anything on unknown filters.
46 2     2   9 sub optimize { return $_[0]; }
47              
48             1;