line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Football::League::Match; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21824
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
836
|
use Time::Piece; |
|
1
|
|
|
|
|
13099
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Football::League::Match::VERSION = '0.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Football::League::Match - A single footie match |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Football::League::Match; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $match = Football::League::Match->from_soccerdata($data); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $final_year_of_season = $match->final_year_of_season; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $division = $match->division; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $hometeam = $match->home_team; |
25
|
|
|
|
|
|
|
my $awayteam = $match->away_team; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $homescore = $match->home_score; |
28
|
|
|
|
|
|
|
my $awaycore = $match->away_score; |
29
|
|
|
|
|
|
|
my $result = $match->result; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my Time::Piece $date = $match->date; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This will create a little object with when passed data about a footie |
36
|
|
|
|
|
|
|
match. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Currently, the only format the data can ve passed in is that defined |
39
|
|
|
|
|
|
|
by that supplied by |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
http://www.soccerdata.com |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _validate_date { |
46
|
2
|
|
|
2
|
|
5
|
my ($class, $date) = @_; |
47
|
2
|
|
|
|
|
4
|
my $tp = eval { Time::Piece->strptime($date, "%Y%m%d") }; |
|
2
|
|
|
|
|
12
|
|
48
|
2
|
100
|
|
|
|
83
|
die "Invalid date" if $@; |
49
|
1
|
|
|
|
|
3
|
return $tp; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _validate_soccerdata { |
53
|
3
|
|
|
3
|
|
7
|
my ($class, $data) = @_; |
54
|
3
|
|
|
|
|
18
|
$data =~ s/"//g; |
55
|
3
|
|
|
|
|
17
|
my @fields = split ",", $data; |
56
|
3
|
100
|
|
|
|
20
|
die "Invalid number of fields" unless scalar @fields == 7; |
57
|
2
|
|
|
|
|
9
|
$fields[6] = $class->_validate_date($fields[6]); |
58
|
1
|
|
|
|
|
5
|
return @fields; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub from_soccerdata { |
62
|
3
|
|
|
3
|
0
|
1615
|
my ($class, $data) = @_; |
63
|
3
|
|
|
|
|
11
|
my @fields = $class->_validate_soccerdata($data); |
64
|
1
|
|
|
|
|
8
|
bless [@fields], $class; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 METHODS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 final_year_of_season |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $fyos = $match->final_year_of_season; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This will return the final year of the season in which the match took place. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 divison |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $division = $match->division; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is the divison the match took place in. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 home_team |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $home_team = $match->home_team; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The home team. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 away_team |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $away_team = $match->away_team; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The away team. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 home_score |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $home_score = $match->home_score; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The number of goals the home team scored. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 away_score |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $away_score = $match->away_score; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The number of goals the away team scored. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 result |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $result = $match->result; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This is the result in 2-1 type form. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 date |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my Time::Piece $date = $match->date; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is the date of the match as a Time::Piece object. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
1
|
1
|
10
|
sub final_year_of_season { shift->[0] } |
120
|
1
|
|
|
1
|
0
|
4
|
sub division { shift->[1] } |
121
|
1
|
|
|
1
|
1
|
5
|
sub home_team { shift->[2] } |
122
|
2
|
|
|
2
|
1
|
8
|
sub home_score { shift->[3] } |
123
|
1
|
|
|
1
|
1
|
6
|
sub away_team { shift->[4] } |
124
|
2
|
|
|
2
|
1
|
9
|
sub away_score { shift->[5] } |
125
|
1
|
|
|
1
|
1
|
6
|
sub date { shift->[6] } |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub result { |
128
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
129
|
1
|
|
|
|
|
6
|
return join "-", $self->home_score, $self->away_score; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 ADDITIONAL INFO |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 soccerdata data format |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The data supplied by soccerdata is in the form: |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1,2,3,4,5,6,7 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1 = final year of season (4 digit) |
141
|
|
|
|
|
|
|
2 = division (P/1/2/3) |
142
|
|
|
|
|
|
|
3 = home team (12 xharacters) |
143
|
|
|
|
|
|
|
4 = home score (2 digits) |
144
|
|
|
|
|
|
|
5 = away team (12 characters) |
145
|
|
|
|
|
|
|
6 = away score (2 digits) |
146
|
|
|
|
|
|
|
7 = match date (YYYYMMDD) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 TODO |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Well, this isn't really an inspired (or inspiring) moudle. As you may (or may |
151
|
|
|
|
|
|
|
not) guess, this is part of A Bigger Picture. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
o Parse different match formats, perhaps screen scraped from some site |
154
|
|
|
|
|
|
|
every saturday night. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 BUGS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Craig McLaughlan has a lot to answer for. Mona, mostly. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SHOWING YOUR APPRECIATION |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
There was a thread on london.pm mailing list about working in a vacumn |
163
|
|
|
|
|
|
|
- that it was a bit depressing to keep writing modules but never get |
164
|
|
|
|
|
|
|
any feedback. So, if you use and like this module then please send me |
165
|
|
|
|
|
|
|
an email and make my day. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
All it takes is a few little bytes. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
(Leon wrote that, not me!) |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 SEE ALSO |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
http://www.soccerdata.com |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Stray Toaster, Ecoder@stray-toaster.co.ukE |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Copyright 2003 by Stray Toaster |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
184
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
return qw/Foxes Never Quit/; |