| 1 | package Checkster; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Checkster is a check perl module | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 5 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 5 | our @EXPORT_OK = qw(check); | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | # constructor | ||||||||||||||||||||||||||||||||
| 15 | 32 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 16 | 32 | my $class = shift; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 32 | ▶ | return bless { | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$class || ref $class
MC/DC0%0/2
$class || ref $class
$class
ref $class
Truth table33%1/3
A || B
A= $classB= ref $class
| |||||||||||||||||||||||||||||||||
| 19 | _operator => undef, | ||||||||||||||||||||||||||||||||
| 20 | }, $class || ref $class; | ||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | # accessors | ||||||||||||||||||||||||||||||||
| 25 | 31 | ▶ | sub check { | ||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 26 | 31 | return Checkster->new(@_); | |||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub Checkster::not { | ||||||||||||||||||||||||||||||
|
Subroutine
not: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 30 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 31 | 4 | $self->_operator('not'); | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 4 | $self | |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | sub any { | ||||||||||||||||||||||||||||||
|
Subroutine
any: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 37 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 38 | 4 | $self->_operator('any'); | |||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 4 | $self | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | sub all { | ||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 44 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 45 | 4 | $self->_operator('all'); | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 4 | $self | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 70 | ▶ | sub op { | ||||||||||||||||||||||||||||||
|
Subroutine
op: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 51 | 70 | return shift->{_operator}; | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # type check | ||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | sub Checkster::array { | ||||||||||||||||||||||||||||||
|
Subroutine
array: called CC=15 SCAR=27.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 56 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | my $value = @_ > 1 ? \@_ : [ shift ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | # one param test | ||||||||||||||||||||||||||||||||
| 60 | 6 | ▶ | if(int(@$value) == 1){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | return ref $value->[0] eq 'ARRAY' ? 1 : 0 unless $self->op; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | return ref $value->[0] eq 'ARRAY' ? 0 : 1 if $self->op && $self->op eq 'not'; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->op and $self->op eq "not"
MC/DC0%0/2
$self->op and $self->op eq "not"
$self->op
$self->op eq "not"
Truth table33%1/3
A and B
A= $self->opB= $self->op eq "not"
| |||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | # multi param test | ||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | if(int(@$value) > 1){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 2 | my $res = 0; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | do { $res = 1; map { $res = 0 unless ref $_ eq 'ARRAY' } @$value } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
CORE::not $self->op or $self->op eq "all"
MC/DC50%1/2
CORE::not $self->op or $self->op eq "all"
CORE::not $self->op
$self->op eq "all"
Truth table66%2/3
not(A) or B
A= CORE::not $self->opB= $self->op eq "all"
| |||||||||||||||||||||||||||||||||
| 70 | if !$self->op || $self->op eq 'all'; | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | map { $res = 1 if ref $_ eq 'ARRAY' } @$value | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$self->op and $self->op eq "any"
MC/DC50%1/2
$self->op and $self->op eq "any"
$self->op
$self->op eq "any"
Truth table66%2/3
A and B
A= $self->opB= $self->op eq "any"
| |||||||||||||||||||||||||||||||||
| 73 | if $self->op && $self->op eq 'any'; | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 2 | return $res; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 6 | ▶ | sub number { | ||||||||||||||||||||||||||||||
|
Subroutine
number: called CC=15 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 80 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||
| 81 | 6 | ▶ | my $value = @_ > 1 ? \@_ : [ shift ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | # one param test | ||||||||||||||||||||||||||||||||
| 84 | 6 | ▶ | if(int(@$value) == 1){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | return $value->[0] =~ /^[\d\.\,]+$/ ? 1 : 0 unless $self->op; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | return $value->[0] =~ /^[\d\.\,]+$/ ? 0 : 1 if $self->op && $self->op eq 'not'; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->op and $self->op eq "not"
MC/DC0%0/2
$self->op and $self->op eq "not"
$self->op
$self->op eq "not"
Truth table33%1/3
A and B
A= $self->opB= $self->op eq "not"
| |||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | # multi param test | ||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | if(int(@$value) > 1){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | 3 | my $res = 0; | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 3 | ▶ | do { $res = 1; map { $res = 0 unless $_ =~ /^[\d\.\,]+$/ } @$value } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
CORE::not $self->op or $self->op eq "all"
MC/DC100%2/2
CORE::not $self->op or $self->op eq "all"
CORE::not $self->op
$self->op eq "all"
Truth table100%3/3
not(A) or B
A= CORE::not $self->opB= $self->op eq "all"
| |||||||||||||||||||||||||||||||||
| 94 | if !$self->op || $self->op eq 'all'; | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | map { $res = 1 if ref $_ eq 'ARRAY' } @$value | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$self->op and $self->op eq "any"
MC/DC100%2/2
$self->op and $self->op eq "any"
$self->op
$self->op eq "any"
Truth table100%3/3
A and B
A= $self->opB= $self->op eq "any"
| |||||||||||||||||||||||||||||||||
| 97 | if $self->op && $self->op eq 'any'; | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 3 | return $res; | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | # bool checkers | ||||||||||||||||||||||||||||||||
| 104 | 18 | ▶ | sub true { | ||||||||||||||||||||||||||||||
|
Subroutine
true: called CC=15 SCAR=27.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 105 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||
| 106 | 18 | ▶ | my $value = @_ > 1 ? \@_ : [ shift ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | # one param test | ||||||||||||||||||||||||||||||||
| 109 | 18 | ▶ | if(int(@$value) == 1){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | 7 | ▶ | return $value->[0] ? 1 : 0 unless $self->op; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | return $value->[0]? 0 : 1 if $self->op && $self->op eq 'not'; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$self->op and $self->op eq "not"
MC/DC0%0/2
$self->op and $self->op eq "not"
$self->op
$self->op eq "not"
Truth table33%1/3
A and B
A= $self->opB= $self->op eq "not"
| |||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | # multi param test | ||||||||||||||||||||||||||||||||
| 115 | 11 | ▶ | if(int(@$value) > 1){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | 11 | my $res = 0; | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 11 | ▶ | do { $res = 1; map { $res = 0 unless $_ } @$value } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
CORE::not $self->op or $self->op eq "all"
MC/DC100%2/2
CORE::not $self->op or $self->op eq "all"
CORE::not $self->op
$self->op eq "all"
Truth table100%3/3
not(A) or B
A= CORE::not $self->opB= $self->op eq "all"
| |||||||||||||||||||||||||||||||||
| 119 | if !$self->op || $self->op eq 'all'; | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 11 | ▶ | map { $res = 1 if $_ } @$value | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$self->op and $self->op eq "any"
MC/DC100%2/2
$self->op and $self->op eq "any"
$self->op
$self->op eq "any"
Truth table100%3/3
A and B
A= $self->opB= $self->op eq "any"
| |||||||||||||||||||||||||||||||||
| 122 | if $self->op && $self->op eq 'any'; | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 11 | return $res; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | 4 | ▶ | sub false { | ||||||||||||||||||||||||||||||
|
Subroutine
false: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 129 | 4 | return !shift->true(@_); | |||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | # private methods | ||||||||||||||||||||||||||||||||
| 134 | 12 | ▶ | sub _operator { | ||||||||||||||||||||||||||||||
|
Subroutine
_operator: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||
| 135 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||
| 136 | 12 | ▶ | $self->{_operator} = $_[0] if $_[0]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 5 | 1; | |||||||||||||||||||||||||||||||
| 140 | __END__ | ||||||||||||||||||||||||||||||||