line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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), |
9
|
|
|
|
|
|
|
# COMPANY: LucidPort Technology, Inc. |
10
|
|
|
|
|
|
|
# CREATED: 11/22/2010 12:03:18 PM PST |
11
|
|
|
|
|
|
|
#=============================================================================== |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
1111
|
use 5.008; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
260
|
|
14
|
6
|
|
|
6
|
|
31
|
use strict; |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
203
|
|
15
|
6
|
|
|
6
|
|
63
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
292
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Games::Go::AGA::DataObjects::Types; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
BEGIN { |
20
|
6
|
|
|
6
|
|
1226
|
use parent 'Exporter'; |
|
6
|
|
|
|
|
669
|
|
|
6
|
|
|
|
|
32
|
|
21
|
6
|
|
|
6
|
|
502
|
our @EXPORT_OK = qw( |
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
|
|
|
6
|
|
719
|
use Mouse::Util::TypeConstraints; |
|
6
|
|
|
|
|
20582
|
|
|
6
|
|
|
|
|
36
|
|
32
|
6
|
|
|
6
|
|
3241
|
use Scalar::Util::Numeric qw( isint isfloat ); |
|
6
|
|
|
|
|
3949
|
|
|
6
|
|
|
|
|
4925
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our $VERSION = '0.107'; # VERSION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# if $_ is undef, the messages crash before they can print anything useful. |
37
|
|
|
|
|
|
|
sub vbar { |
38
|
0
|
|
|
0
|
0
|
0
|
my ($bar) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
0
|
$bar = '(undef)' if (not defined $bar); |
41
|
0
|
0
|
|
|
|
0
|
$bar = "''" if ($bar eq ''); |
42
|
0
|
|
|
|
|
0
|
return $bar; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# type definitions |
46
|
|
|
|
|
|
|
sub is_ID { |
47
|
36
|
|
|
36
|
0
|
685
|
$_ = shift; |
48
|
|
|
|
|
|
|
return ( |
49
|
36
|
|
100
|
|
|
581
|
m/^\w+$/ # valid alpha-numeric characters |
50
|
|
|
|
|
|
|
and m/^\D/ # not digit in first character |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
subtype 'ID', |
54
|
|
|
|
|
|
|
as 'Str', |
55
|
|
|
|
|
|
|
where { is_ID($_) }, |
56
|
|
|
|
|
|
|
message { $_ = vbar($_); "Invalid ID:$_. Must be a letter followed by letters and numbers"; }; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub is_Rank { |
59
|
35
|
|
|
35
|
0
|
52
|
$_ = shift; |
60
|
|
|
|
|
|
|
return ( |
61
|
35
|
|
66
|
|
|
763
|
(m/^(\d+)[dD]$/ and $1 >= 1 and $1 < 20) or |
62
|
|
|
|
|
|
|
(m/^(\d+)[kK]$/ and $1 >= 1 and $1 < 100) |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
subtype 'Rank', |
66
|
|
|
|
|
|
|
as 'Str', |
67
|
|
|
|
|
|
|
where { is_Rank($_) }, |
68
|
|
|
|
|
|
|
message { $_ = vbar($_); "$_ is not a valid rank: must be 19D to 1D or 1K to 99K" }; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub is_Rating { |
71
|
54
|
|
|
54
|
0
|
112
|
$_ = shift; |
72
|
|
|
|
|
|
|
return( |
73
|
54
|
|
66
|
|
|
1035
|
$_ and |
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
|
|
|
|
|
|
|
where { is_Rating($_) }, |
85
|
|
|
|
|
|
|
message { $_ = vbar($_); "$_ is not a valid rating: must be 19.99 to 1.0 or -1.0 to -99.99" }; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub is_Handicap { |
88
|
9
|
|
|
9
|
0
|
19
|
$_ = shift; |
89
|
|
|
|
|
|
|
return ( |
90
|
9
|
|
66
|
|
|
147
|
defined $_ and |
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
|
|
|
|
|
|
|
where { is_Handicap($_) }, |
99
|
|
|
|
|
|
|
message { $_ = vbar($_); "$_ is not a valid handicap, must be between 0 and 99" }; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub is_Komi { |
102
|
9
|
|
|
9
|
0
|
14
|
$_ = shift; |
103
|
9
|
|
33
|
|
|
188
|
return (defined $_ and (isint($_) or isfloat($_))); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
subtype 'Komi', |
106
|
|
|
|
|
|
|
as 'Num', |
107
|
|
|
|
|
|
|
where { is_Komi($_) }, |
108
|
|
|
|
|
|
|
message { $_ = vbar($_); "$_ is not a valid komi, must be a decimal number" }; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub is_Winner { |
111
|
5
|
|
|
5
|
0
|
13
|
$_ = shift; |
112
|
5
|
|
|
|
|
31
|
return $_ =~ m/^[wb?]$/i; # w, b, or ? |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
subtype 'Winner', # black, white, or unknown |
115
|
|
|
|
|
|
|
as 'Str', |
116
|
|
|
|
|
|
|
where { is_Winner($_) }, |
117
|
|
|
|
|
|
|
message { $_ = vbar($_); qq[$_ is not a valid winner, must be "b", "w", or "?"] }; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub is_Rank_or_Rating { |
120
|
26
|
|
|
26
|
0
|
25
|
$_ = shift; |
121
|
26
|
|
66
|
|
|
48
|
return (is_Rank($_) or is_Rating($_)); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
subtype 'Rank_or_Rating', |
124
|
|
|
|
|
|
|
as 'Str', |
125
|
|
|
|
|
|
|
where { is_Rank_or_Rating($_) }, |
126
|
|
|
|
|
|
|
message { $_ = vbar($_); qq[$_ is not a valid Rank or Rating, must be like "3D", "14K", or "-14.5"] }; |
127
|
|
|
|
|
|
|
|
128
|
6
|
|
|
6
|
|
294
|
no Mouse; |
|
6
|
|
|
|
|
12294
|
|
|
6
|
|
|
|
|
38
|
|
129
|
|
|
|
|
|
|
#__PACKAGE__->meta->make_immutable; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |