| 1 | package Apache::Voodoo::Validate::signed_int; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | $VERSION = "3.0200"; | |||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use base("Apache::Voodoo::Validate::Plugin"); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 0 | ▶ | sub config { | ||||||||||||||||||
|
Subroutine
config: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 11 | 0 | my ($self,$c) = @_; | |||||||||||||||||||
| 12 | 0 | my @e; | |||||||||||||||||||
| 13 | 0 | ▶ | if (defined($c->{bytes})) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 14 | 0 | ▶ | if ($c->{bytes} =~ /^\d+$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | 0 | $self->{'max'} = ( 2 ** ($c->{bytes} * 8))/2; | |||||||||||||||||||
| 16 | 0 | $self->{'min'} = (0 - (2 ** ($c->{bytes} * 8))/2 - 1); | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | else { | ||||||||||||||||||||
| 19 | 0 | push(@e,"'bytes' must be a positive integer"); | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | ▶ | elsif (defined($c->{max}) && defined($c->{min})) { | |||||||||||||||||||
|
Condition0%0/3
defined $c->{"max"} and defined $c->{"min"}
MC/DC0%0/2
defined $c->{"max"} and defined $c->{"min"}
defined $c->{"max"}
defined $c->{"min"}
Truth table0%0/3
A and B
A= defined $c->{"max"}B= defined $c->{"min"}
| |||||||||||||||||||||
| 23 | 0 | ▶ | if ($c->{max} =~ /^\d+$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 0 | $self->{max} = $c->{max}; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||
| 27 | 0 | push(@e,"'max' must be zero or a positive integer"); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | ▶ | if ($c->{min} =~ /^(0+|-\d+)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 0 | $self->{min} = $c->{min}; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||
| 34 | 0 | push(@e,"'min' must be zero or a negative integer"); | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||
| 38 | 0 | push(@e,"either 'max' and 'min' or 'bytes' is a required parameter"); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | return @e; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub valid { | ||||||||||||||||||
|
Subroutine
valid: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 45 | 0 | my ($self,$v) = @_; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | ▶ | return undef,'BAD' unless ($v =~ /^(\+|-)?\d*$/); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 0 | ▶ | return undef,'MAX' unless ($v <= $self->{'max'}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | ▶ | return undef,'MIN' unless ($v >= $self->{'min'}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | return $v; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 1 | 1; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | ################################################################################ | ||||||||||||||||||||
| 57 | # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org). | ||||||||||||||||||||
| 58 | # All rights reserved. | ||||||||||||||||||||
| 59 | # | ||||||||||||||||||||
| 60 | # You may use and distribute Apache::Voodoo under the terms described in the | ||||||||||||||||||||
| 61 | # LICENSE file include in this package. The summary is it's a legalese version | ||||||||||||||||||||
| 62 | # of the Artistic License :) | ||||||||||||||||||||
| 63 | # | ||||||||||||||||||||
| 64 | ################################################################################ | ||||||||||||||||||||