File Coverage

blib/lib/Apache/Voodoo/Validate/unsigned_int.pm
Criterion Covered Total %
statement 21 24 87.5
branch 9 12 75.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 35 43 81.4


line stmt bran cond sub pod time code
1             package Apache::Voodoo::Validate::unsigned_int;
2              
3             $VERSION = "3.0200";
4              
5 3     3   1465 use strict;
  3         6  
  3         113  
6 3     3   17 use warnings;
  3         5  
  3         94  
7              
8 3     3   19 use base("Apache::Voodoo::Validate::Plugin");
  3         5  
  3         13050  
9              
10             sub config {
11 6     6 0 9 my ($self,$c) = @_;
12              
13 6         7 my @e;
14 6 100       18 if (defined($c->{bytes})) {
    50          
15 4 50       62 if ($c->{bytes} =~ /^\d+$/) {
16 4         17 $self->{max} = 2 ** ($c->{bytes} * 8) - 1;
17             }
18             else {
19 0         0 push(@e,"'bytes' must be a positive integer");
20             }
21             }
22             elsif (defined($c->{max})) {
23 2 50       8 if ($c->{max} =~ /^\d+$/) {
24 2         5 $self->{max} = $c->{max};
25             }
26             else {
27 0         0 push(@e,"'max' must be a positive integer");
28             }
29             }
30             else {
31 0         0 push(@e,"either 'max' or 'bytes' is a required parameter");
32             }
33              
34 6         20 return @e;
35             }
36              
37             sub valid {
38 21     21 0 40 my ($self,$v) = @_;
39              
40 21 100       166 return undef,'BAD' unless ($v =~ /^\d*$/ );
41 17 100       63 return undef,'MAX' unless ($v <= $self->{'max'});
42              
43 13         49 return $v;
44             }
45              
46             1;
47              
48             ################################################################################
49             # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
50             # All rights reserved.
51             #
52             # You may use and distribute Apache::Voodoo under the terms described in the
53             # LICENSE file include in this package. The summary is it's a legalese version
54             # of the Artistic License :)
55             #
56             ################################################################################