File Coverage

blib/lib/Apache/Voodoo/Validate/signed_decimal.pm
Criterion Covered Total %
statement 9 33 27.2
branch 0 12 0.0
condition 0 7 0.0
subroutine 3 5 60.0
pod 0 2 0.0
total 12 59 20.3


line stmt bran cond sub pod time code
1             package Apache::Voodoo::Validate::signed_decimal;
2              
3             $VERSION = "3.0200";
4              
5 1     1   9571 use strict;
  1         2  
  1         48  
6 1     1   7 use warnings;
  1         2  
  1         43  
7              
8 1     1   7 use base("Apache::Voodoo::Validate::Plugin");
  1         2  
  1         632  
9              
10             sub config {
11 0     0 0   my ($self,$c) = @_;
12 0           my @e;
13 0 0         if (defined($c->{left})) {
14 0 0         if ($c->{left} =~ /^\d+$/) {
15 0           $self->{left} = $c->{left};
16             }
17             else {
18 0           push(@e,"'left' must be positive integer");
19             }
20             }
21             else {
22 0           push(@e,"'left' must be positive integer");
23             }
24              
25 0 0         if (defined($c->{right})) {
26 0 0         if ($c->{right} =~ /^\d+$/) {
27 0           $self->{right} = $c->{right};
28             }
29             else {
30 0           push(@e,"'right' must be positive integer");
31             }
32             }
33             else {
34 0           push(@e,"'right' must be positive integer");
35             }
36              
37 0           return @e;
38             }
39              
40             sub valid {
41 0     0 0   my ($self,$v) = @_;
42              
43 0           my $e;
44 0 0         if ($v =~ /^(\+|-)?(\d*)(?:\.(\d+))?$/) {
45 0   0       my $l = $2 || 0;
46 0   0       my $r = $3 || 0;
47 0           $l *= 1;
48 0           $r *= 1;
49              
50 0 0 0       if (length($l) > $self->{'left'} ||
51             length($r) > $self->{'right'} ) {
52 0           $e='BIG';
53             }
54             }
55             else {
56 0           $e='BAD';
57             }
58 0           return $v,$e;
59             }
60              
61             1;
62              
63             ################################################################################
64             # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
65             # All rights reserved.
66             #
67             # You may use and distribute Apache::Voodoo under the terms described in the
68             # LICENSE file include in this package. The summary is it's a legalese version
69             # of the Artistic License :)
70             #
71             ################################################################################