blib/lib/WWW/Shopify/Liquid/Tag/Decrement.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 15 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 72 CC 8 SCAR 33.2
CC
8
Cov
0%
process
56.0
verify
6.0
max_arguments
2.0
CRAP 27.7
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4  
5 package WWW::Shopify::Liquid::Tag::Decrement;
6 use base 'WWW::Shopify::Liquid::Tag::Free';
7 sub max_arguments { return 1; }
8 sub min_arguments { return 1; }
9 sub verify {
10 my ($self) = @_;
11 die new WWW::Shopify::Liquid::Exception::Parser::Arguments($self, "Requires variable to decrement.") unless
12 $self->{arguments}->[0]->isa('WWW::Shopify::Liquid::Token::Variable');
13 }
14 use Scalar::Util qw(looks_like_number);
15 sub process {
16 my ($self, $hash, $action, $pipeline) = @_;
17 my @vars = map { $self->is_processed($_) ? $_ : $_->$action($pipeline, $hash) } @{$self->{arguments}->[0]->{core}};
18
19 my $inner_hash = $hash;
20 for (0..$#vars-1) {
21 return $self if ref($inner_hash) && ref($inner_hash) eq "HASH" && !exists $inner_hash->{$vars[$_]} && $action eq 'optimize';
22 if (looks_like_number($vars[$_]) && ref($inner_hash) && ref($inner_hash) eq "ARRAY") {
23 $inner_hash->[$vars[$_]] = {} if !defined $inner_hash->[$vars[$_]];
24 $inner_hash = $inner_hash->[$vars[$_]];
25 } else {
26 $inner_hash->{$vars[$_]} = {} if !exists $inner_hash->{$vars[$_]};
27 $inner_hash = $inner_hash->{$vars[$_]};
28 }
29 }
30 if (looks_like_number($inner_hash->{$vars[-1]})) {
31 $inner_hash->{$vars[-1]}--;
32 }
33 return '';
34
35 }
36  
37  
38  
39 1;