File Coverage

blib/lib/WWW/Shopify/Liquid/Security.pm
Criterion Covered Total %
statement 29 30 96.6
branch 4 6 66.6
condition 3 9 33.3
subroutine 11 14 78.5
pod 0 4 0.0
total 47 63 74.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 37     37   258 use strict;
  37         96  
  37         1099  
4 37     37   228 use warnings;
  37         157  
  37         1028  
5              
6 37     37   232 use WWW::Shopify::Liquid;
  37         93  
  37         4726  
7              
8             # Designed to verify objects for possible malicious uses.
9             package WWW::Shopify::Liquid::Security;
10             sub new {
11 257     257 0 755 my ($package) = @_;
12 257 100       946 $package = 'WWW::Shopify::Liquid::Security::None' if $package eq 'WWW::Shopify::Liquid::Security';
13 257         4292 return bless { }, $package;
14             }
15       0 0   sub verify { }
16       0 0   sub check_tag { }
17       967 0   sub check_operate { }
18              
19             package WWW::Shopify::Liquid::Exception::Security;
20 37     37   260 use base 'WWW::Shopify::Liquid::Exception';
  37         103  
  37         4328  
21              
22             # No checking.
23             package WWW::Shopify::Liquid::Security::None;
24 37     37   279 use base 'WWW::Shopify::Liquid::Security';
  37         152  
  37         3753  
25              
26             package WWW::Shopify::Liquid::Security::Strict;
27 37     37   260 use base 'WWW::Shopify::Liquid::Security';
  37         115  
  37         3765  
28 37     37   347 use Scalar::Util qw(looks_like_number);
  37         96  
  37         8237  
29              
30             sub check_tag {
31 0     0   0 my ($self, $ast, @rest) = @_;
32             }
33              
34             sub check_operate {
35 1     1   7 my ($self, $ast, @rest) = @_;
36             my %types = (
37             'WWW::Shopify::Liquid::Operator::Array' => sub {
38 1     1   5 my ($self, $hash, $type, $op1, $op2) = @_;
39 1 50 33     36 die new WWW::Shopify::Liquid::Exception::Security($self, "Array generation operands are too large.") if looks_like_number($op2) && looks_like_number($op1) && ($op2 - $op1) > 1000;
      33        
40             }
41 1         9 );
42            
43 1 50 33     12 $types{ref($ast)}->($ast, @rest) if ref($ast) && $types{ref($ast)};
44             }
45              
46             1;