File Coverage

blib/lib/WWW/Shopify/Liquid/Tag/Increment.pm
Criterion Covered Total %
statement 12 31 38.7
branch 0 14 0.0
condition 0 18 0.0
subroutine 4 8 50.0
pod 0 4 0.0
total 16 75 21.3


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2 30     30   16821 use strict;
  30         53  
  30         994  
3 30     30   188 use warnings;
  30         45  
  30         1097  
4              
5             package WWW::Shopify::Liquid::Tag::Increment;
6 30     30   138 use base 'WWW::Shopify::Liquid::Tag::Free';
  30         48  
  30         4815  
7 0     0 0   sub max_arguments { return 1; }
8 0     0 0   sub min_arguments { return 1; }
9             sub verify {
10 0     0 0   my ($self) = @_;
11             die new WWW::Shopify::Liquid::Exception::Parser::Arguments($self, "Requires variable to increment.") unless
12 0 0         $self->{arguments}->[0]->isa('WWW::Shopify::Liquid::Token::Variable');
13             }
14              
15 30     30   174 use Scalar::Util qw(looks_like_number);
  30         53  
  30         8900  
16             sub process {
17 0     0 0   my ($self, $hash, $action, $pipeline) = @_;
18 0 0         my @vars = map { $self->is_processed($_) ? $_ : $_->$action($pipeline, $hash) } @{$self->{arguments}->[0]->{core}};
  0            
  0            
19            
20 0           my $inner_hash = $hash;
21 0           for (0..$#vars-1) {
22 0 0 0       return $self if ref($inner_hash) && ref($inner_hash) eq "HASH" && !exists $inner_hash->{$vars[$_]} && $action eq 'optimize';
      0        
      0        
23 0 0 0       if (looks_like_number($vars[$_]) && ref($inner_hash) && ref($inner_hash) eq "ARRAY") {
      0        
24 0 0         $inner_hash->[$vars[$_]] = {} if !defined $inner_hash->[$vars[$_]];
25 0           $inner_hash = $inner_hash->[$vars[$_]];
26             } else {
27 0 0         $inner_hash->{$vars[$_]} = {} if !exists $inner_hash->{$vars[$_]};
28 0           $inner_hash = $inner_hash->{$vars[$_]};
29             }
30             }
31 0 0 0       if (exists $inner_hash->{$vars[-1]} && looks_like_number($inner_hash->{$vars[-1]})) {
32 0           $inner_hash->{$vars[-1]}++;
33             }
34 0           return '';
35            
36             }
37              
38              
39              
40             1;