DataObjects/Types.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran 42.8% 6 / 14 Conditioncond 82.4% 47 / 57 MC/DCmcdc 61.5% 16 / 26 Subroutinesub 95.6% 22 / 23 Podpod 0.0% 0 / 15 totaltotal 75.0% 135 / 180 CC 27 SCAR 13.6
CC
27
Cov
84%
isa_Num
12.0
is_Rating
7.0
is_Rank
6.2
CRAP 3.9
« DataObjects.pm ↑ Summary
1 #===============================================================================
2 #
3 # FILE: Types.pm
4 #
5 # PODNAME: Games::Go::AGA::DataObjects::Game
6 # ABSTRACT: library of types and constraints for Games::Go::AGA
7 #
8 # AUTHOR: Reid Augustin (REID), <reid@hellosix.com>
9 # CREATED: 11/22/2010 12:03:18 PM PST
10 #===============================================================================
11  
12 7 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 package Games::Go::AGA::DataObjects::Types;
17 7 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use Scalar::Util::Numeric qw( isint isfloat );
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 7 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
22 7 ▶ use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 7 our @EXPORT_OK = qw(
24 is_Int
25 is_ID
26 is_Rank
27 is_Rating
28 is_Rank_or_Rating
29 is_Handicap
30 is_Komi
31 is_Winner
32 isa_Int
33 isa_Num
34 isa_ArrayRef
35 isa_HashRef
36 isa_CodeRef
37 isa_Komi
38 isa_Handicap
39 );
40 }
41  
42 7 our $VERSION = '0.152'; # VERSION
43  
44 12 ▶sub isa_Int { die("$_[0] is not an integer\n") if (not isint($_[0])) };
Subroutine isa_Int: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if not &isint($_[0]) 0 12 12
45 0 ▶sub isa_Num { die("$_[0] is not a number\n") if (not isint($_[0]) or isfloat($_[0])) };
Subroutine isa_Num: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if not &isint($_[0]) or &isfloat($_[0]) 0 0 0
Condition0%0/3
not &isint($_[0]) or &isfloat($_[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
not &isint($_[0]) or &isfloat($_[0])
not &isint($_[0]) &isfloat($_[0])
Truth table0%0/3
not(A) or B
A= not &isint($_[0])B= &isfloat($_[0])
ABresult
1X1
011
000
46 25 ▶sub isa_ArrayRef { die("$_[0] is not an array ref\n") if (ref $_[0] ne 'ARRAY') };
Subroutine isa_ArrayRef: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] ne "ARRAY" 0 25 25
47 1 ▶sub isa_HashRef { die("$_[0] is not a hash ref\n") if (ref $_[0] ne 'HASH') };
Subroutine isa_HashRef: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] ne "HASH" 0 1 1
48 45 ▶sub isa_CodeRef { die("$_[0] is not a code ref\n") if (ref $_[0] ne 'CODE') };
Subroutine isa_CodeRef: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] ne "CODE" 0 45 45
49 7 ▶sub isa_Komi { die("$_[0] is not a Komi\n") if (not is_Komi($_[0])) }
Subroutine isa_Komi: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if not is_Komi($_[0]) 0 7 7
50 6 ▶sub isa_Handicap { die("$_[0] is not a Handicap\n") if (not is_Handicap($_[0])) }
Subroutine isa_Handicap: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if not is_Handicap($_[0]) 0 6 6
51  
52 # type definitions
53 2 ▶sub is_Int {
Subroutine is_Int: called CC=1 SCAR=0.0
Pod undocumented
54 2 return isint(shift);
55 }
56  
57 40 ▶sub is_ID {
Subroutine is_ID: called CC=2 SCAR=6.9
Pod undocumented
58 40 $_ = shift;
59 return (
60 40 ▶ m/^\w+$/ # valid alpha-numeric characters
Condition100%3/3
/^\w+$/ && /^\D/
!ll&&!rl&&r
3235
MC/DC100%2/2
/^\w+$/ && /^\D/
/^\w+$/ /^\D/
Truth table100%3/3
A && B
A= /^\w+$/B= /^\D/
ABresult
0X0
100
111
61 and m/^\D/ # not digit in first character
62 );
63 }
64  
65 39 ▶sub is_Rank {
Subroutine is_Rank: called CC=6 SCAR=18.2
Pod undocumented
66 39 $_ = shift;
67 return (
68 39 ▶ (m/^(\d+)[dD]$/ and $1 >= 1 and $1 < 20) or
Condition80%12/15
/^(\d+)[dD]$/ && $1 >= 1 && $1 < 20 || /^(\d+)[kK]$/ && $1 >= 1 && $1 < 100
l!l&&r!l&&!r
9822
/^(\d+)[dD]$/ and $1 >= 1 and $1 < 20
!ll&&!rl&&r
2919
/^(\d+)[dD]$/ and $1 >= 1
!ll&&!rl&&r
29010
/^(\d+)[kK]$/ and $1 >= 1 and $1 < 100
!ll&&!rl&&r
2208
/^(\d+)[kK]$/ and $1 >= 1
!ll&&!rl&&r
2208
MC/DC50%3/6
/^(\d+)[dD]$/ && $1 >= 1 && $1 < 20 || /^(\d+)[kK]$/ && $1 >= 1 && $1 < 100
/^(\d+)[dD]$/ $1 >= 1 $1 < 20 /^(\d+)[kK]$/ $1 >= 1 $1 < 100
Truth table30%4/13
A and B and C || D and E and F
A= /^(\d+)[dD]$/B= $1 >= 1C= $1 < 20D= /^(\d+)[kK]$/E= $1 >= 1F= $1 < 100
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
69 (m/^(\d+)[kK]$/ and $1 >= 1 and $1 < 100)
70 );
71 }
72  
73 59 ▶sub is_Rating {
Subroutine is_Rating: called CC=7 SCAR=19.5
Pod undocumented
74 59 $_ = shift;
75 return(
76 59 ▶ $_ and
Condition94%17/18
$_ && (&isint($_) || &isfloat($_)) && ($_ < 20 && $_ >= 1 || $_ <= -1 && $_ > -100)
!ll&&!rl&&r
13442
$_ and &isint($_) || &isfloat($_)
!ll&&!rl&&r
01346
&isint($_) or &isfloat($_)
l!l&&r!l&&!r
143213
$_ < 20 and $_ >= 1 or $_ <= -1 and $_ > -100
l!l&&r!l&&!r
14284
$_ < 20 and $_ >= 1
!ll&&!rl&&r
13114
$_ <= -1 and $_ > -100
!ll&&!rl&&r
3128
MC/DC85%6/7
$_ && (&isint($_) || &isfloat($_)) && ($_ < 20 && $_ >= 1 || $_ <= -1 && $_ > -100)
$_ &isint($_) &isfloat($_) $_ < 20 $_ >= 1 $_ <= -1 $_ > -100
Truth table50%8/16
A and B or C && D and E or F and G
A= $_B= &isint($_)C= &isfloat($_)D= $_ < 20E= $_ >= 1F= $_ <= -1G= $_ > -100
ABCDEFGresult
0XXXXXX0
100XXXX0
11X0X0X0
11X0X100
11X100X0
11X10100
1010X0X0
1010X100
101100X0
10110100
11X11XX1
11X0X111
11X10111
10111XX1
1010X111
10110111
77 (isint($_) or
78 isfloat($_)) and
79 (($_ < 20.0 and
80 $_ >= 1.0) or
81 ($_ <= -1.0 and
82 $_ > -100.0))
83 );
84 }
85  
86 11 ▶sub is_Handicap {
Subroutine is_Handicap: called CC=4 SCAR=13.9
Pod undocumented
87 11 $_ = shift;
88 return (
89 11 ▶ defined $_ and
Condition88%8/9
defined $_ && &isint($_) && ($_ >= 0 && $_ <= 99)
!ll&&!rl&&r
128
defined $_ and &isint($_)
!ll&&!rl&&r
0110
$_ >= 0 and $_ <= 99
!ll&&!rl&&r
118
MC/DC75%3/4
defined $_ && &isint($_) && ($_ >= 0 && $_ <= 99)
defined $_ &isint($_) $_ >= 0 $_ <= 99
Truth table80%4/5
A and B && C and D
A= defined $_B= &isint($_)C= $_ >= 0D= $_ <= 99
ABCDresult
0XXX0
10XX0
110X0
11100
11111
90 isint($_) and
91 (($_ >= 0) and
92 ($_ <= 99)) # really should be 9, but let"s not be cops about it
93 );
94 }
95  
96 11 ▶sub is_Komi {
Subroutine is_Komi: called CC=3 SCAR=11.0
Pod undocumented
97 11 $_ = shift;
98 11 ▶ return (defined $_ and (isint($_) or isfloat($_)));
Condition83%5/6
defined $_ && (&isint($_) || &isfloat($_))
!ll&&!rl&&r
0110
&isint($_) or &isfloat($_)
l!l&&r!l&&!r
371
MC/DC66%2/3
defined $_ && (&isint($_) || &isfloat($_))
defined $_ &isint($_) &isfloat($_)
Truth table75%3/4
A && B or C
A= defined $_B= &isint($_)C= &isfloat($_)
ABCresult
0XX0
1000
11X1
1011
99 }
100  
101 5 ▶sub is_Winner {
Subroutine is_Winner: called CC=1 SCAR=0.0
Pod undocumented
102 5 $_ = shift;
103 5 return $_ =~ m/^[wb?]$/i; # w, b, or ?
104 }
105  
106 30 ▶sub is_Rank_or_Rating {
Subroutine is_Rank_or_Rating: called CC=2 SCAR=7.1
Pod undocumented
107 30 $_ = shift;
108 30 ▶ return (is_Rank($_) or is_Rating($_));
Condition66%2/3
is_Rank($_) || is_Rating($_)
l!l&&r!l&&!r
13170
MC/DC0%0/2
is_Rank($_) || is_Rating($_)
is_Rank($_) is_Rating($_)
Truth table66%2/3
A || B
A= is_Rank($_)B= is_Rating($_)
ABresult
1X1
011
000
109 }
110  
111 7 1;
112  
113 __END__
« DataObjects.pm ↑ Summary