blib/lib/Football/League/Match.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 77.7% 7 / 9 totaltotal 96.7% 59 / 61 CC 3 SCAR 2.2
CC
3
Cov
100%
_validate_date
2.0
_validate_soccerdata
2.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 package Football::League::Match;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 $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 2 ▶sub _validate_date {
Subroutine _validate_date: called CC=2 SCAR=6.9
46 2 my ($class, $date) = @_;
47 2 my $tp = eval { Time::Piece->strptime($date, "%Y%m%d") };
48 2 ▶ die "Invalid date" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 1 2
49 1 return $tp;
50 }
51  
52 3 ▶sub _validate_soccerdata {
Subroutine _validate_soccerdata: called CC=2 SCAR=6.9
53 3 my ($class, $data) = @_;
54 3 $data =~ s/"//g;
55 3 my @fields = split ",", $data;
56 3 ▶ die "Invalid number of fields" unless scalar @fields == 7;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @fields == 7 1 2 3
57 2 $fields[6] = $class->_validate_date($fields[6]);
58 1 return @fields;
59 }
60  
61 3 ▶sub from_soccerdata {
Subroutine from_soccerdata: called CC=1 SCAR=0.0
Pod undocumented
62 3 my ($class, $data) = @_;
63 3 my @fields = $class->_validate_soccerdata($data);
64 1 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 ▶sub final_year_of_season { shift->[0] }
Subroutine final_year_of_season: called CC=1 SCAR=0.0
Pod documented
120 1 ▶sub division { shift->[1] }
Subroutine division: called CC=1 SCAR=0.0
Pod undocumented
121 1 ▶sub home_team { shift->[2] }
Subroutine home_team: called CC=1 SCAR=0.0
Pod documented
122 2 ▶sub home_score { shift->[3] }
Subroutine home_score: called CC=1 SCAR=0.0
Pod documented
123 1 ▶sub away_team { shift->[4] }
Subroutine away_team: called CC=1 SCAR=0.0
Pod documented
124 2 ▶sub away_score { shift->[5] }
Subroutine away_score: called CC=1 SCAR=0.0
Pod documented
125 1 ▶sub date { shift->[6] }
Subroutine date: called CC=1 SCAR=0.0
Pod documented
126  
127 1 ▶sub result {
Subroutine result: called CC=1 SCAR=0.0
Pod documented
128 1 my $self = shift;
129 1 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, E<lt>coder@stray-toaster.co.ukE<gt>
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 1 return qw/Foxes Never Quit/;
↑ Summary