DataObjects/Types.pm

filter: Statementstmt 69.5% 48 / 69 Branchbran 0.0% 0 / 4 Conditioncond 87.0% 47 / 54 MC/DCmcdc 66.6% 16 / 24 Subroutinesub 63.3% 19 / 30 Podpod 0.0% 0 / 8 totaltotal 68.7% 130 / 189 CC 21 SCAR 13.0
CC
21
Cov
75%
vbar
12.0
is_Rating
7.0
is_Rank
6.2
CRAP 3.7
« DataObjects/Directives.pm ↑ Summary DataObjects.pm »
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@lucidport.com>
9 # COMPANY: LucidPort Technology, Inc.
10 # CREATED: 11/22/2010 12:03:18 PM PST
11 #===============================================================================
12  
13 6 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 package Games::Go::AGA::DataObjects::Types;
18  
19 BEGIN {
20 6 ▶ use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ our @EXPORT_OK = qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 is_ID
23 is_Rank
24 is_Rating
25 is_Rank_or_Rating
26 is_Handicap
27 is_Komi
28 is_Winner
29 );
30 }
31 6 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 6 ▶use Scalar::Util::Numeric qw( isint isfloat );
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 6 our $VERSION = '0.107'; # VERSION
35  
36 # if $_ is undef, the messages crash before they can print anything useful.
37 sub vbar {
38 0 ▶ my ($bar) = @_;
Subroutine vbar: not called CC=3 SCAR=24.8
Pod undocumented
39  
40 0 ▶ $bar = '(undef)' if (not defined $bar);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bar 0 0 0
41 0 ▶ $bar = "''" if ($bar eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $bar eq "" 0 0 0
42 0 return $bar;
43 }
44  
45 # type definitions
46 sub is_ID {
47 36 ▶ $_ = shift;
Subroutine is_ID: called CC=2 SCAR=6.9
Pod undocumented
48 return (
49 36 ▶ m/^\w+$/ # valid alpha-numeric characters
Condition100%3/3
/^\w+$/ && /^\D/
!ll&&!rl&&r
3231
MC/DC100%2/2
/^\w+$/ && /^\D/
/^\w+$/ /^\D/
Truth table100%3/3
A && B
A= /^\w+$/B= /^\D/
ABresult
0X0
100
111
50 and m/^\D/ # not digit in first character
51 );
52 }
53 subtype 'ID',
54 as 'Str',
55 29 ▶ where { is_ID($_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
56 0 ▶ message { $_ = vbar($_); "Invalid ID:$_. Must be a letter followed by letters and numbers"; };
Subroutine __ANON__: not called CC=1 SCAR=2.6
57  
58 sub is_Rank {
59 35 ▶ $_ = shift;
Subroutine is_Rank: called CC=6 SCAR=18.2
Pod undocumented
60 return (
61 35 ▶ (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
8621
/^(\d+)[dD]$/ and $1 >= 1 and $1 < 20
!ll&&!rl&&r
2618
/^(\d+)[dD]$/ and $1 >= 1
!ll&&!rl&&r
2609
/^(\d+)[kK]$/ and $1 >= 1 and $1 < 100
!ll&&!rl&&r
2106
/^(\d+)[kK]$/ and $1 >= 1
!ll&&!rl&&r
2106
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
62 (m/^(\d+)[kK]$/ and $1 >= 1 and $1 < 100)
63 );
64 }
65 subtype 'Rank',
66 as 'Str',
67 0 ▶ where { is_Rank($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 ▶ message { $_ = vbar($_); "$_ is not a valid rank: must be 19D to 1D or 1K to 99K" };
Subroutine __ANON__: not called CC=1 SCAR=2.6
69  
70 sub is_Rating {
71 54 ▶ $_ = shift;
Subroutine is_Rating: called CC=7 SCAR=19.5
Pod undocumented
72 return(
73 54 ▶ $_ and
Condition94%17/18
$_ && (&isint($_) || &isfloat($_)) && ($_ < 20 && $_ >= 1 || $_ <= -1 && $_ > -100)
!ll&&!rl&&r
10440
$_ and &isint($_) || &isfloat($_)
!ll&&!rl&&r
01044
&isint($_) or &isfloat($_)
l!l&&r!l&&!r
143010
$_ < 20 and $_ >= 1 or $_ <= -1 and $_ > -100
l!l&&r!l&&!r
14264
$_ < 20 and $_ >= 1
!ll&&!rl&&r
12914
$_ <= -1 and $_ > -100
!ll&&!rl&&r
3126
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
74 (isint($_) or
75 isfloat($_)) and
76 (($_ < 20.0 and
77 $_ >= 1.0) or
78 ($_ <= -1.0 and
79 $_ > -100.0))
80 );
81 }
82 subtype 'Rating',
83 as 'Num',
84 0 ▶ where { is_Rating($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 0 ▶ message { $_ = vbar($_); "$_ is not a valid rating: must be 19.99 to 1.0 or -1.0 to -99.99" };
Subroutine __ANON__: not called CC=1 SCAR=2.6
86  
87 sub is_Handicap {
88 9 ▶ $_ = shift;
Subroutine is_Handicap: called CC=4 SCAR=13.9
Pod undocumented
89 return (
90 9 ▶ defined $_ and
Condition88%8/9
defined $_ && &isint($_) && ($_ >= 0 && $_ <= 99)
!ll&&!rl&&r
126
defined $_ and &isint($_)
!ll&&!rl&&r
018
$_ >= 0 and $_ <= 99
!ll&&!rl&&r
116
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
91 isint($_) and
92 (($_ >= 0) and
93 ($_ <= 99)) # really should be 9, but let"s not be cops about it
94 );
95 }
96 subtype 'Handicap',
97 as 'Int',
98 4 ▶ where { is_Handicap($_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
99 0 ▶ message { $_ = vbar($_); "$_ is not a valid handicap, must be between 0 and 99" };
Subroutine __ANON__: not called CC=1 SCAR=2.6
100  
101 sub is_Komi {
102 9 ▶ $_ = shift;
Subroutine is_Komi: called CC=3 SCAR=11.0
Pod undocumented
103 9 ▶ return (defined $_ and (isint($_) or isfloat($_)));
Condition83%5/6
defined $_ && (&isint($_) || &isfloat($_))
!ll&&!rl&&r
018
&isint($_) or &isfloat($_)
l!l&&r!l&&!r
351
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
104 }
105 subtype 'Komi',
106 as 'Num',
107 5 ▶ where { is_Komi($_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
108 0 ▶ message { $_ = vbar($_); "$_ is not a valid komi, must be a decimal number" };
Subroutine __ANON__: not called CC=1 SCAR=2.6
109  
110 sub is_Winner {
111 5 ▶ $_ = shift;
Subroutine is_Winner: called CC=1 SCAR=0.0
Pod undocumented
112 5 return $_ =~ m/^[wb?]$/i; # w, b, or ?
113 }
114 subtype 'Winner', # black, white, or unknown
115 as 'Str',
116 0 ▶ where { is_Winner($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 0 ▶ message { $_ = vbar($_); qq[$_ is not a valid winner, must be "b", "w", or "?"] };
Subroutine __ANON__: not called CC=1 SCAR=2.6
118  
119 sub is_Rank_or_Rating {
120 26 ▶ $_ = shift;
Subroutine is_Rank_or_Rating: called CC=2 SCAR=7.1
Pod undocumented
121 26 ▶ return (is_Rank($_) or is_Rating($_));
Condition66%2/3
is_Rank($_) || is_Rating($_)
l!l&&r!l&&!r
10160
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
122 }
123 subtype 'Rank_or_Rating',
124 as 'Str',
125 26 ▶ where { is_Rank_or_Rating($_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
126 0 ▶ message { $_ = vbar($_); qq[$_ is not a valid Rank or Rating, must be like "3D", "14K", or "-14.5"] };
Subroutine __ANON__: not called CC=1 SCAR=2.6
127  
128 6 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 #__PACKAGE__->meta->make_immutable;
130  
131 6 1;
132  
133 __END__
« DataObjects/Directives.pm ↑ Summary DataObjects.pm »