line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sport::Analytics::NHL::Usage; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3048
|
use v5.10.1; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
572
|
use Getopt::Long qw(:config no_ignore_case bundling); |
|
1
|
|
|
|
|
7699
|
|
|
1
|
|
|
|
|
4
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
133
|
use Sport::Analytics::NHL::Config; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
140
|
|
10
|
1
|
|
|
1
|
|
6
|
use Sport::Analytics::NHL::LocalConfig; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
91
|
|
11
|
1
|
|
|
1
|
|
6
|
use Sport::Analytics::NHL; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
4
|
use parent 'Exporter'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw(gopts); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Sport::Analytics::NHL::Usage - an internal utility module standardizing the usage of our applications. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 FUNCTIONS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over 2 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item C |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=item C |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item C |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
this is the main wrapper for GetOptions to keep things coherent. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=back |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $USAGE_MESSAGE = ''; |
38
|
|
|
|
|
|
|
our $def_db = $MONGO_DB || 'hockey'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our %OPTS = ( |
41
|
|
|
|
|
|
|
standard => [ |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
short => 'h', long => 'help', |
44
|
|
|
|
|
|
|
action => sub { usage(); }, |
45
|
|
|
|
|
|
|
description => 'print this message and exit' |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
short => 'V', long => 'version', |
49
|
|
|
|
|
|
|
action => sub { say hdb_version(); exit; }, |
50
|
|
|
|
|
|
|
description => 'print version and exit' |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
short => 'v', long => 'verbose', |
54
|
|
|
|
|
|
|
action => sub { $ENV{HOCKEYDB_VERBOSE} = 1 }, |
55
|
|
|
|
|
|
|
description => 'produce verbose output to STDERR' |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
{ |
58
|
|
|
|
|
|
|
short => 'd', long => 'debug', |
59
|
|
|
|
|
|
|
action => sub { $ENV{HOCKEYDB_DEBUG} = 1; }, |
60
|
|
|
|
|
|
|
description => 'produce debug output to STDERR' |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
], |
63
|
|
|
|
|
|
|
season => [ |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
short => 's', long => 'start-season', arg => 'SEASON', type => 'i', |
66
|
|
|
|
|
|
|
description => "Start at season SEASON (default $CURRENT_SEASON)", |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
short => 'S', long => 'stop-season', arg => 'SEASON', type => 'i', |
70
|
|
|
|
|
|
|
description => "Stop at season SEASON (default $CURRENT_SEASON)", |
71
|
|
|
|
|
|
|
}, |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
short => 'T', long => 'stage', arg => 'STAGE', type => 'i', |
74
|
|
|
|
|
|
|
description => "Scrape stage STAGE ($REGULAR: REGULAR, $PLAYOFF: PLAYOFF, default: $CURRENT_STAGE", |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
], |
77
|
|
|
|
|
|
|
database => [ |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
long => 'no-database', |
80
|
|
|
|
|
|
|
description => 'Do not use a MongoDB backend', |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
{ |
83
|
|
|
|
|
|
|
short => 'D', long => 'database', arg => 'DB', type => 's', |
84
|
|
|
|
|
|
|
description => "Use Mongo database DB (default $def_db)" |
85
|
|
|
|
|
|
|
}, |
86
|
|
|
|
|
|
|
], |
87
|
|
|
|
|
|
|
compile => [ |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
long => 'no-compile', |
90
|
|
|
|
|
|
|
description => 'Do not compile file even if storable is absent', |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
long => 'recompile', |
94
|
|
|
|
|
|
|
description => 'Compile file even if storable is present', |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
], |
97
|
|
|
|
|
|
|
merge => [ |
98
|
|
|
|
|
|
|
{ |
99
|
|
|
|
|
|
|
long => 'no-merge', |
100
|
|
|
|
|
|
|
description => 'Do not merge file even if storable is absent', |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
long => 'remerge', |
104
|
|
|
|
|
|
|
description => 'Compile file even if storable is present', |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
], |
107
|
|
|
|
|
|
|
normalize => [ |
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
long => 'no-normalize', |
110
|
|
|
|
|
|
|
description => 'Do not normalize file even if storable is absent', |
111
|
|
|
|
|
|
|
}, |
112
|
|
|
|
|
|
|
{ |
113
|
|
|
|
|
|
|
long => 'renormalize', |
114
|
|
|
|
|
|
|
description => 'Compile file even if storable is present', |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
], |
117
|
|
|
|
|
|
|
misc => [ |
118
|
|
|
|
|
|
|
{ |
119
|
|
|
|
|
|
|
short => 'f', long => 'force', |
120
|
|
|
|
|
|
|
description => 'override/overwrite existing data', |
121
|
|
|
|
|
|
|
}, |
122
|
|
|
|
|
|
|
{ |
123
|
|
|
|
|
|
|
long => 'test', |
124
|
|
|
|
|
|
|
description => 'Test the validity of the files (use with caution)' |
125
|
|
|
|
|
|
|
}, |
126
|
|
|
|
|
|
|
{ |
127
|
|
|
|
|
|
|
long => 'doc', |
128
|
|
|
|
|
|
|
description => 'Only process reports of type doc (repeatable). Available types are: BS, PL, RO, GS, ES', |
129
|
|
|
|
|
|
|
repeatable => 1, arg => 'DOC', |
130
|
|
|
|
|
|
|
type => 's' |
131
|
|
|
|
|
|
|
}, |
132
|
|
|
|
|
|
|
{ |
133
|
|
|
|
|
|
|
long => 'no-schedule-crawl', |
134
|
|
|
|
|
|
|
description => 'Try to use schedule already present in the system', |
135
|
|
|
|
|
|
|
}, |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
short => 'E', long => 'data-dir', arg => 'DIR', type => 's', |
138
|
|
|
|
|
|
|
description => "Data directory root (default $DATA_DIR)", |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
], |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub usage (;$) { |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
0
|
0
|
1
|
|
my $status = shift || 0; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
print join("\n", <
|
148
|
|
|
|
|
|
|
$USAGE_MESSAGE |
149
|
|
|
|
|
|
|
ENDUSAGE |
150
|
0
|
|
|
|
|
|
exit $status; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub convert_opt ($) { |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
0
|
1
|
|
my $opt = shift; |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
my $c_opt = $opt; |
158
|
0
|
|
|
|
|
|
$c_opt =~ s/\-/_/g; |
159
|
0
|
|
|
|
|
|
$c_opt; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub gopts ($$$) { |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
0
|
1
|
|
my $wid = shift; |
165
|
0
|
|
|
|
|
|
my $opts = shift; |
166
|
0
|
|
|
|
|
|
my $args = shift; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my %g_opts = (); |
169
|
0
|
|
|
|
|
|
my $u_opts = {}; |
170
|
0
|
0
|
|
|
|
|
my $u_arg = @{$args} ? ' Arguments' : ''; |
|
0
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
my $usage_message =" |
172
|
|
|
|
|
|
|
\t\t$wid |
173
|
|
|
|
|
|
|
\t\tUsage: $0 [Options]$u_arg |
174
|
|
|
|
|
|
|
"; |
175
|
0
|
0
|
|
|
|
|
unshift(@{$opts}, ':standard') unless grep {$_ eq '-standard'} @{$opts}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
if (@{$opts}) { |
|
0
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
$usage_message .= "\t\tOptions:\n"; |
178
|
0
|
|
|
|
|
|
for my $opt_group (@{ $opts }) { |
|
0
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
my @opts; |
180
|
0
|
0
|
|
|
|
|
if ($opt_group =~ /^\:(.*)/) { |
181
|
0
|
|
|
|
|
|
@opts = @{ $OPTS{$1} }; |
|
0
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
else { |
184
|
0
|
|
|
|
|
|
@opts = grep { $_->{long} eq $opt_group } @{ $OPTS{misc} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
} |
186
|
0
|
|
|
|
|
|
for my $opt (@opts) { |
187
|
|
|
|
|
|
|
$usage_message .= sprintf( |
188
|
|
|
|
|
|
|
"\t\t\t%-20s %-10s %s\n", |
189
|
|
|
|
|
|
|
($opt->{short} ? "-$opt->{short}|" : '') . "--$opt->{long}", |
190
|
|
|
|
|
|
|
$opt->{arg} || '', |
191
|
|
|
|
|
|
|
$opt->{description}, |
192
|
0
|
0
|
0
|
|
|
|
); |
193
|
0
|
0
|
|
|
|
|
my $is_repeatable = $opt->{repeatable} ? '@' : ''; |
194
|
|
|
|
|
|
|
$g_opts{ |
195
|
|
|
|
|
|
|
(($opt->{short} ? "$opt->{short}|" : '') . $opt->{long}) . |
196
|
|
|
|
|
|
|
($opt->{type} ? "=$opt->{type}$is_repeatable" : '') |
197
|
0
|
0
|
0
|
|
|
|
} = ($opt->{action} || \$u_opts->{convert_opt($opt->{long})}); |
|
|
0
|
|
|
|
|
|
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
else { |
202
|
0
|
|
|
|
|
|
$usage_message .= "\t\tNo Options\n"; |
203
|
|
|
|
|
|
|
} |
204
|
0
|
0
|
|
|
|
|
if (@{$args}) { |
|
0
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
$usage_message .= "\t\tArguments:\n"; |
206
|
0
|
|
|
|
|
|
for my $arg (@{$args}) { |
|
0
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
$usage_message .= sprintf( |
208
|
|
|
|
|
|
|
"\t\t\t%-20s %s%s", |
209
|
|
|
|
|
|
|
$arg->{name}, $arg->{description}, |
210
|
0
|
0
|
|
|
|
|
$arg->{optional} ? ' [optional]' : '' |
211
|
|
|
|
|
|
|
); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
0
|
|
|
|
|
|
$USAGE_MESSAGE = $usage_message; |
215
|
0
|
0
|
|
|
|
|
GetOptions(%g_opts) || usage(); |
216
|
0
|
|
|
|
|
|
$u_opts; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 AUTHOR |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
More Hockey Stats, C<< >> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 BUGS |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
228
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
229
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 SUPPORT |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
perldoc Sport::Analytics::NHL::Usage |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
You can also look for information at: |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=over 4 |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
L |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
L |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item * CPAN Ratings |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
L |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * Search CPAN |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
L |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=back |