line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Chess::Pgn; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.004; |
4
|
|
|
|
|
|
|
#use warnings; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
) ] ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw( |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $LINE =""; |
22
|
|
|
|
|
|
|
my $FLAG=1; |
23
|
|
|
|
|
|
|
my $GAME=0; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _init { |
27
|
0
|
|
|
0
|
|
|
my $self=shift; |
28
|
0
|
|
|
|
|
|
$self->{Event}=""; |
29
|
0
|
|
|
|
|
|
$self->{Site}=""; |
30
|
0
|
|
|
|
|
|
$self->{Date}=""; |
31
|
0
|
|
|
|
|
|
$self->{Round}=""; |
32
|
0
|
|
|
|
|
|
$self->{White}=""; |
33
|
0
|
|
|
|
|
|
$self->{Black}=""; |
34
|
0
|
|
|
|
|
|
$self->{Result}=""; |
35
|
0
|
|
|
|
|
|
$self->{ECO}=""; |
36
|
0
|
|
|
|
|
|
$self->{WhiteElo}=""; |
37
|
0
|
|
|
|
|
|
$self->{BlackElo}=""; |
38
|
0
|
|
|
|
|
|
$self->{PlyCount}=""; |
39
|
0
|
|
|
|
|
|
$self->{Game}=""; |
40
|
0
|
|
|
|
|
|
$FLAG=1; |
41
|
0
|
|
|
|
|
|
$GAME=0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
45
|
0
|
|
|
0
|
1
|
|
my $this= shift ; |
46
|
0
|
|
0
|
|
|
|
my $class= ref($this) || $this ; |
47
|
0
|
|
|
|
|
|
my $file=shift; |
48
|
0
|
|
|
|
|
|
my $self=bless {},$class; |
49
|
0
|
|
|
|
|
|
$self->_init(); |
50
|
0
|
0
|
|
|
|
|
if (defined $file) |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
|
|
|
$self->{file} = $file; |
53
|
0
|
0
|
|
|
|
|
$self->open($file, -umod => $args{-umod}) or return undef; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return ($self); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub game |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
61
|
0
|
0
|
|
|
|
|
if (@_) {$self{Game}=shift; } |
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self->{Game} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub blackelo |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
68
|
0
|
0
|
|
|
|
|
if (@_) {$self{BlackElo}=shift; } |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self->{BlackElo} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub plycount |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
75
|
0
|
0
|
|
|
|
|
if (@_) {$self{PlyCount}=shift; } |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $self->{PlyCount} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub whiteelo |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
83
|
0
|
0
|
|
|
|
|
if (@_) {$self{WhiteElo}=shift; } |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $self->{WhiteElo} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub eco |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
90
|
0
|
0
|
|
|
|
|
if (@_) {$self{ECO}=shift; } |
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $self->{ECO} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub result |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
98
|
0
|
0
|
|
|
|
|
if (@_) {$self{Result}=shift; } |
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $self->{Result} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub black |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
105
|
0
|
0
|
|
|
|
|
if (@_) {$self{Black}=shift; } |
|
0
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
return $self->{Black} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub white |
110
|
|
|
|
|
|
|
{ |
111
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
112
|
0
|
0
|
|
|
|
|
if (@_) {$self{White}=shift; } |
|
0
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $self->{White} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub round |
118
|
|
|
|
|
|
|
{ |
119
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
120
|
0
|
0
|
|
|
|
|
if (@_) {$self{Round}=shift; } |
|
0
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $self->{Round} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub date |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
127
|
0
|
0
|
|
|
|
|
if (@_) {$self{Date}=shift; } |
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $self->{Date} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub site |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
135
|
0
|
0
|
|
|
|
|
if (@_) {$self{Site}=shift; } |
|
0
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return $self->{Site} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub event |
140
|
|
|
|
|
|
|
{ |
141
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
142
|
0
|
0
|
|
|
|
|
if (@_) {$self{Event}=shift; } |
|
0
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return $self->{Event} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub open |
147
|
|
|
|
|
|
|
{ |
148
|
0
|
|
|
0
|
0
|
|
my ($self, $file, %args) = @_; |
149
|
0
|
0
|
|
|
|
|
if (defined $file) { $self->{file} = $file;} |
|
0
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
else { $file = $self->{file}; } |
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
|
open FICPGN, "<$file" or return 0; |
153
|
0
|
|
|
|
|
|
$LINE=; |
154
|
0
|
|
|
|
|
|
$LINE=~s/\r//; |
155
|
0
|
|
|
|
|
|
return 1 ; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub quit |
159
|
|
|
|
|
|
|
{ |
160
|
0
|
|
|
0
|
1
|
|
close (FICPGN); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub PrintAll |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
166
|
0
|
|
|
|
|
|
my $return ; |
167
|
0
|
|
|
|
|
|
my @Keys=(Event,Site,Date,Round,White,Black,Result,ECO,WhiteElo,BlackElo,PlyCount); |
168
|
0
|
|
|
|
|
|
foreach my $i ( @Keys ) |
169
|
|
|
|
|
|
|
{ |
170
|
0
|
|
|
|
|
|
$return.="[$i \"".$self->{$i}."\"]\n"; |
171
|
|
|
|
|
|
|
} |
172
|
0
|
|
|
|
|
|
$return .="\n"; |
173
|
0
|
|
|
|
|
|
$return.=$self->{Game}; |
174
|
0
|
|
|
|
|
|
$return .="\n"; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub ReadGame |
178
|
|
|
|
|
|
|
{ |
179
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
180
|
0
|
|
|
|
|
|
my $continue=1; |
181
|
0
|
|
|
|
|
|
$self->_init(); |
182
|
|
|
|
|
|
|
do |
183
|
0
|
|
|
|
|
|
{ |
184
|
0
|
0
|
|
|
|
|
if ( $continue == 2 ) { $continue = 0 } |
|
0
|
|
|
|
|
|
|
185
|
0
|
0
|
|
|
|
|
if ( $LINE =~/\[(.*)\]/ ) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
186
|
|
|
|
|
|
|
{ |
187
|
0
|
|
|
|
|
|
my $line=$1; |
188
|
0
|
|
|
|
|
|
my ($key,$val,$junk)=split(/"/,$line); |
189
|
0
|
|
|
|
|
|
$key=~s/ $//g, |
190
|
|
|
|
|
|
|
$self->{$key}=$val; |
191
|
0
|
|
|
|
|
|
$GAME=0; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
elsif ( $LINE !~/^$/) |
194
|
|
|
|
|
|
|
{ |
195
|
0
|
|
|
|
|
|
$self->{Game}.=$LINE; |
196
|
0
|
|
|
|
|
|
$GAME=1; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
elsif ( $GAME == 1 ) |
199
|
|
|
|
|
|
|
{ |
200
|
0
|
|
|
|
|
|
$FLAG=0; |
201
|
|
|
|
|
|
|
} |
202
|
0
|
|
|
|
|
|
$LINE=; |
203
|
0
|
0
|
0
|
|
|
|
if ( eof(FICPGN) && $continue == 1 ) { $continue = 2 } |
|
0
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
$LINE=~s/\r//; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
while ( $FLAG==1 ); |
207
|
0
|
|
|
|
|
|
return ( $continue ) ; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
1; |
215
|
|
|
|
|
|
|
__END__ |