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
|
|
|
|
|
|
|
# CREATED: 11/22/2010 12:03:18 PM PST |
10
|
|
|
|
|
|
|
#=============================================================================== |
11
|
|
|
|
|
|
|
|
12
|
7
|
|
|
7
|
|
1349
|
use 5.008; |
|
7
|
|
|
|
|
40
|
|
13
|
7
|
|
|
7
|
|
35
|
use strict; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
254
|
|
14
|
7
|
|
|
7
|
|
48
|
use warnings; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
310
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Games::Go::AGA::DataObjects::Types; |
17
|
7
|
|
|
7
|
|
916
|
use Moo; |
|
7
|
|
|
|
|
15122
|
|
|
7
|
|
|
|
|
56
|
|
18
|
7
|
|
|
7
|
|
4479
|
use namespace::clean; |
|
7
|
|
|
|
|
12655
|
|
|
7
|
|
|
|
|
52
|
|
19
|
7
|
|
|
7
|
|
5358
|
use Scalar::Util::Numeric qw( isint isfloat ); |
|
7
|
|
|
|
|
4663
|
|
|
7
|
|
|
|
|
532
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
BEGIN { |
22
|
7
|
|
|
7
|
|
1290
|
use parent 'Exporter'; |
|
7
|
|
|
|
|
649
|
|
|
7
|
|
|
|
|
37
|
|
23
|
7
|
|
|
7
|
|
5831
|
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
|
|
|
|
|
|
|
our $VERSION = '0.152'; # VERSION |
43
|
|
|
|
|
|
|
|
44
|
12
|
50
|
|
12
|
0
|
2772
|
sub isa_Int { die("$_[0] is not an integer\n") if (not isint($_[0])) }; |
45
|
0
|
0
|
0
|
0
|
0
|
0
|
sub isa_Num { die("$_[0] is not a number\n") if (not isint($_[0]) or isfloat($_[0])) }; |
46
|
25
|
50
|
|
25
|
0
|
662
|
sub isa_ArrayRef { die("$_[0] is not an array ref\n") if (ref $_[0] ne 'ARRAY') }; |
47
|
1
|
50
|
|
1
|
0
|
31
|
sub isa_HashRef { die("$_[0] is not a hash ref\n") if (ref $_[0] ne 'HASH') }; |
48
|
45
|
50
|
|
45
|
0
|
1581
|
sub isa_CodeRef { die("$_[0] is not a code ref\n") if (ref $_[0] ne 'CODE') }; |
49
|
7
|
50
|
|
7
|
0
|
263
|
sub isa_Komi { die("$_[0] is not a Komi\n") if (not is_Komi($_[0])) } |
50
|
6
|
50
|
|
6
|
0
|
123
|
sub isa_Handicap { die("$_[0] is not a Handicap\n") if (not is_Handicap($_[0])) } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# type definitions |
53
|
|
|
|
|
|
|
sub is_Int { |
54
|
2
|
|
|
2
|
0
|
110
|
return isint(shift); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub is_ID { |
58
|
40
|
|
|
40
|
0
|
567
|
$_ = shift; |
59
|
|
|
|
|
|
|
return ( |
60
|
40
|
|
100
|
|
|
1059
|
m/^\w+$/ # valid alpha-numeric characters |
61
|
|
|
|
|
|
|
and m/^\D/ # not digit in first character |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub is_Rank { |
66
|
39
|
|
|
39
|
0
|
53
|
$_ = shift; |
67
|
|
|
|
|
|
|
return ( |
68
|
39
|
|
66
|
|
|
1014
|
(m/^(\d+)[dD]$/ and $1 >= 1 and $1 < 20) or |
69
|
|
|
|
|
|
|
(m/^(\d+)[kK]$/ and $1 >= 1 and $1 < 100) |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub is_Rating { |
74
|
59
|
|
|
59
|
0
|
78
|
$_ = shift; |
75
|
|
|
|
|
|
|
return( |
76
|
59
|
|
66
|
|
|
1238
|
$_ and |
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
|
|
|
|
|
|
|
sub is_Handicap { |
87
|
11
|
|
|
11
|
0
|
31
|
$_ = shift; |
88
|
|
|
|
|
|
|
return ( |
89
|
11
|
|
66
|
|
|
362
|
defined $_ and |
90
|
|
|
|
|
|
|
isint($_) and |
91
|
|
|
|
|
|
|
(($_ >= 0) and |
92
|
|
|
|
|
|
|
($_ <= 99)) # really should be 9, but let"s not be cops about it |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub is_Komi { |
97
|
11
|
|
|
11
|
0
|
23
|
$_ = shift; |
98
|
11
|
|
33
|
|
|
439
|
return (defined $_ and (isint($_) or isfloat($_))); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub is_Winner { |
102
|
5
|
|
|
5
|
0
|
11
|
$_ = shift; |
103
|
5
|
|
|
|
|
30
|
return $_ =~ m/^[wb?]$/i; # w, b, or ? |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub is_Rank_or_Rating { |
107
|
30
|
|
|
30
|
0
|
42
|
$_ = shift; |
108
|
30
|
|
66
|
|
|
58
|
return (is_Rank($_) or is_Rating($_)); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |