Checkster.pm

filter: Statementstmt 100% 72 / 72 Branchbran 86.7% 59 / 68 Conditioncond 66.6% 20 / 30 MC/DCmcdc 50.0% 10 / 20 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 10 totaltotal 81.8% 176 / 215 CC 45 SCAR 24.9
CC
45
Cov
89%
array
15.8
number
15.3
true
15.2
CRAP 12.1
↑ Summary example.pl »
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
l!l&&r!l&&!r
3200
MC/DC0%0/2
$class || ref $class
$class ref $class
Truth table33%1/3
A || B
A= $classB= ref $class
ABresult
1X1
011
000
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
BranchTrueFalseTotal
@_ > 1 ? : 2 4 6
58  
59 # one param test
60 6 ▶ if(int(@$value) == 1){
Branch: 1 branch
BranchTrueFalseTotal
if (int @$value == 1) 4 2 6
61 4 ▶ return ref $value->[0] eq 'ARRAY' ? 1 : 0 unless $self->op;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->op 3 1 4
ref $value->[0] eq 'ARRAY' ? : 2 1 3
62 1 ▶ return ref $value->[0] eq 'ARRAY' ? 0 : 1 if $self->op && $self->op eq 'not';
Branch: 2 branches
BranchTrueFalseTotal
if $self->op and $self->op eq "not" 1 0 1
ref $value->[0] eq 'ARRAY' ? : 0 1 1
Condition33%1/3
$self->op and $self->op eq "not"
!ll&&!rl&&r
001
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"
ABresult
0X0
100
111
63 }
64  
65 # multi param test
66 2 ▶ if(int(@$value) > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (int @$value > 1) 2 0 2
67 2 my $res = 0;
68
69 2 ▶ do { $res = 1; map { $res = 0 unless ref $_ eq 'ARRAY' } @$value }
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not $self->op or $self->op eq "all") 1 1 2
unless ref $_ eq "ARRAY" 1 1 2
Condition66%2/3
CORE::not $self->op or $self->op eq "all"
l!l&&r!l&&!r
011
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"
ABresult
1X1
011
000
70 if !$self->op || $self->op eq 'all';
71  
72 2 ▶ map { $res = 1 if ref $_ eq 'ARRAY' } @$value
Branch: 2 branches
BranchTrueFalseTotal
if $self->op and $self->op eq "any" 1 1 2
if ref $_ eq "ARRAY" 1 1 2
Condition66%2/3
$self->op and $self->op eq "any"
!ll&&!rl&&r
011
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
@_ > 1 ? : 3 3 6
82  
83 # one param test
84 6 ▶ if(int(@$value) == 1){
Branch: 1 branch
BranchTrueFalseTotal
if (int @$value == 1) 3 3 6
85 3 ▶ return $value->[0] =~ /^[\d\.\,]+$/ ? 1 : 0 unless $self->op;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->op 2 1 3
$value->[0] =~ /^[\d\.\,]+$/ ? : 1 1 2
86 1 ▶ return $value->[0] =~ /^[\d\.\,]+$/ ? 0 : 1 if $self->op && $self->op eq 'not';
Branch: 2 branches
BranchTrueFalseTotal
if $self->op and $self->op eq "not" 1 0 1
$value->[0] =~ /^[\d\.\,]+$/ ? : 0 1 1
Condition33%1/3
$self->op and $self->op eq "not"
!ll&&!rl&&r
001
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"
ABresult
0X0
100
111
87 }
88  
89 # multi param test
90 3 ▶ if(int(@$value) > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (int @$value > 1) 3 0 3
91 3 my $res = 0;
92
93 3 ▶ do { $res = 1; map { $res = 0 unless $_ =~ /^[\d\.\,]+$/ } @$value }
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not $self->op or $self->op eq "all") 2 1 3
unless $_ =~ /^[\d\.\,]+$/ 1 4 5
Condition100%3/3
CORE::not $self->op or $self->op eq "all"
l!l&&r!l&&!r
111
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"
ABresult
1X1
011
000
94 if !$self->op || $self->op eq 'all';
95  
96 3 ▶ map { $res = 1 if ref $_ eq 'ARRAY' } @$value
Branch: 2 branches
BranchTrueFalseTotal
if $self->op and $self->op eq "any" 1 2 3
if ref $_ eq "ARRAY" 1 1 2
Condition100%3/3
$self->op and $self->op eq "any"
!ll&&!rl&&r
111
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
@_ > 1 ? : 11 7 18
107  
108 # one param test
109 18 ▶ if(int(@$value) == 1){
Branch: 1 branch
BranchTrueFalseTotal
if (int @$value == 1) 7 11 18
110 7 ▶ return $value->[0] ? 1 : 0 unless $self->op;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->op 5 2 7
$value->[0] ? : 2 3 5
111 2 ▶ return $value->[0]? 0 : 1 if $self->op && $self->op eq 'not';
Branch: 2 branches
BranchTrueFalseTotal
if $self->op and $self->op eq "not" 2 0 2
$value->[0] ? : 1 1 2
Condition33%1/3
$self->op and $self->op eq "not"
!ll&&!rl&&r
002
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"
ABresult
0X0
100
111
112 }
113  
114 # multi param test
115 11 ▶ if(int(@$value) > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (int @$value > 1) 11 0 11
116 11 my $res = 0;
117
118 11 ▶ do { $res = 1; map { $res = 0 unless $_ } @$value }
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::not $self->op or $self->op eq "all") 9 2 11
unless $_ 8 14 22
Condition100%3/3
CORE::not $self->op or $self->op eq "all"
l!l&&r!l&&!r
722
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"
ABresult
1X1
011
000
119 if !$self->op || $self->op eq 'all';
120  
121 11 ▶ map { $res = 1 if $_ } @$value
Branch: 2 branches
BranchTrueFalseTotal
if $self->op and $self->op eq "any" 2 9 11
if $_ 2 5 7
Condition100%3/3
$self->op and $self->op eq "any"
!ll&&!rl&&r
722
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $_[0] 12 0 12
137 }
138  
139 5 1;
140 __END__
↑ Summary example.pl »