blib/lib/WWW/Shopify/Liquid/Filter/DateMath.pm untested

filter: Statementstmt 0.0% 0 / 17 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 33 CC 3 SCAR 17.5
CC
3
Cov
0%
operate
12.0
min_arguments
2.0
max_arguments
2.0
CRAP 5.8
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4  
5 package WWW::Shopify::Liquid::Filter::DateMath;
6 use base 'WWW::Shopify::Liquid::Filter';
7 # +-, #, <unit>
8 sub min_arguments { return 2; }
9 sub max_arguments { return 2; }
10 sub operate {
11 my ($self, $hash, $operand, @arguments) = @_;
12 my ($number, $unit) = @arguments;
13 $unit = lc($unit);
14 return undef unless ref($operand) && ref($operand) eq "DateTime";
15 return $operand unless $unit =~ m/^(days|months|years|weeks|seconds|minutes|hours)$/;
16 return $operand->clone->add(
17 $unit => $number
18 );
19 }
20  
21 1;