File Coverage

blib/lib/WWW/Shopify/Liquid/Tag/Decrement.pm
Criterion Covered Total %
statement 23 31 74.1
branch 3 14 21.4
condition 0 15 0.0
subroutine 6 8 75.0
pod 0 4 0.0
total 32 72 44.4


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