QuoteHist/Generic.pm

filter: Statementstmt 57.6% 428 / 743 Branchbran 37.6% 170 / 452 Conditioncond 23.9% 50 / 209 MC/DCmcdc 2.2% 3 / 134 Subroutinesub 59.3% 51 / 86 Podpod 28.9% 20 / 69 totaltotal 42.6% 722 / 1693 SCAR 97.8
CC
333
Cov
46%
__ANON__
1519.4
__ANON__
506.0
set_label_pattern
110.0
CRAP 17645.2
↑ Summary QuoteHist/Yahoo.pm »
1 package Finance::QuoteHist::Generic;
2  
3 # http://www.stanford.edu/dept/OOD/RESEARCH/top-ten-faq/how_do_i_find_an_historical_st.html
4 #
5 # Shortcut: Use adjusted close price
6 #
7 # For the mathematically inclined, one shortcut to determining the value
8 # after splits is to use the adjusted close price from the historical
9 # quote tool. For June 2, 1997, it lists a market close price of 33.13
10 # and an adjusted close price of 1.38. Divide 33.13 by 1.38 and you come
11 # up with 24.007. Multiply by 1,000 and you come pretty close to the
12 # 24,000 share figure determined above. Or you could divide 1.38 by
13 # 33.13, which gives you 0.041654. Divide $33,130 by 0.041654, and you
14 # get $795K, which is very close to the $808K figure above.
15  
16 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 $VERSION = "1.22";
21  
22 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use Date::Manip;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 5 my $CSV_XS_Class = 'Text::CSV_XS';
27 5 my $CSV_PP_Class = 'Text::CSV_PP';
28 5 my $CSV_Class = $CSV_XS_Class;
29 5 ▶eval "use $CSV_Class";
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 5 5
31 0 $CSV_Class = $CSV_PP_Class;
32 0 eval "use $CSV_Class";
33 0 ▶ croak "Could not load either $CSV_XS_Class or $CSV_PP_Class : $@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
34 }
35  
36 5 my $HTE_CLASS;
37 5 my $HTE_Class = 'HTML::TableExtract';
38 sub HTML_CLASS {
39 0 ▶ if (!$HTE_CLASS) {
Subroutine HTML_CLASS: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless ($HTE_CLASS) 0 0 0
40 0 eval "use $HTE_Class";
41 0 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
42 0 $HTE_CLASS = $HTE_Class;
43 }
44 0 $HTE_CLASS;
45 }
46  
47 5 my $Default_Target_Mode = 'quote';
48 5 my $Default_Parse_Mode = 'html';
49 5 my $Default_Granularity = 'daily';
50 5 my $Default_Vol_Pat = qr(vol|shares)i;
51  
52 5 my %Default_Labels;
53 5 $Default_Labels{quote}{$Default_Parse_Mode} =
54 [qw( date open high low close ), $Default_Vol_Pat];
55 5 $Default_Labels{dividend}{$Default_Parse_Mode} =
56 [qw( date div )];
57 5 $Default_Labels{'split'}{$Default_Parse_Mode} =
58 [qw( date post pre )];
59 5 $Default_Labels{intraday}{$Default_Parse_Mode} =
60 [qw( date time high low close ), $Default_Vol_Pat];
61  
62 5 my @Scalar_Flags = qw(
63 verbose
64 quiet
65 zthresh
66 quote_precision
67 attempts
68 adjusted
69 has_non_adjusted
70 env_proxy
71 debug
72 parse_mode
73 target_mode
74 granularity
75 auto_proxy
76 row_filter
77 ua_params
78 );
79 5 my $SF_pat = join('|', @Scalar_Flags);
80  
81 5 my @Array_Flags = qw(
82 symbols
83 lineup
84 );
85 5 my $AF_pat = join('|', @Array_Flags);
86  
87 5 my @Hash_Flags = qw( ua_params );
88 5 my $HF_pat = join('|', @Hash_Flags);
89  
90 sub new {
91 5 ▶ my $that = shift;
Subroutine new: called CC=29 SCAR=39.5
Pod documented
92 5 ▶ my $class = ref($that) || $that;
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
93 5 my(%parms, $k, $v);
94 5 ▶ while (($k,$v) = splice(@_, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 33 5 38
95 33 ▶ if ($k eq 'start_date' || $k eq 'end_date' && $v !~ /^\s*$/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($k eq 'start_date' or $k eq 'end_date' and not $v =~ /^\s*$/) { } 10 23 33
elsif ($k =~ /^$AF_pat$/o) { } 5 18 23
elsif ($k =~ /^$HF_pat$/o) { } 5 13 18
elsif ($k eq 'row_filter') { } 0 13 13
elsif ($k =~ /^$SF_pat$/o) { } 13 0 13
Condition83%5/6
$k eq "start_date" or $k eq "end_date" and not $v =~ /^\s*$/
l!l&&r!l&&!r
5523
$k eq "end_date" and not $v =~ /^\s*$/
!ll&&!rl&&r
2305
MC/DC66%2/3
$k eq "start_date" or $k eq "end_date" and not $v =~ /^\s*$/
$k eq "start_date" $k eq "end_date" not $v =~ /^\s*$/
Truth table75%3/4
A or B and not(C)
A= $k eq "start_date"B= $k eq "end_date"C= not $v =~ /^\s*$/
ABCresult
1XX1
0111
00X0
0100
96 10 $parms{$k} = __PACKAGE__->date_standardize($v);
97 }
98 elsif ($k =~ /^$AF_pat$/o) {
99 5 ▶ if (UNIVERSAL::isa($v, 'ARRAY')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($v, 'ARRAY')) { } 0 5 5
elsif (ref $v) { } 0 5 5
100 0 $parms{$k} = $v;
101 }
102 elsif (ref $v) {
103 0 croak "$k must be passed as an array ref or single-entry string\n";
104 }
105 else {
106 5 $parms{$k} = [$v];
107 }
108 }
109 elsif ($k =~ /^$HF_pat$/o) {
110 5 ▶ if (UNIVERSAL::isa($v, 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($v, 'HASH')) { } 5 0 5
111 5 $parms{$k} = $v;
112 }
113 else {
114 0 croak "$k must be passed as a hash ref\n";
115 }
116 }
117 elsif ($k eq 'row_filter') {
118 0 ▶ croak "$k must be sub ref\n" unless UNIVERSAL::isa($v, 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($v, "CODE") 0 0 0
119 0 $parms{$k} = $v;
120 }
121 elsif ($k =~ /^$SF_pat$/o) {
122 13 $parms{$k} = $v;
123 }
124 }
125 5 ▶ $parms{end_date} ||= __PACKAGE__->date_standardize('today');
Condition33%1/3
$parms{"end_date"} ||= __PACKAGE__->date_standardize("today")
l!l&&r!l&&!r
500
MC/DC0%0/2
$parms{"end_date"} ||= __PACKAGE__->date_standardize("today")
$parms{"end_date"} __PACKAGE__->date_standardize("today")
Truth table33%1/3
A ||= B
A= $parms{"end_date"}B= __PACKAGE__->date_standardize("today")
ABresult
1X1
011
000
126 5 ▶ $parms{symbols} or croak "Symbol list required\n";
Branch: 1 branch
BranchTrueFalseTotal
$parms{"symbols"} or croak("Symbol list required\n") 0 5 5
127  
128 5 my $start_date = delete $parms{start_date};
129 5 my $end_date = delete $parms{end_date};
130 5 my $symbols = delete $parms{symbols};
131  
132 # Defaults
133 5 ▶ $parms{zthresh} = 30 unless $parms{zthresh};
Branch: 1 branch
BranchTrueFalseTotal
unless $parms{"zthresh"} 5 0 5
134 5 ▶ $parms{attempts} = 3 unless $parms{attempts};
Branch: 1 branch
BranchTrueFalseTotal
unless $parms{"attempts"} 5 0 5
135 5 ▶ $parms{adjusted} = 1 unless exists $parms{adjusted};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $parms{"adjusted"} 5 0 5
136 5 ▶ $parms{has_non_adjusted} = 0 unless defined $parms{has_non_adjusted};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"has_non_adjusted"} 5 0 5
137 5 ▶ $parms{quote_precision} = 4 unless defined $parms{quote_precision};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"quote_precision"} 5 0 5
138 5 ▶ $parms{auto_proxy} = 1 unless exists $parms{auto_proxy};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $parms{"auto_proxy"} 0 5 5
139 5 ▶ $parms{debug} = 0 unless defined $parms{debug};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"debug"} 5 0 5
140  
141 5 my $self = \%parms;
142 5 bless $self, $class;
143  
144 5 ▶ my $ua_params = $parms{ua_params} || {};
Condition50%1/2
$parms{'ua_params'} || {}
l!l
50
MC/DC0%0/1
$parms{'ua_params'} || {}
$parms{'ua_params'}
Truth table50%1/2
A
A= $parms{'ua_params'}
Aresult
11
00
145 5 ▶ if ($parms{env_proxy}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parms{'env_proxy'}) { } 0 5 5
elsif ($parms{'auto_proxy'}) { } 5 0 5
146 0 $ua_params->{env_proxy} = 1;
147 }
148 elsif ($parms{auto_proxy}) {
149 5 ▶ $ua_params->{env_proxy} = 1 if $ENV{http_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"http_proxy"} 0 5 5
150 }
151 5 ▶ $self->{ua} ||= LWP::UserAgent->new(%$ua_params);
Condition33%1/3
$self->{"ua"} ||= "LWP::UserAgent"->new(%$ua_params)
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->{"ua"} ||= "LWP::UserAgent"->new(%$ua_params)
$self->{"ua"} "LWP::UserAgent"->new(%$ua_params)
Truth table33%1/3
A ||= B
A= $self->{"ua"}B= "LWP::UserAgent"->new(%$ua_params)
ABresult
1X1
011
000
152  
153 5 ▶ if ($self->granularity !~ /^d/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->granularity =~ /^d/i) 2 3 5
154 2 $start_date = $self->snap_start_date($start_date);
155 2 $end_date = $self->snap_end_date($end_date);
156 }
157  
158 5 $self->start_date($start_date);
159 5 $self->end_date($end_date);
160 5 $self->symbols(@$symbols);
161  
162 # These are used for constructing method names for target types.
163 5 $self->{target_order} = [qw(quote split dividend)];
164 5 grep($self->{targets}{$_} = "${_}s", @{$self->{target_order}});
165  
166 5 $self;
167 }
168  
169 ### User interface stubs
170  
171 3 ▶sub quotes { shift->getter(target_mode => 'quote')->() }
Subroutine quotes: called CC=1 SCAR=0.0
Pod documented
172 1 ▶sub dividends { shift->getter(target_mode => 'dividend')->() }
Subroutine dividends: called CC=1 SCAR=0.0
Pod documented
173 1 ▶sub splits { shift->getter(target_mode => 'split')->() }
Subroutine splits: called CC=1 SCAR=0.0
Pod documented
174 0 ▶sub intraday { shift->getter(target_mode => 'intraday')->() }
Subroutine intraday: not called CC=1 SCAR=6.9
Pod undocumented
175  
176 5 *intraday_quotes = *intraday;
177  
178 sub target_worthy {
179 5 ▶ my $self = shift;
Subroutine target_worthy: called CC=6 SCAR=22.4
Pod undocumented
180 5 my %parms = @_;
181 5 ▶ my $target_mode = $parms{target_mode} || $self->target_mode;
Condition33%1/3
$parms{'target_mode'} || $self->target_mode
l!l&&r!l&&!r
500
MC/DC0%0/2
$parms{'target_mode'} || $self->target_mode
$parms{'target_mode'} $self->target_mode
Truth table33%1/3
A || B
A= $parms{'target_mode'}B= $self->target_mode
ABresult
1X1
011
000
182 5 ▶ my $parse_mode = $parms{parse_mode} || $self->parse_mode;
Condition33%1/3
$parms{'parse_mode'} || $self->parse_mode
l!l&&r!l&&!r
500
MC/DC0%0/2
$parms{'parse_mode'} || $self->parse_mode
$parms{'parse_mode'} $self->parse_mode
Truth table33%1/3
A || B
A= $parms{'parse_mode'}B= $self->parse_mode
ABresult
1X1
011
000
183 # forcing url_maker into a boolean role here, using a dummy symbol
184 5 my $capable = $self->url_maker(
185 %parms,
186 target_mode => $target_mode,
187 parse_mode => $parse_mode,
188 symbol => 'waggledance',
189 );
190 5 ▶ my $worthy = $capable && UNIVERSAL::isa($capable, 'CODE');
Condition33%1/3
$capable && UNIVERSAL::isa($capable, 'CODE')
!ll&&!rl&&r
005
MC/DC0%0/2
$capable && UNIVERSAL::isa($capable, 'CODE')
$capable UNIVERSAL::isa($capable, 'CODE')
Truth table33%1/3
A && B
A= $capableB= UNIVERSAL::isa($capable, 'CODE')
ABresult
0X0
100
111
191 5 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 5 5
192 0 ▶ print STDERR "Seeing if ", ref $self,
Branch: 1 branch
BranchTrueFalseTotal
$worthy ? : 0 0 0
193 " can get ($target_mode, $parse_mode) : ",
194 $worthy ? "yes\n" : "no\n";
195 }
196 5 $worthy;
197 }
198  
199 0 ▶sub granularities { qw( daily ) }
Subroutine granularities: not called CC=1 SCAR=6.9
Pod undocumented
200  
201 ### Data retrieval
202  
203 sub ua {
204 25 ▶ my $self = shift;
Subroutine ua: called CC=2 SCAR=7.2
Pod documented
205 25 ▶ @_ ? $self->{ua} = shift : $self->{ua};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 25 25
206 }
207  
208 sub fetch {
209 # HTTP::Request and LWP::UserAgent Wrangler
210 10 ▶ my($self, $request) = splice(@_, 0, 2);
Subroutine fetch: called CC=10 SCAR=24.1
Pod undocumented
211 10 ▶ $request or croak "Request or URL required\n";
Branch: 1 branch
BranchTrueFalseTotal
$request or croak("Request or URL required\n") 0 10 10
212  
213 10 ▶ if (! ref $request || ! $request->isa('HTTP::Request')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $request and $request->isa("HTTP::Request")) 10 0 10
Condition33%1/3
ref $request and $request->isa("HTTP::Request")
!ll&&!rl&&r
1000
MC/DC0%0/2
ref $request and $request->isa("HTTP::Request")
ref $request $request->isa("HTTP::Request")
Truth table33%1/3
A and B
A= ref $requestB= $request->isa("HTTP::Request")
ABresult
0X0
100
111
214 10 $request = HTTP::Request->new(GET => $request);
215 }
216  
217 10 my $trys = $self->{attempts};
218 10 my $response = $self->ua->request($request, @_);
219 10 $self->{_lwp_success} = 0;
220 10 ▶ while (! $response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 20 5 25
221 20 ▶ last unless $trys;
Branch: 1 branch
BranchTrueFalseTotal
unless $trys 5 15 20
222 15 $self->{_lwp_status} = $response->status_line;
223 print STDERR "Bad fetch",
224 $response->is_error ? ' (' . $response->status_line . '), ' : ', ',
225 15 ▶ "trying again...\n" if $self->{debug};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"debug"} 0 15 15
$response->is_error ? : 0 0 0
226 15 $response = $self->ua->request($request, @_);
227 15 --$trys;
228 }
229 10 $self->{_lwp_success} = $response->is_success;
230 10 ▶ return undef unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 5 5 10
231 print STDERR 'Fetch complete. (' . length($response->content) . " chars)\n"
232 5 ▶ if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 5 5
233 5 $response->content;
234 }
235  
236 sub getter {
237 # closure factory to get results for a particular target_mode and
238 # parse_mode
239 5 ▶ my $self = shift;
Subroutine getter: called CC=3 SCAR=15.3
Pod undocumented
240  
241 5 my %parms = @_;
242 5 ▶ my $target_mode = $parms{target_mode} || $self->target_mode;
Condition33%1/3
$parms{'target_mode'} || $self->target_mode
l!l&&r!l&&!r
500
MC/DC0%0/2
$parms{'target_mode'} || $self->target_mode
$parms{'target_mode'} $self->target_mode
Truth table33%1/3
A || B
A= $parms{'target_mode'}B= $self->target_mode
ABresult
1X1
011
000
243 5 ▶ my $parse_mode = $parms{parse_mode} || $self->parse_mode;
Condition33%1/3
$parms{'parse_mode'} || $self->parse_mode
l!l&&r!l&&!r
050
MC/DC0%0/2
$parms{'parse_mode'} || $self->parse_mode
$parms{'parse_mode'} $self->parse_mode
Truth table33%1/3
A || B
A= $parms{'parse_mode'}B= $self->parse_mode
ABresult
1X1
011
000
244 5 my @column_labels = $self->labels(
245 %parms, target_mode => $target_mode, parse_mode => $parse_mode
246 );
247 5 my %extractors = $self->extractors(
248 %parms, target_mode => $target_mode, parse_mode => $parse_mode
249 );
250  
251 # return our closure
252 sub {
253 5 ▶ my @symbols = @_ ? @_ : $self->symbols;
Subroutine __ANON__: called CC=87 SCAR=73.3
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 5 5
254  
255 5 my @rows;
256  
257 # cache check
258 my @not_seen;
259 5 foreach my $symbol (@symbols) {
260 5 my @r = $self->result_rows($target_mode, $symbol);
261 5 ▶ if (@r) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r) { } 0 5 5
262 0 push(@rows, @r);
263 }
264 else {
265 5 push(@not_seen, $symbol);
266 }
267 }
268 5 ▶ return @rows unless @not_seen;
Branch: 1 branch
BranchTrueFalseTotal
unless @not_seen 0 5 5
269  
270 5 my $original_target_mode = $self->target_mode;
271 5 my $original_parse_mode = $self->parse_mode;
272  
273 5 $self->target_mode($target_mode);
274 5 $self->parse_mode($parse_mode);
275  
276 5 my $dcol = $self->label_column('date');
277 5 my(%empty_fetch, %saw_good_rows);
278 5 my $last_data = '';
279  
280 5 my $target_worthy = $self->target_worthy(
281 %parms,
282 target_mode => $target_mode,
283 parse_mode => $parse_mode
284 );
285 5 ▶ if (!$target_worthy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target_worthy) 0 5 5
286 # make sure and empty @symbols
287 0 ▶ ++$empty_fetch{$_} while $_ = pop @symbols;
Branch: 1 branch
BranchTrueFalseTotal
$_ = pop @symbols and do { ++$empty_fetch{$_} } 0 0 0
288 }
289  
290 5 SYMBOL: foreach my $s (@symbols) {
291 5 my $urlmaker = $self->url_maker(
292 target_mode => $target_mode,
293 parse_mode => $parse_mode,
294 symbol => $s,
295 );
296 5 ▶ UNIVERSAL::isa($urlmaker, 'CODE') or croak "urlmaker not a code ref.\n";
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($urlmaker, "CODE") or croak("urlmaker not a code ref.\n") 0 5 5
297 5 my $so_far_so_good = 0;
298 5 ▶ URL: while (my $url = $urlmaker->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = &$urlmaker()) 5 5 10
299 5 ▶ if ($empty_fetch{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($empty_fetch{$s}) 0 5 5
300 print STDERR ref $self,
301 " passing on $s ($target_mode) for now, empty fetch\n"
302 0 ▶ if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
303 0 last URL;
304 }
305  
306 5 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 5 5
307 0 my $uri = $url;
308 0 ▶ $uri = $url->uri if UNIVERSAL::isa($url, 'HTTP::Request');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($url, "HTTP::Request") 0 0 0
309 0 print STDERR "Processing ($s:$target_mode) $uri\n";
310 }
311  
312 # We're a bit more persistent with quotes. It is more suspicious
313 # if we get no quote rows, but it is nevertheless possible.
314 5 ▶ my $trys = $target_mode eq 'quote' ? $self->{attempts} : 1;
Branch: 1 branch
BranchTrueFalseTotal
$target_mode eq 'quote' ? : 3 2 5
315 5 my $initial_trys = $trys;
316 5 my($data, $rows) = ('', []);
317 do {
318 print STDERR "$s Trying ($target_mode) again due to no rows...\n"
319 5 ▶ if $self->{verbose} && $trys != $initial_trys;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} and $trys != $initial_trys 0 5 5
Condition33%1/3
$self->{"verbose"} and $trys != $initial_trys
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"verbose"} and $trys != $initial_trys
$self->{"verbose"} $trys != $initial_trys
Truth table33%1/3
A and B
A= $self->{"verbose"}B= $trys != $initial_trys
ABresult
0X0
100
111
320 5 ▶ if (!($data = $self->{url_cache}{$url})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data = $self->{"url_cache"}{$url}) 5 0 5
321 5 $data = $self->fetch($url);
322 5 ▶ if (my $pre_parser = $self->pre_parser) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pre_parser = $self->pre_parser) 0 5 5
323 0 $data = $pre_parser->(
324 $data,
325 target_mode => $target_mode,
326 parse_mode => $parse_mode,
327 );
328 }
329 }
330 # make sure our url_maker hasn't sent us into a twister
331 5 ▶ if ($data && $data eq $last_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data and $data eq $last_data) { } 0 5 5
Condition33%1/3
$data and $data eq $last_data
!ll&&!rl&&r
050
MC/DC0%0/2
$data and $data eq $last_data
$data $data eq $last_data
Truth table33%1/3
A and B
A= $dataB= $data eq $last_data
ABresult
0X0
100
111
332 print STDERR "Redundant data fetch, assuming end of URLs.\n"
333 0 ▶ if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
334 0 last URL;
335 }
336 else {
337 5 ▶ $last_data = defined $data ? $data : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $data ? : 5 0 5
338 }
339 5 $rows = $self->rows($self->parser->($data));
340 5 ▶ last URL if $so_far_so_good && !@$rows;
Branch: 1 branch
BranchTrueFalseTotal
if $so_far_so_good and not @$rows 0 5 5
Condition33%1/3
$so_far_so_good and not @$rows
!ll&&!rl&&r
500
MC/DC0%0/2
$so_far_so_good and not @$rows
$so_far_so_good not @$rows
Truth table33%1/3
A and not(B)
A= $so_far_so_goodB= not @$rows
ABresult
0X0
100
111
341 5 --$trys;
342 5 ▶ } while !@$rows && $trys && $self->{_lwp_success};
Branch: 1 branch
BranchTrueFalseTotal
not @$rows and $trys and $self->{"_lwp_success"} and do { do { print STDERR "$s Trying ($target_mode) again due to no rows...\n" if $self->{"verbose"} and $trys != $initial_trys; unless ($data = $self->{"url_cache"}{$url}) { $data = $self->fetch($url); if (my $pre_parser = $self->pre_parser) { $data = &$pre_parser($data, "target_mode", $target_mode, "parse_mode", $parse_mode); } ; } ; if ($data and $data eq $last_data) { print STDERR "Redundant data fetch, assuming end of URLs.\n" if $self->{"verbose"}; last URL; } else { $last_data = defined $data ? $data : ""; } ; $rows = $self->rows($self->parser->($data)); last URL if $so_far_so_good and not @$rows; --$trys } } 0 5 5
Condition33%2/6
not @$rows and $trys and $self->{"_lwp_success"}
!ll&&!rl&&r
500
not @$rows and $trys
!ll&&!rl&&r
500
MC/DC0%0/3
not @$rows and $trys and $self->{"_lwp_success"}
not @$rows $trys $self->{"_lwp_success"}
Truth table25%1/4
not(A) and B and C
A= not @$rowsB= $trysC= $self->{"_lwp_success"}
ABCresult
0XX0
10X0
1100
1111
343 5 $so_far_so_good = 1;
344  
345 5 ▶ if ($target_mode ne 'quote' || $target_mode ne 'intraday') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_mode ne "quote" or $target_mode ne "intraday") 5 0 5
Condition66%2/3
$target_mode ne "quote" or $target_mode ne "intraday"
l!l&&r!l&&!r
230
MC/DC0%0/2
$target_mode ne "quote" or $target_mode ne "intraday"
$target_mode ne "quote" $target_mode ne "intraday"
Truth table66%2/3
A or B
A= $target_mode ne "quote"B= $target_mode ne "intraday"
ABresult
1X1
011
000
346 # We are not very stubborn about dividends and splits right
347 # now. This is because we cannot prove a successful negative
348 # (i.e., say there were no dividends or splits over the time
349 # period...or perhaps there were, but it is a defunct
350 # symbol...whatever...quotes should always be present unless
351 # they are defunct, which is dealt with later.
352 5 ▶ if (!$self->{_lwp_success} || !$data) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'_lwp_success'} && $data) { } 0 5 5
elsif ($self->{'_lwp_success'} and not @$rows) { } 0 5 5
Condition33%1/3
$self->{'_lwp_success'} && $data
!ll&&!rl&&r
005
MC/DC0%0/2
$self->{'_lwp_success'} && $data
$self->{'_lwp_success'} $data
Truth table33%1/3
A && B
A= $self->{'_lwp_success'}B= $data
ABresult
0X0
100
111
353 0 ++$empty_fetch{$s};
354 0 @$rows = ();
355 }
356 ▶ elsif ($self->{_lwp_success} && !@$rows) {
Condition33%1/3
$self->{"_lwp_success"} and not @$rows
!ll&&!rl&&r
050
MC/DC0%0/2
$self->{"_lwp_success"} and not @$rows
$self->{"_lwp_success"} not @$rows
Truth table33%1/3
A and not(B)
A= $self->{"_lwp_success"}B= not @$rows
ABresult
0X0
100
111
357 0 ++$empty_fetch{$s};
358 }
359 }
360  
361 # Raw cache
362 5 $self->{url_cache}{$url} = $data;
363
364 # Extraction filters. This is an opportunity to extract rows
365 # that are not what we are looking for, but contain valuable
366 # information nevertheless. An example of this would be the
367 # split and dividend rows you see in Yahoo HTML quote output. An
368 # extraction filter method should expect an array ref as an
369 # argument, representing a single row, and should return another
370 # array ref with extracted output. If there is a return value,
371 # then this row will be filtered from the primary output.
372 5 my(%extractions, $ecount, $rc);
373 5 $rc = @$rows;
374 5 ▶ if (%extractors) {
Branch: 1 branch
BranchTrueFalseTotal
if (%extractors) 0 5 5
375 0 my(@filtered, $row);
376 0 ▶ while ($row = pop(@$rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row = pop @$rows) 0 0 0
377 0 my $erow;
378 0 foreach my $mode (sort keys %extractors) {
379 0 ▶ $extractions{$mode} ||= [];
Condition0%0/2
$extractions{$mode} ||= []
l!l
00
MC/DC0%0/1
$extractions{$mode} ||= []
$extractions{$mode}
Truth table0%0/2
A
A= $extractions{$mode}
Aresult
11
00
380 0 my $em = $extractors{$mode};
381 0 ▶ if ($erow = $em->($row)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($erow = &$em($row)) 0 0 0
382 print STDERR "$s extract ($mode) got $s, ",
383 0 ▶ join(', ', @$erow), "\n" if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
384 0 push(@{$extractions{$mode}}, [@$erow]);
385 0 ++$ecount;
386 0 last;
387 }
388 }
389 0 ▶ push(@filtered, $row) unless $erow;
Branch: 1 branch
BranchTrueFalseTotal
unless $erow 0 0 0
390 }
391 0 ▶ if ($self->{verbose} && $ecount) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} and $ecount) 0 0 0
Condition0%0/3
$self->{"verbose"} and $ecount
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"verbose"} and $ecount
$self->{"verbose"} $ecount
Truth table0%0/3
A and B
A= $self->{"verbose"}B= $ecount
ABresult
0X0
100
111
392 0 print STDERR "$s Trimmed to ",$rc - $ecount,
393 " rows after $ecount extractions.\n";
394 }
395 0 $rows = \@filtered;
396 }
397  
398 5 ▶ if ($extractions{$target_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extractions{$target_mode}) 0 5 5
399 0 $rows = [@{$extractions{$target_mode}}];
400 print STDERR "Coopted to ", scalar @$rows,
401 " rows after $target_mode extraction redundancy.\n"
402 0 ▶ if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
403 }
404  
405 5 ▶ if (@$rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$rows) 5 0 5
406 # Normalization steps
407  
408 5 ▶ if ($target_mode eq 'split') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_mode eq "split") 1 4 5
409 1 ▶ if (@{$rows->[0]} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rows->[0];} == 2) 0 1 1
410 0 foreach (@$rows) {
411 0 ▶ if ($_->[-1] =~ /(split\s+)?(\d+)\D+(\d+)/is) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->[-1] =~ /(split\s+)?(\d+)\D+(\d+)/is) 0 0 0
412 0 splice(@$_, -1, 1, $2, $3);
413 }
414 }
415 }
416 }
417  
418 # Saving the rounding operations until after the adjust
419 # routine is deliberate since we don't want to be auto-
420 # adjusting pre-rounded numbers.
421 5 $self->number_normalize_rows($rows);
422
423 # Do the same for the extraction rows, plus store the
424 # extracted rows
425 5 foreach my $mode (keys %extractions) {
426 # _store_results splices each row...don't do it twice
427 0 ▶ next if $mode eq $target_mode;
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq $target_mode 0 0 0
428 0 $self->target_mode($mode);
429 0 $self->number_normalize_rows($extractions{$mode});
430 0 $self->_target_source($mode, $s, ref $self);
431 0 $self->_store_results($mode, $s, $dcol, $extractions{$mode});
432 }
433 # restore original target mode
434 5 $self->target_mode($target_mode);
435
436 5 ▶ if ($target_mode eq 'quote' || $target_mode eq 'intraday') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_mode eq "quote" or $target_mode eq "intraday") 3 2 5
Condition66%2/3
$target_mode eq "quote" or $target_mode eq "intraday"
l!l&&r!l&&!r
302
MC/DC50%1/2
$target_mode eq "quote" or $target_mode eq "intraday"
$target_mode eq "quote" $target_mode eq "intraday"
Truth table66%2/3
A or B
A= $target_mode eq "quote"B= $target_mode eq "intraday"
ABresult
1X1
011
000
437 3 my $count = @$rows;
438 3 ▶ @$rows = grep($self->is_quote_row($_) &&
Condition33%1/3
$self->is_quote_row($_) && $self->row_not_seen($s, $_)
!ll&&!rl&&r
00317
MC/DC0%0/2
$self->is_quote_row($_) && $self->row_not_seen($s, $_)
$self->is_quote_row($_) $self->row_not_seen($s, $_)
Truth table33%1/3
A && B
A= $self->is_quote_row($_)B= $self->row_not_seen($s, $_)
ABresult
0X0
100
111
439 $self->row_not_seen($s, $_), @$rows);
440 3 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 3 3
441 0 ▶ if ($count == @$rows) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == @$rows) { } 0 0 0
442 0 print STDERR "$s Retained $count rows\n";
443 }
444 else {
445 0 print STDERR "$s Retained $count raw rows, trimmed to ",
446 scalar @$rows, " rows due to noise\n";
447 }
448 }
449
450 }
451 5 ▶ if ($target_mode eq 'quote') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_mode eq "quote") 3 2 5
452 # zcount is an attempt to capture null values; if there are
453 # too many we assume there is something wrong with the
454 # remote data
455 3 my $close_col = $self->label_column('close');
456 3 my($zcount, $hcount) = (0,0);
457 3 foreach (@$rows) {
458 317 foreach (@$_) {
459 # Sometimes N/A appears
460 1902 s%^\s*N/A\s*$%%;
461 }
462 317 my $q = $_->[$close_col];
463 317 ▶ if (defined $q && $q =~ /\d+/) { ++$hcount }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $q and $q =~ /\d+/) { } 317 0 317
Condition33%1/3
defined $q and $q =~ /\d+/
!ll&&!rl&&r
00317
MC/DC0%0/2
defined $q and $q =~ /\d+/
defined $q $q =~ /\d+/
Truth table33%1/3
A and B
A= defined $qB= $q =~ /\d+/
ABresult
0X0
100
111
464 0 else { ++$zcount }
465 }
466 3 ▶ my $pct = $hcount ? 100 * $zcount / ($zcount + $hcount) : 100;
Branch: 1 branch
BranchTrueFalseTotal
$hcount ? : 3 0 3
467 3 ▶ if (!$trys || $pct >= $self->{zthresh}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $trys or $pct >= $self->{'zthresh'}) { } 0 3 3
Condition33%1/3
not $trys or $pct >= $self->{"zthresh"}
l!l&&r!l&&!r
003
MC/DC0%0/2
not $trys or $pct >= $self->{"zthresh"}
not $trys $pct >= $self->{"zthresh"}
Truth table33%1/3
not(A) or B
A= not $trysB= $pct >= $self->{"zthresh"}
ABresult
1X1
011
000
468 0 ▶ ++$empty_fetch{$s} unless $saw_good_rows{$s};
Branch: 1 branch
BranchTrueFalseTotal
unless $saw_good_rows{$s} 0 0 0
469 }
470 else {
471 # For defunct symbols, we could conceivably get quotes
472 # over a date range that contains blocks of time where the
473 # ticker was actively traded, as well as blocks of time
474 # where the ticker doesn't exist. If we got good data over
475 # some of the blocks, then we take note of it so we don't
476 # toss the whole set of queries for this symbol.
477 3 ++$saw_good_rows{$s};
478 }
479 $self->precision_normalize_rows($rows)
480 3 ▶ if @$rows && $self->{quote_precision};
Branch: 1 branch
BranchTrueFalseTotal
if @$rows and $self->{"quote_precision"} 3 0 3
Condition33%1/3
@$rows and $self->{"quote_precision"}
!ll&&!rl&&r
003
MC/DC0%0/2
@$rows and $self->{"quote_precision"}
@$rows $self->{"quote_precision"}
Truth table33%1/3
A and B
A= @$rowsB= $self->{"quote_precision"}
ABresult
0X0
100
111
481 }
482  
483 5 ▶ last URL if !$ecount && !@$rows;
Branch: 1 branch
BranchTrueFalseTotal
unless $ecount or @$rows 0 5 5
Condition33%1/3
$ecount or @$rows
l!l&&r!l&&!r
050
MC/DC0%0/2
$ecount or @$rows
$ecount @$rows
Truth table33%1/3
A or B
A= $ecountB= @$rows
ABresult
1X1
011
000
484 5 ▶ $self->_store_results($target_mode, $s, $dcol, $rows) if @$rows;
Branch: 1 branch
BranchTrueFalseTotal
if @$rows 5 0 5
485 5 $self->_target_source($target_mode, $s, ref $self);
486 }
487 }
488 }
489  
490 5 $self->_store_empty_fetches([keys %empty_fetch]);
491
492 # Check for bad fetches. If we failed on some symbols, punt them to
493 # our champion class.
494 5 ▶ if (%empty_fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if (%empty_fetch) 0 5 5
495 0 my @bad_symbols = $self->empty_fetches;
496 0 my @champion_classes = $self->lineup;
497 0 ▶ while (@champion_classes && @bad_symbols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@champion_classes and @bad_symbols) 0 0 0
Condition0%0/3
@champion_classes and @bad_symbols
!ll&&!rl&&r
000
MC/DC0%0/2
@champion_classes and @bad_symbols
@champion_classes @bad_symbols
Truth table0%0/3
A and B
A= @champion_classesB= @bad_symbols
ABresult
0X0
100
111
498 print STDERR "Bad fetch for ", join(',', @bad_symbols), "\n"
499 0 ▶ if $self->{verbose} && $target_worthy;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} and $target_worthy 0 0 0
Condition0%0/3
$self->{"verbose"} and $target_worthy
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"verbose"} and $target_worthy
$self->{"verbose"} $target_worthy
Truth table0%0/3
A and B
A= $self->{"verbose"}B= $target_worthy
ABresult
0X0
100
111
500 0 my $champion =
501 $self->_summon_champion(shift @champion_classes, @bad_symbols);
502 0 ▶ next unless $champion &&
Branch: 1 branch
BranchTrueFalseTotal
unless $champion and $champion->target_worthy("target_mode", $target_mode) 0 0 0
Condition0%0/3
$champion and $champion->target_worthy("target_mode", $target_mode)
!ll&&!rl&&r
000
MC/DC0%0/2
$champion and $champion->target_worthy("target_mode", $target_mode)
$champion $champion->target_worthy("target_mode", $target_mode)
Truth table0%0/3
A and B
A= $championB= $champion->target_worthy("target_mode", $target_mode)
ABresult
0X0
100
111
503 $champion->target_worthy(target_mode => $target_mode);
504 0 ▶ print STDERR ref $champion, ", my hero!\n" if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
505 # Hail Mary
506 0 $champion->getter(target_mode => $target_mode)->();
507 # Our champion was the source for these symbols (including
508 # extracted info).
509 0 foreach my $mode ($champion->result_modes) {
510 0 foreach my $symbol ($champion->result_symbols($mode)) {
511 0 $self->_target_source($mode, $symbol, ref $champion);
512 0 $self->_copy_results($mode, $symbol,
513 $champion->results($mode, $symbol));
514 }
515 }
516 0 @bad_symbols = $champion->empty_fetches;
517 }
518 0 ▶ if (@bad_symbols && !$self->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bad_symbols and not $self->{"quiet"}) 0 0 0
Condition0%0/3
@bad_symbols and not $self->{"quiet"}
!ll&&!rl&&r
000
MC/DC0%0/2
@bad_symbols and not $self->{"quiet"}
@bad_symbols not $self->{"quiet"}
Truth table0%0/3
A and not(B)
A= @bad_symbolsB= not $self->{"quiet"}
ABresult
0X0
100
111
519 0 print STDERR "WARNING: Could not fetch $target_mode for some symbols (",join(', ', @bad_symbols), "). Abandoning request for these symbols.";
520 0 ▶ if ($target_mode ne 'quote') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_mode ne "quote") 0 0 0
521 0 print STDERR " Don't worry, though, we were looking for ${target_mode}s. These are less likely to exist compared to quotes.";
522 }
523 0 ▶ if ($self->{_lwp_status}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_lwp_status"}) 0 0 0
524 0 print STDERR "\n\nLast status: $self->{_lwp_status}\n";
525 }
526 0 print STDERR "\n";
527 }
528 }
529
530 5 $self->target_mode($original_target_mode);
531 5 $self->parse_mode($original_parse_mode);
532  
533 5 @rows = $self->result_rows($target_mode);
534 5 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 5 5
535 0 print STDERR "Class ", ref $self, " returning ", scalar @rows,
536 " composite rows.\n";
537 }
538  
539 # Return the loot.
540 5 ▶ wantarray ? @rows : \@rows;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 0 5
541 5 };
542 }
543  
544 sub _store_results {
545 5 ▶ my($self, $mode, $symbol, $dcol, $rows) = @_;
Subroutine _store_results: called CC=2 SCAR=6.9
546 5 foreach my $row (@$rows) {
547 329 my $date = splice(@$row, $dcol, 1);
548 329 $self->{results}{$mode}{$symbol}{$date} = $row;
549 }
550 }
551  
552 sub _copy_results {
553 0 ▶ my($self, $mode, $symbol, $results) = @_;
Subroutine _copy_results: not called CC=2 SCAR=17.9
554 0 foreach my $date (sort keys %$results) {
555 0 $self->{results}{$mode}{$symbol}{$date} = [@{$results->{$date}}];
556 }
557 }
558  
559 sub result_rows {
560 10 ▶ my($self, $target_mode, @symbols) = @_;
Subroutine result_rows: called CC=5 SCAR=16.2
Pod undocumented
561 10 ▶ $target_mode ||= $self->target_mode;
Condition33%1/3
$target_mode ||= $self->target_mode
l!l&&r!l&&!r
1000
MC/DC0%0/2
$target_mode ||= $self->target_mode
$target_mode $self->target_mode
Truth table33%1/3
A ||= B
A= $target_modeB= $self->target_mode
ABresult
1X1
011
000
562 10 ▶ @symbols = $self->result_symbols($target_mode) unless @symbols;
Branch: 1 branch
BranchTrueFalseTotal
unless @symbols 5 5 10
563 10 my @rows;
564 10 foreach my $symbol (@symbols) {
565 10 my $results = $self->results($target_mode, $symbol);
566 10 foreach my $date (sort keys %$results) {
567 329 push(@rows, [$symbol, $date, @{$results->{$date}}]);
568 }
569 }
570 10 sort { $a->[1] cmp $b->[1] } @rows;
571 }
572  
573 sub _store_empty_fetches {
574 5 ▶ my $self = shift;
Subroutine _store_empty_fetches: called CC=2 SCAR=7.0
575 5 ▶ my $ref = shift || [];
Condition50%1/2
shift() || []
l!l
50
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
576 5 @$ref = sort @$ref;
577 5 $self->{empty_fetches} = $ref;
578 }
579  
580 sub empty_fetches {
581 0 ▶ my $self = shift;
Subroutine empty_fetches: not called CC=2 SCAR=17.9
Pod undocumented
582 0 ▶ return () unless $self->{empty_fetches};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"empty_fetches"} 0 0 0
583 0 @{$self->{empty_fetches}}
584 }
585  
586 5 ▶sub extractors { () }
Subroutine extractors: called CC=1 SCAR=0.0
Pod documented
587  
588 sub rows {
589 5 ▶ my($self, $rows) = @_;
Subroutine rows: called CC=17 SCAR=31.3
Pod undocumented
590 5 ▶ return wantarray ? () : [] unless $rows;
Branch: 2 branches
BranchTrueFalseTotal
unless $rows 0 5 5
wantarray ? : 0 0 0
591 5 my $rc = @$rows;
592 5 ▶ print STDERR "Got $rc raw rows\n" if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 5 5
593  
594 # Load user filter if present
595 5 my $row_filter = $self->row_filter;
596  
597 # Prep the rows
598 5 foreach my $row (@$rows) {
599 332 ▶ $row_filter->($row) if $row_filter;
Branch: 1 branch
BranchTrueFalseTotal
if $row_filter 0 332 332
600 332 foreach (@$row) {
601 # Zap leading and trailing white space
602 1927 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 1927 1927
603 1927 s/^\s+//; s/\s+$//;
604 }
605 }
606 # Pass only rows with a valid date that is in range (and store the
607 # processed value while we are at it)
608 5 my $target_mode = $self->target_mode;
609 5 my @date_rows;
610 5 my $dcol = $self->label_column('date');
611 5 ▶ my $tcol = $self->label_column('time') if $target_mode eq 'intraday';
Branch: 1 branch
BranchTrueFalseTotal
if $target_mode eq "intraday" 0 5 5
612 5 my $r;
613 5 ▶ while($r = pop @$rows) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r = pop @$rows) 332 5 337
614 332 my $date = $r->[$dcol];
615 332 ▶ if ($target_mode eq 'intraday') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_mode eq "intraday") 0 332 332
616 0 my $time = splice(@$r, $tcol, 1);
617 0 $date = join('', $date, $time);
618 }
619 332 $date = $self->date_normalize($date);
620 332 ▶ unless ($date) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($date) 3 329 332
621 3 ▶ print STDERR "Reject row (no date): '$r->[$dcol]'\n" if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 3 3
622 3 next;
623 }
624 329 ▶ next unless $self->date_in_range($date);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->date_in_range($date) 0 329 329
625 329 $r->[$dcol] = $date;
626 329 push(@date_rows, $r);
627 }
628  
629 print STDERR "Trimmed to ", scalar @date_rows, " applicable date rows\n"
630 5 ▶ if $self->{verbose} && @date_rows != $rc;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} and @date_rows != $rc 0 5 5
Condition33%1/3
$self->{"verbose"} and @date_rows != $rc
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"verbose"} and @date_rows != $rc
$self->{"verbose"} @date_rows != $rc
Truth table33%1/3
A and B
A= $self->{"verbose"}B= @date_rows != $rc
ABresult
0X0
100
111
631  
632 5 ▶ return wantarray ? @date_rows : \@date_rows;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 5 5
633 }
634  
635 ### Adjustment triggers and manipulation
636  
637 sub adjuster {
638 # In order to be an adjuster, it must first be enabled. In addition,
639 # there has to be a column specified as the adjusted value. This is
640 # not as generic as I would like it, but so far it's just for
641 # Yahoo...it should work for any site with "adj" in the column
642 # label...this column should be the adjusted closing value.
643 3 ▶ my $self = shift;
Subroutine adjuster: called CC=4 SCAR=14.3
Pod undocumented
644 3 ▶ return 0 if !$self->{adjusted};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"adjusted"} 0 3 3
645 3 foreach ($self->labels) {
646 18 ▶ return 1 if /adj/i;
Branch: 1 branch
BranchTrueFalseTotal
if /adj/i 0 18 18
647 }
648 3 0;
649 }
650  
651 0 ▶sub adjusted { shift->{adjusted} ? 1 : 0 }
Subroutine adjusted: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'adjusted'} ? : 0 0 0
652  
653 ### Bulk manipulation filters
654  
655 sub date_normalize_rows {
656 # Place dates into a consistent format, courtesy of Date::Manip
657 0 ▶ my($self, $rows, $dcol) = @_;
Subroutine date_normalize_rows: not called CC=3 SCAR=24.8
Pod undocumented
658 0 ▶ $dcol = $self->label_column('date') unless defined $dcol;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dcol 0 0 0
659 0 foreach my $row (@$rows) {
660 0 $row->[$dcol] = $self->date_normalize($row->[$dcol]);
661 }
662 0 $rows;
663 }
664  
665 sub date_normalize {
666 332 ▶ my($self, $date) = @_;
Subroutine date_normalize: called CC=9 SCAR=27.5
Pod undocumented
667 332 ▶ return unless $date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 3 329 332
668 329 my $normal_date;
669 329 ▶ if ($self->granularity =~ /^m/ && $date =~ m{^\s*(\D+)[-/]+(\d{2,})\s*$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->granularity =~ /^m/ and $date =~ m[^\s*(\D+)[-/]+(\d{2,})\s*$]) { } 0 329 329
Condition66%2/3
$self->granularity =~ /^m/ and $date =~ m[^\s*(\D+)[-/]+(\d{2,})\s*$]
!ll&&!rl&&r
316130
MC/DC0%0/2
$self->granularity =~ /^m/ and $date =~ m[^\s*(\D+)[-/]+(\d{2,})\s*$]
$self->granularity =~ /^m/ $date =~ m[^\s*(\D+)[-/]+(\d{2,})\s*$]
Truth table66%2/3
A and B
A= $self->granularity =~ /^m/B= $date =~ m[^\s*(\D+)[-/]+(\d{2,})\s*$]
ABresult
0X0
100
111
670 0 my($m, $y) = ($1, $2);
671 0 ▶ $y += 1900 if length $y == 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $y == 2 0 0 0
672 0 ▶ $normal_date = ParseDate($m =~ /^\d+$/ ? "$y/$m/01" : "$m 01 $y");
Branch: 1 branch
BranchTrueFalseTotal
$m =~ /^\d+$/ ? : 0 0 0
673 }
674 else {
675 329 ▶ if ($date =~ /^\d{10}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date =~ /^\d{10}$/) { } 329 0 329
676 329 $normal_date = ParseDateString("epoch $date");
677 }
678 else {
679 0 $normal_date = ParseDate($date);
680 }
681 }
682 329 ▶ $normal_date or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$normal_date or return undef 0 329 329
683 329 ▶ return $normal_date if $self->target_mode eq 'intraday';
Branch: 1 branch
BranchTrueFalseTotal
if $self->target_mode eq "intraday" 0 329 329
684 329 join('/', $self->ymd($normal_date));
685 }
686  
687 sub snap_start_date {
688 2 ▶ my($self, $date) = @_;
Subroutine snap_start_date: called CC=5 SCAR=16.4
Pod undocumented
689 2 my $g = $self->granularity;
690 2 ▶ if ($g =~ /^(m|w)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($g =~ /^(m|w)/i) 2 0 2
691 2 ▶ if ($1 eq 'm') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq 'm') { } 1 1 2
692 1 my($dom) = UnixDate($date, '%d') - 1;
693 1 ▶ $date = DateCalc($date, "- $dom days") if $dom;
Branch: 1 branch
BranchTrueFalseTotal
if $dom 0 1 1
694 }
695 else {
696 1 my $dow = Date_DayOfWeek(UnixDate($date, '%m', '%d', '%Y')) - 1;
697 1 ▶ $date = DateCalc($date, "- $dow days") if $dow;
Branch: 1 branch
BranchTrueFalseTotal
if $dow 1 0 1
698 }
699 }
700 2 $date;
701 }
702  
703 sub snap_end_date {
704 2 ▶ my($self, $date) = @_;
Subroutine snap_end_date: called CC=4 SCAR=13.9
Pod undocumented
705 2 my $g = $self->granularity;
706 2 ▶ if ($g =~ /^(m|w)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($g =~ /^(m|w)/i) 2 0 2
707 2 ▶ if ($1 eq 'm') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq 'm') { } 1 1 2
708 1 my($m, $y) = UnixDate($date, '%m', '%Y');
709 1 my $last = Date_DaysInMonth($m, $y);
710 1 $date = ParseDateString("$y$m$last");
711 }
712 else {
713 1 my $dow = Date_DayOfWeek(UnixDate($date, '%m', '%d', '%Y')) - 1;
714 1 ▶ $date = DateCalc($date, "+ " . (6 - $dow) . ' days')
Branch: 1 branch
BranchTrueFalseTotal
unless $dow == 6 1 0 1
715 unless $dow == 6;
716 }
717 }
718 2 $date;
719 }
720  
721 sub number_normalize_rows {
722 # Strip non-numeric noise from numeric fields
723 5 ▶ my($self, $rows, $dcol) = @_;
Subroutine number_normalize_rows: called CC=4 SCAR=13.9
Pod undocumented
724 5 ▶ $dcol = $self->label_column('date') unless defined $dcol;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dcol 5 0 5
725 # filtered rows might not have same columns
726 5 my @cols = grep($_ != $dcol, 0 .. $#{$rows->[0]});
727 5 foreach my $row (@$rows) {
728 329 s/[^\d\.]//go foreach @{$row}[@cols];
729 }
730 5 $rows;
731 }
732  
733 sub precision_normalize_rows {
734 # Round off numeric fields, if requested (%.4f by default). Volume
735 # is the exception -- we just round that into an integer. This
736 # should probably only be called for 'quote' targets because it
737 # knows details about where the numbers of interest reside.
738 3 ▶ my($self, $rows) = @_;
Subroutine precision_normalize_rows: called CC=7 SCAR=20.8
Pod undocumented
739 3 my $target_mode = $self->target_mode;
740 3 ▶ croak "precision_normalize invoked in '$target_mode' mode rather than 'quote' or 'intraday' mode.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $target_mode eq "quote" or $target_mode eq "intraday" 0 3 3
Condition33%1/3
$target_mode eq "quote" or $target_mode eq "intraday"
l!l&&r!l&&!r
300
MC/DC0%0/2
$target_mode eq "quote" or $target_mode eq "intraday"
$target_mode eq "quote" $target_mode eq "intraday"
Truth table33%1/3
A or B
A= $target_mode eq "quote"B= $target_mode eq "intraday"
ABresult
1X1
011
000
741 unless $target_mode eq 'quote' || $target_mode eq 'intraday';
742 3 my @columns;
743 3 ▶ if ($target_mode ne 'intraday') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_mode ne 'intraday') { } 3 0 3
744 3 @columns = $self->label_column(qw(open high low close));
745 3 ▶ push(@columns, $self->label_column('adj')) if $self->adjuster;
Branch: 1 branch
BranchTrueFalseTotal
if $self->adjuster 0 3 3
746 }
747 else {
748 0 @columns = $self->label_column(qw(high low close));
749 }
750 3 my $vol_col = $self->label_column($Default_Vol_Pat);
751 3 foreach my $row (@$rows) {
752 $row->[$_] = sprintf("%.$self->{quote_precision}f", $row->[$_])
753 317 foreach @columns;
754 317 $row->[$vol_col] = int $row->[$vol_col];
755 }
756 3 $rows;
757 }
758  
759 ### Single row filters
760  
761 sub is_quote_row {
762 317 ▶ my($self, $row, $dcol) = @_;
Subroutine is_quote_row: called CC=7 SCAR=20.7
Pod undocumented
763 317 ▶ ref $row or croak "Row ref required\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $row or croak("Row ref required\n") 0 317 317
764 # Skip date in first field
765 317 ▶ $dcol = $self->label_column('date') unless defined $dcol;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dcol 317 0 317
766 317 foreach (0 .. $#$row) {
767 1902 ▶ next if $_ == $dcol;
Branch: 1 branch
BranchTrueFalseTotal
if $_ == $dcol 317 1585 1902
768 1585 ▶ next if $row->[$_] =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $row->[$_] =~ /^\s*$/ 0 1585 1585
769 1585 ▶ if ($row->[$_] !~ /^\s*\$*[\d\.,]+\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($row->[$_] =~ /^\s*\$*[\d\.,]+\s*$/) 0 1585 1585
770 0 return 0;
771 }
772 }
773 317 1;
774 }
775  
776 sub row_not_seen {
777 317 ▶ my($self, $symbol, $row, $dcol) = @_;
Subroutine row_not_seen: called CC=7 SCAR=26.4
Pod undocumented
778 317 ▶ ref $row or croak "Row ref required\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $row or croak("Row ref required\n") 0 317 317
779 317 ▶ $symbol or croak "ticker symbol required\n";
Branch: 1 branch
BranchTrueFalseTotal
$symbol or croak("ticker symbol required\n") 0 317 317
780 317 my $mode = $self->target_mode;
781 317 ▶ my $res = $self->{results}{$mode} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"results"}{$mode} or return 1 0 317 317
782 317 ▶ my $mres = $res->{$symbol} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $mres = $res->{$symbol} or return 1 317 0 317
783 0 ▶ $dcol = $self->label_column('date') unless defined $dcol;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dcol 0 0 0
784 0 ▶ $mres->{$row->[$dcol]} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
$$mres{$row->[$dcol]} or return 1 0 0 0
785 0 return 0;
786 }
787  
788 sub date_in_range {
789 329 ▶ my $self = shift;
Subroutine date_in_range: called CC=6 SCAR=20.9
Pod undocumented
790 329 my $date = shift;
791 329 ▶ $date = $self->date_standardize($date) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$date = $self->date_standardize($date) or return undef 0 329 329
792 329 ▶ return 0 if $self->{start_date} && $date lt $self->{start_date};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"start_date"} and $date lt $self->{"start_date"} 0 329 329
Condition33%1/3
$self->{"start_date"} and $date lt $self->{"start_date"}
!ll&&!rl&&r
03290
MC/DC0%0/2
$self->{"start_date"} and $date lt $self->{"start_date"}
$self->{"start_date"} $date lt $self->{"start_date"}
Truth table33%1/3
A and B
A= $self->{"start_date"}B= $date lt $self->{"start_date"}
ABresult
0X0
100
111
793 329 ▶ return 0 if $self->{end_date} && $date gt $self->{end_date};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"end_date"} and $date gt $self->{"end_date"} 0 329 329
Condition33%1/3
$self->{"end_date"} and $date gt $self->{"end_date"}
!ll&&!rl&&r
03290
MC/DC0%0/2
$self->{"end_date"} and $date gt $self->{"end_date"}
$self->{"end_date"} $date gt $self->{"end_date"}
Truth table33%1/3
A and B
A= $self->{"end_date"}B= $date gt $self->{"end_date"}
ABresult
0X0
100
111
794 329 1;
795 }
796  
797 ### Label and label mapping/extraction management
798  
799 5 ▶sub default_target_mode { $Default_Target_Mode }
Subroutine default_target_mode: called CC=1 SCAR=0.0
Pod undocumented
800 16 ▶sub default_parse_mode { $Default_Parse_Mode }
Subroutine default_parse_mode: called CC=1 SCAR=0.0
Pod undocumented
801 18 ▶sub default_granularity { $Default_Granularity }
Subroutine default_granularity: called CC=1 SCAR=0.0
Pod undocumented
802  
803 sub set_label_pattern {
804 0 ▶ my $self = shift;
Subroutine set_label_pattern: not called CC=10 SCAR=47.0
Pod undocumented
805 0 my %parms = @_;
806 0 ▶ my $target_mode = $parms{target_mode} || $self->target_mode;
Condition0%0/3
$parms{'target_mode'} || $self->target_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{'target_mode'} || $self->target_mode
$parms{'target_mode'} $self->target_mode
Truth table0%0/3
A || B
A= $parms{'target_mode'}B= $self->target_mode
ABresult
1X1
011
000
807 0 ▶ my $parse_mode = $parms{parse_mode} || $self->parse_mode;
Condition0%0/3
$parms{'parse_mode'} || $self->parse_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{'parse_mode'} || $self->parse_mode
$parms{'parse_mode'} $self->parse_mode
Truth table0%0/3
A || B
A= $parms{'parse_mode'}B= $self->parse_mode
ABresult
1X1
011
000
808 0 my $label = $parms{label};
809 0 ▶ croak "Column label required\n" unless $label;
Branch: 1 branch
BranchTrueFalseTotal
unless $label 0 0 0
810 0 ▶ my $l2p = $self->{_label_pat}{$target_mode}{$parse_mode} ||= {};
Condition0%0/2
$self->{"_label_pat"}{$target_mode}{$parse_mode} ||= {}
l!l
00
MC/DC0%0/1
$self->{"_label_pat"}{$target_mode}{$parse_mode} ||= {}
$self->{"_label_pat"}{$target_mode}{$parse_mode}
Truth table0%0/2
A
A= $self->{"_label_pat"}{$target_mode}{$parse_mode}
Aresult
11
00
811 0 ▶ my $p2l = $self->{_pat_label}{$target_mode}{$parse_mode} ||= {};
Condition0%0/2
$self->{"_pat_label"}{$target_mode}{$parse_mode} ||= {}
l!l
00
MC/DC0%0/1
$self->{"_pat_label"}{$target_mode}{$parse_mode} ||= {}
$self->{"_pat_label"}{$target_mode}{$parse_mode}
Truth table0%0/2
A
A= $self->{"_pat_label"}{$target_mode}{$parse_mode}
Aresult
11
00
812 0 my $pattern = $parms{pattern};
813 0 ▶ if ($pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern) 0 0 0
814 0 $l2p->{$label} = $pattern;
815 0 delete $self->{label_map};
816 0 delete $self->{pattern_map};
817 }
818 0 ▶ my $pat = $l2p->{$label} ||= ($label =~ $Default_Vol_Pat ?
Branch: 1 branch
BranchTrueFalseTotal
$label =~ /$Default_Vol_Pat/ ? : 0 0 0
Condition0%0/3
$l2p->{$label} ||= $label =~ /$Default_Vol_Pat/ ? qr/\s*$label/i : qr/^\s*$label/i
l!l&&r!l&&!r
000
MC/DC0%0/2
$l2p->{$label} ||= $label =~ /$Default_Vol_Pat/ ? qr/\s*$label/i : qr/^\s*$label/i
$l2p->{$label} $label =~ /$Default_Vol_Pat/ ? qr/\s*$label/i : qr/^\s*$label/i
Truth table0%0/3
A ||= B
A= $l2p->{$label}B= $label =~ /$Default_Vol_Pat/ ? qr/\s*$label/i : qr/^\s*$label/i
ABresult
1X1
011
000
819 qr/\s*$label/i : qr/^\s*$label/i);
820 0 ▶ $p2l->{$pat} ||= $label;
Condition0%0/3
$p2l->{$pat} ||= $label
l!l&&r!l&&!r
000
MC/DC0%0/2
$p2l->{$pat} ||= $label
$p2l->{$pat} $label
Truth table0%0/3
A ||= B
A= $p2l->{$pat}B= $label
ABresult
1X1
011
000
821 0 $pat;
822 }
823  
824 sub label_pattern {
825 0 ▶ my $self = shift;
Subroutine label_pattern: not called CC=4 SCAR=30.0
Pod undocumented
826 0 my $target_mode = $self->target_mode;
827 0 my $parse_mode = $self->parse_mode;
828 0 my $label = shift;
829 0 ▶ croak "column label required\n" unless $label;
Branch: 1 branch
BranchTrueFalseTotal
unless $label 0 0 0
830 0 ▶ my $l2p = $self->{_label_pat}{$target_mode}{$parse_mode} ||= {};
Condition0%0/2
$self->{"_label_pat"}{$target_mode}{$parse_mode} ||= {}
l!l
00
MC/DC0%0/1
$self->{"_label_pat"}{$target_mode}{$parse_mode} ||= {}
$self->{"_label_pat"}{$target_mode}{$parse_mode}
Truth table0%0/2
A
A= $self->{"_label_pat"}{$target_mode}{$parse_mode}
Aresult
11
00
831 0 ▶ my $pat = $l2p->{$label} || $self->set_label_pattern(label => $label);
Condition0%0/3
$l2p->{$label} || $self->set_label_pattern('label', $label)
l!l&&r!l&&!r
000
MC/DC0%0/2
$l2p->{$label} || $self->set_label_pattern('label', $label)
$l2p->{$label} $self->set_label_pattern('label', $label)
Truth table0%0/3
A || B
A= $l2p->{$label}B= $self->set_label_pattern('label', $label)
ABresult
1X1
011
000
832 0 $pat;
833 }
834  
835 sub label_column {
836 341 ▶ my $self = shift;
Subroutine label_column: called CC=7 SCAR=19.5
Pod undocumented
837 341 my @cols;
838 341 ▶ if (!$self->{label_map}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"label_map"}) 8 333 341
839 8 delete $self->{pattern_map};
840 8 my @labels = $self->labels;
841 8 foreach my $i (0 .. $#labels) {
842 41 $self->{label_map}{$labels[$i]} = $i;
843 }
844 }
845 341 foreach (@_) {
846 350 ▶ croak "Unknown label '$_'\n" unless exists $self->{label_map}{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"label_map"}{$_} 0 350 350
847 350 push(@cols, $self->{label_map}{$_});
848 }
849 341 ▶ unless (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 338 3 341
850 338 ▶ croak "multiple columns in scalar context\n" if @cols > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @cols > 1 0 338 338
851 338 return $cols[0];
852 }
853 3 @cols;
854 }
855  
856 sub pattern_column {
857 0 ▶ my $self = shift;
Subroutine pattern_column: not called CC=5 SCAR=34.0
Pod undocumented
858 0 ▶ if (!$self->{pattern_map}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"pattern_map"}) 0 0 0
859 0 my @patterns = $self->patterns;
860 0 foreach my $i (0 .. $#patterns) {
861 0 $self->{pattern_map}{$patterns[$i]} = $i;
862 }
863 }
864 0 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
865 0 my $pattern = shift;
866 0 ▶ croak "Unknown pattern '$pattern'\n" unless $self->{_pat_map}{$pattern};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_pat_map"}{$pattern} 0 0 0
867 0 $self->{pattern_map{$pattern}};
868 }
869  
870 sub pattern_map {
871 0 ▶ my $self = shift;
Subroutine pattern_map: not called CC=2 SCAR=17.9
Pod undocumented
872 0 ▶ $self->pattern_column unless $self->{pattern_map};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"pattern_map"} 0 0 0
873 0 $self->{pattern_map};
874 }
875  
876 sub label_map {
877 0 ▶ my $self = shift;
Subroutine label_map: not called CC=2 SCAR=17.9
Pod undocumented
878 0 ▶ $self->label_column unless $self->{label_map};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"label_map"} 0 0 0
879 0 $self->{label_map};
880 }
881  
882 sub pattern_label {
883 0 ▶ my $self = shift;
Subroutine pattern_label: not called CC=7 SCAR=40.3
Pod undocumented
884 0 my %parms = @_;
885 0 ▶ my $target_mode = $parms{target_mode} || $self->target_mode;
Condition0%0/3
$parms{'target_mode'} || $self->target_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{'target_mode'} || $self->target_mode
$parms{'target_mode'} $self->target_mode
Truth table0%0/3
A || B
A= $parms{'target_mode'}B= $self->target_mode
ABresult
1X1
011
000
886 0 ▶ my $parse_mode = $parms{parse_mode} || $self->parse_mode;
Condition0%0/3
$parms{'parse_mode'} || $self->parse_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{'parse_mode'} || $self->parse_mode
$parms{'parse_mode'} $self->parse_mode
Truth table0%0/3
A || B
A= $parms{'parse_mode'}B= $self->parse_mode
ABresult
1X1
011
000
887 0 ▶ my $pat = $parms{pattern} or croak "pattern required for label lookup\n";
Branch: 1 branch
BranchTrueFalseTotal
my $pat = $parms{"pattern"} or croak("pattern required for label lookup\n") 0 0 0
888 0 ▶ my $p2l = $self->{_pat_label}{$target_mode}{$parse_mode} ||= {};
Condition0%0/2
$self->{"_pat_label"}{$target_mode}{$parse_mode} ||= {}
l!l
00
MC/DC0%0/1
$self->{"_pat_label"}{$target_mode}{$parse_mode} ||= {}
$self->{"_pat_label"}{$target_mode}{$parse_mode}
Truth table0%0/2
A
A= $self->{"_pat_label"}{$target_mode}{$parse_mode}
Aresult
11
00
889 0 my $label = $p2l->{$pat};
890 0 ▶ unless (defined $label) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $label) 0 0 0
891 0 delete $parms{pattern};
892 0 $self->set_label_pattern(%parms, label => $_) foreach $self->labels;
893 }
894 0 $label;
895 }
896  
897 sub patterns {
898 0 ▶ my $self = shift;
Subroutine patterns: not called CC=3 SCAR=24.8
Pod undocumented
899 0 my %parms = @_;
900 0 ▶ $parms{target_mode} ||= $self->target_mode;
Condition0%0/3
$parms{"target_mode"} ||= $self->target_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{"target_mode"} ||= $self->target_mode
$parms{"target_mode"} $self->target_mode
Truth table0%0/3
A ||= B
A= $parms{"target_mode"}B= $self->target_mode
ABresult
1X1
011
000
901 0 ▶ $parms{parse_mode} ||= $self->parse_mode;
Condition0%0/3
$parms{"parse_mode"} ||= $self->parse_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{"parse_mode"} ||= $self->parse_mode
$parms{"parse_mode"} $self->parse_mode
Truth table0%0/3
A ||= B
A= $parms{"parse_mode"}B= $self->parse_mode
ABresult
1X1
011
000
902 0 map($self->label_pattern($_), $self->labels(%parms));
903 }
904  
905 sub columns {
906 0 ▶ my $self = shift;
Subroutine columns: not called CC=3 SCAR=24.8
Pod undocumented
907 0 my %parms = @_;
908 0 ▶ $parms{target_mode} ||= $self->target_mode;
Condition0%0/3
$parms{"target_mode"} ||= $self->target_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{"target_mode"} ||= $self->target_mode
$parms{"target_mode"} $self->target_mode
Truth table0%0/3
A ||= B
A= $parms{"target_mode"}B= $self->target_mode
ABresult
1X1
011
000
909 0 ▶ $parms{parse_mode} ||= $self->parse_mode;
Condition0%0/3
$parms{"parse_mode"} ||= $self->parse_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{"parse_mode"} ||= $self->parse_mode
$parms{"parse_mode"} $self->parse_mode
Truth table0%0/3
A ||= B
A= $parms{"parse_mode"}B= $self->parse_mode
ABresult
1X1
011
000
910 0 $self->label_column($self->labels(%parms));
911 }
912  
913 sub default_labels {
914 16 ▶ my $self = shift;
Subroutine default_labels: called CC=5 SCAR=17.8
Pod undocumented
915 16 my %parms = @_;
916 16 ▶ my $target_mode = $parms{target_mode} || $self->target_mode;
Condition33%1/3
$parms{'target_mode'} || $self->target_mode
l!l&&r!l&&!r
1600
MC/DC0%0/2
$parms{'target_mode'} || $self->target_mode
$parms{'target_mode'} $self->target_mode
Truth table33%1/3
A || B
A= $parms{'target_mode'}B= $self->target_mode
ABresult
1X1
011
000
917 16 my $tm = $Default_Labels{$target_mode};
918 16 ▶ unless ($tm) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tm) 0 16 16
919 0 $tm = $Default_Labels{$self->default_target_mode};
920 }
921 16 ▶ my $parse_mode = $parms{parse_mode} || $self->parse_mode;
Condition33%1/3
$parms{'parse_mode'} || $self->parse_mode
l!l&&r!l&&!r
1600
MC/DC0%0/2
$parms{'parse_mode'} || $self->parse_mode
$parms{'parse_mode'} $self->parse_mode
Truth table33%1/3
A || B
A= $parms{'parse_mode'}B= $self->parse_mode
ABresult
1X1
011
000
922 16 my $labels = $tm->{$parse_mode};
923 16 ▶ unless ($labels) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($labels) 16 0 16
924 16 $labels = $tm->{$self->default_parse_mode};
925 }
926 16 @$labels;
927 }
928  
929 sub labels {
930 16 ▶ my $self = shift;
Subroutine labels: called CC=7 SCAR=20.7
Pod documented
931 16 my %parms = @_;
932 16 ▶ my $target_mode = $parms{target_mode} || $self->target_mode;
Condition66%2/3
$parms{'target_mode'} || $self->target_mode
l!l&&r!l&&!r
5110
MC/DC0%0/2
$parms{'target_mode'} || $self->target_mode
$parms{'target_mode'} $self->target_mode
Truth table66%2/3
A || B
A= $parms{'target_mode'}B= $self->target_mode
ABresult
1X1
011
000
933 16 ▶ my $parse_mode = $parms{parse_mode} || $self->parse_mode;
Condition66%2/3
$parms{'parse_mode'} || $self->parse_mode
l!l&&r!l&&!r
5110
MC/DC0%0/2
$parms{'parse_mode'} || $self->parse_mode
$parms{'parse_mode'} $self->parse_mode
Truth table66%2/3
A || B
A= $parms{'parse_mode'}B= $self->parse_mode
ABresult
1X1
011
000
934 16 my $tm = $self->{_labels}{$target_mode};
935 16 ▶ if ($parms{labels} || ! $tm->{$parse_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parms{"labels"} or not $tm->{$parse_mode}) 16 0 16
Condition33%1/3
$parms{"labels"} or not $tm->{$parse_mode}
l!l&&r!l&&!r
0160
MC/DC0%0/2
$parms{"labels"} or not $tm->{$parse_mode}
$parms{"labels"} not $tm->{$parse_mode}
Truth table33%1/3
A or not(B)
A= $parms{"labels"}B= not $tm->{$parse_mode}
ABresult
1X1
011
000
936 16 delete $self->{label_map};
937 16 delete $self->{pattern_map};
938 }
939 16 ▶ $tm->{$parse_mode} = $parms{labels} if $parms{labels};
Branch: 1 branch
BranchTrueFalseTotal
if $parms{"labels"} 0 16 16
940 16 ▶ my $labels = $tm->{$parse_mode} ||= [$self->default_labels(
Condition50%1/2
$tm->{$parse_mode} ||= [$self->default_labels("target_mode", $target_mode, "parse_mode", $parse_mode)]
l!l
016
MC/DC0%0/1
$tm->{$parse_mode} ||= [$self->default_labels("target_mode", $target_mode, "parse_mode", $parse_mode)]
$tm->{$parse_mode}
Truth table50%1/2
A
A= $tm->{$parse_mode}
Aresult
11
00
941 target_mode => $target_mode,
942 parse_mode => $parse_mode)];
943 16 @$labels;
944 }
945  
946 sub parse_mode {
947 41 ▶ my $self = shift;
Subroutine parse_mode: called CC=3 SCAR=11.0
Pod documented
948 41 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 10 31 41
949 10 $self->{parse_mode} = shift;
950 }
951 41 ▶ $self->{parse_mode} || $self->default_parse_mode;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"parse_mode"} or $self->default_parse_mode 0 41 41
952 }
953  
954 sub target_mode {
955 690 ▶ my $self = shift;
Subroutine target_mode: called CC=3 SCAR=11.0
Pod documented
956 690 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 15 675 690
957 15 $self->{target_mode} = shift;
958 }
959 690 ▶ $self->{target_mode} || $self->default_target_mode;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"target_mode"} or $self->default_target_mode 5 685 690
960 }
961  
962 sub granularity {
963 348 ▶ my $self = shift;
Subroutine granularity: called CC=3 SCAR=11.4
Pod documented
964 348 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 348 348
965 0 $self->{granularity} = shift;
966 }
967 348 ▶ $self->{granularity} || $self->default_granularity;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"granularity"} or $self->default_granularity 18 330 348
968 }
969  
970 sub lineup {
971 0 ▶ my $self = shift;
Subroutine lineup: not called CC=3 SCAR=24.8
Pod documented
972 0 ▶ $self->{lineup} = \@_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
973 0 ▶ return unless $self->{lineup};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lineup"} 0 0 0
974 0 @{$self->{lineup}};
975 }
976  
977 ### Parser methods
978  
979 sub pre_parser {
980 5 ▶ my($self, %parms) = @_;
Subroutine pre_parser: called CC=3 SCAR=12.7
Pod undocumented
981 5 ▶ my $parse_mode = $parms{parse_mode} || $self->parse_mode;
Condition33%1/3
$parms{'parse_mode'} || $self->parse_mode
l!l&&r!l&&!r
050
MC/DC0%0/2
$parms{'parse_mode'} || $self->parse_mode
$parms{'parse_mode'} $self->parse_mode
Truth table33%1/3
A || B
A= $parms{'parse_mode'}B= $self->parse_mode
ABresult
1X1
011
000
982 5 my $method = "${parse_mode}_pre_parser";
983 5 ▶ return unless $self->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($method) 5 0 5
984 0 $self->$method(%parms, parse_mode => $parse_mode);
985 }
986  
987 sub parser {
988 5 ▶ my($self, %parms) = @_;
Subroutine parser: called CC=2 SCAR=7.4
Pod undocumented
989 5 ▶ my $parse_mode = $parms{parse_mode} || $self->parse_mode;
Condition33%1/3
$parms{'parse_mode'} || $self->parse_mode
l!l&&r!l&&!r
050
MC/DC0%0/2
$parms{'parse_mode'} || $self->parse_mode
$parms{'parse_mode'} $self->parse_mode
Truth table33%1/3
A || B
A= $parms{'parse_mode'}B= $self->parse_mode
ABresult
1X1
011
000
990 5 my $make_parser = "${parse_mode}_parser";
991 5 $self->$make_parser(%parms, parse_mode => $parse_mode);
992 }
993  
994 sub html_parser {
995 # HTML::TableExtract supports automatic column reordering.
996 0 ▶ my $self = shift;
Subroutine html_parser: not called CC=3 SCAR=24.8
Pod undocumented
997 0 my $class = HTML_CLASS;
998 0 my @labels = $self->labels(@_);
999 0 my @patterns = $self->patterns(@_);
1000 0 my(%pat_map, %label_map);
1001 0 $pat_map{$patterns[$_]} = $_ foreach 0 .. $#patterns;
1002 0 $label_map{$labels[$_]} = $_ foreach 0 .. $#labels;
1003 0 $self->pattern_map(\%pat_map);
1004 0 $self->label_map(\%label_map);
1005 sub {
1006 0 ▶ my $data = shift;
Subroutine __ANON__: not called CC=5 SCAR=34.0
1007 0 my $html_string;
1008 0 ▶ if (ref $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data) { } 0 0 0
1009 0 local($/);
1010 0 $html_string = <$data>;
1011 }
1012 else {
1013 0 $html_string = $data;
1014 }
1015 0 my %te_parms = (
1016 headers => \@patterns,
1017 automap => 1,
1018 );
1019 0 ▶ $te_parms{debug} = $self->{debug} if $self->{debug} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} > 2 0 0 0
1020 0 ▶ my $te = $class->new(%te_parms) or croak "Problem creating $class\n";
Branch: 1 branch
BranchTrueFalseTotal
my $te = $class->new(%te_parms) or croak("Problem creating $class\n") 0 0 0
1021 0 $te->parse($html_string);
1022 0 $te->eof;
1023 0 my $ts = $te->first_table_found;
1024 0 ▶ [ $ts ? $ts->rows() : ()];
Branch: 1 branch
BranchTrueFalseTotal
$ts ? : 0 0 0
1025 }
1026 0 }
1027  
1028 sub csv_parser {
1029 # Text::CSV_XS doesn't column slice or re-order, so we do.
1030 0 ▶ my $self = shift;
Subroutine csv_parser: not called CC=1 SCAR=6.9
Pod undocumented
1031 0 my @patterns = $self->patterns(@_);
1032 sub {
1033 0 ▶ my $data = shift;
Subroutine __ANON__: not called CC=22 SCAR=62.3
1034 0 ▶ return [] unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
1035 0 ▶ my @csv_lines = ref $data ? <$data> : split("\n", $data);
Branch: 1 branch
BranchTrueFalseTotal
ref $data ? : 0 0 0
1036 # BOM squad (byte order mark, as csv from google tends to be)
1037 0 ▶ if ($csv_lines[0] =~ s/^\xEF\xBB\xBF//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($csv_lines[0] =~ s/^\xEF\xBB\xBF//) 0 0 0
1038 0 for my $i (0 .. $#csv_lines) {
1039 0 utf8::decode($csv_lines[$i]);
1040 }
1041 }
1042 # might be unix, windows, or mac style newlines
1043 0 s/\s+$// foreach @csv_lines;
1044 0 ▶ return [] if !@csv_lines || $csv_lines[0] =~ /(no data)|error/i;
Branch: 1 branch
BranchTrueFalseTotal
if not @csv_lines or $csv_lines[0] =~ /(no data)|error/i 0 0 0
Condition0%0/3
not @csv_lines or $csv_lines[0] =~ /(no data)|error/i
l!l&&r!l&&!r
000
MC/DC0%0/2
not @csv_lines or $csv_lines[0] =~ /(no data)|error/i
not @csv_lines $csv_lines[0] =~ /(no data)|error/i
Truth table0%0/3
not(A) or B
A= not @csv_linesB= $csv_lines[0] =~ /(no data)|error/i
ABresult
1X1
011
000
1045 # attempt to get rid of comments at front of csv data
1046 0 ▶ while (@csv_lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@csv_lines) 0 0 0
1047 0 ▶ last if $csv_lines[0] =~ /date/i || $csv_lines[0] =~ /\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $csv_lines[0] =~ /date/i or $csv_lines[0] =~ /\d+$/ 0 0 0
Condition0%0/3
$csv_lines[0] =~ /date/i or $csv_lines[0] =~ /\d+$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$csv_lines[0] =~ /date/i or $csv_lines[0] =~ /\d+$/
$csv_lines[0] =~ /date/i $csv_lines[0] =~ /\d+$/
Truth table0%0/3
A or B
A= $csv_lines[0] =~ /date/iB= $csv_lines[0] =~ /\d+$/
ABresult
1X1
011
000
1048 0 ▶ print STDERR "CSV reject line: $csv_lines[0]\n" if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
1049 0 shift @csv_lines;
1050 }
1051 0 my $first_line = $csv_lines[0];
1052 0 ▶ my $sep_char = $first_line =~ /date\s*(\S)/i ? $1 : ',';
Branch: 1 branch
BranchTrueFalseTotal
$first_line =~ /date\s*(\S)/i ? : 0 0 0
1053 0 ▶ my $cp = $CSV_Class->new({sep_char => $sep_char, binary => 1})
Branch: 1 branch
BranchTrueFalseTotal
my $cp = $CSV_Class->new({"sep_char", $sep_char, "binary", 1}) or croak("Problem creating $CSV_Class\n") 0 0 0
1054 or croak "Problem creating $CSV_Class\n";
1055 0 my @pat_slice;
1056 0 ▶ if ($first_line =~ /date/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_line =~ /date/i) { } 0 0 0
1057 # derive column detection and ordering
1058 0 ▶ $cp->parse($first_line) or croak ("Problem parsing (" .
Branch: 1 branch
BranchTrueFalseTotal
$cp->parse($first_line) or croak('Problem parsing (' . $cp->error_input . ') : ' . $cp->error_diag . "\n") 0 0 0
1059 $cp->error_input . ") : " . $cp->error_diag . "\n");
1060 0 my @headers = $cp->fields;
1061 0 my @pats = @patterns;
1062 0 my @labels = map($self->pattern_label(pattern => $_), @patterns);
1063 0 my(%pat_map, %label_map);
1064 0 HEADER: for my $i (0 .. $#headers) {
1065 0 ▶ last unless @pats;
Branch: 1 branch
BranchTrueFalseTotal
unless @pats 0 0 0
1066 0 my $header = $headers[$i];
1067 0 for my $pi (0 .. $#pats) {
1068 0 my $pat = $pats[$pi];
1069 0 ▶ if ($header =~ /$pat/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header =~ /$pat/) 0 0 0
1070 0 my $label = $labels[$pi];
1071 0 splice(@pats, $pi, 1);
1072 0 splice(@labels, $pi, 1);
1073 0 $pat_map{$pat} = $i;
1074 0 $label_map{$label} = $i;
1075 0 next HEADER;
1076 }
1077 }
1078 }
1079 0 shift @csv_lines;
1080 0 @pat_slice = map($pat_map{$_}, @patterns);
1081 }
1082 else {
1083 # no header row, trust natural order and presence
1084 0 @pat_slice = 0 .. $#patterns;
1085 }
1086 0 my @rows;
1087 0 foreach my $line (@csv_lines) {
1088 0 ▶ $cp->parse($line) or next;
Branch: 1 branch
BranchTrueFalseTotal
$cp->parse($line) or next 0 0 0
1089 0 my @fields = $cp->fields;
1090 0 push(@rows, [@fields[@pat_slice]]);
1091 }
1092 0 \@rows;
1093 0 };
1094 }
1095  
1096 ### Accessors, generators
1097  
1098 sub start_date {
1099 15 ▶ my $self = shift;
Subroutine start_date: called CC=5 SCAR=16.5
Pod documented
1100 15 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 10 15
1101 5 my $start_date = shift;
1102 5 ▶ my $clear = @_ ? shift : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 5 5
1103 5 ▶ $self->clear_cache if $clear;
Branch: 1 branch
BranchTrueFalseTotal
if $clear 5 0 5
1104 5 ▶ $self->{start_date} = defined $start_date ?
Branch: 1 branch
BranchTrueFalseTotal
defined $start_date ? : 5 0 5
1105 $self->date_standardize($start_date) : undef;
1106 }
1107 15 $self->{start_date};
1108 }
1109  
1110 sub end_date {
1111 15 ▶ my $self = shift;
Subroutine end_date: called CC=5 SCAR=16.5
Pod documented
1112 15 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 10 15
1113 5 my $end_date = shift;
1114 5 ▶ my $clear = @_ ? shift : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 5 5
1115 5 ▶ $self->clear_cache if $clear;
Branch: 1 branch
BranchTrueFalseTotal
if $clear 5 0 5
1116 5 ▶ $self->{end_date} = defined $end_date ?
Branch: 1 branch
BranchTrueFalseTotal
defined $end_date ? : 5 0 5
1117 $self->date_standardize($end_date) : undef;
1118 }
1119 15 $self->{end_date};
1120 }
1121  
1122 sub date_standardize {
1123 349 ▶ my($self, @dates) = @_;
Subroutine date_standardize: called CC=5 SCAR=16.8
Pod undocumented
1124 349 ▶ return unless @dates;
Branch: 1 branch
BranchTrueFalseTotal
unless @dates 0 349 349
1125 349 foreach (@dates) {
1126 349 ▶ $_ = ParseDate($_) or Carp::confess "Could not parse date '$_'\n";
Branch: 1 branch
BranchTrueFalseTotal
$_ = ParseDate($_) or Carp::confess("Could not parse date '${_}'\n") 0 349 349
1127 349 s/\d\d:.*//;
1128 }
1129 349 ▶ @dates > 1 ? @dates : ($dates[0]);
Branch: 1 branch
BranchTrueFalseTotal
@dates > 1 ? : 0 349 349
1130 }
1131  
1132 sub mydates {
1133 0 ▶ my $self = shift;
Subroutine mydates: not called CC=1 SCAR=6.9
Pod undocumented
1134 0 $self->dates($self->{start_date}, $self->{end_date});
1135 }
1136  
1137 sub dates {
1138 0 ▶ my($self, $sdate, $edate) = @_;
Subroutine dates: not called CC=5 SCAR=34.0
Pod documented
1139 0 ▶ $sdate && $edate or croak "Start date and end date strings required\n";
Branch: 1 branch
BranchTrueFalseTotal
$sdate and $edate or croak("Start date and end date strings required\n") 0 0 0
Condition0%0/3
$sdate and $edate
!ll&&!rl&&r
000
MC/DC0%0/2
$sdate and $edate
$sdate $edate
Truth table0%0/3
A and B
A= $sdateB= $edate
ABresult
0X0
100
111
1140 0 my($sd, $ed) = sort($self->date_standardize($sdate, $edate));
1141 0 my @dates;
1142 0 ▶ push(@dates, $sd) if Date_IsWorkDay($sd);
Branch: 1 branch
BranchTrueFalseTotal
if Date_IsWorkDay($sd) 0 0 0
1143 0 my $cd = $self->date_standardize(Date_NextWorkDay($sd, 1));
1144 0 ▶ while ($cd <= $ed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd <= $ed) 0 0 0
1145 0 push(@dates, $cd);
1146 0 $cd = $self->date_standardize(Date_NextWorkDay($cd));
1147 }
1148 0 @dates;
1149 }
1150  
1151 sub symbols {
1152 10 ▶ my($self, @symbols) = @_;
Subroutine symbols: called CC=2 SCAR=6.9
Pod documented
1153 10 ▶ if (@symbols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@symbols) 5 5 10
1154 5 my %seen;
1155 5 grep(++$seen{$_}, grep(uc $_, @symbols));
1156 5 $self->{symbols} = [sort keys %seen];
1157 5 $self->clear_cache;
1158 }
1159 10 @{$self->{symbols}};
1160 }
1161  
1162 sub successors {
1163 0 ▶ my $self = shift;
Subroutine successors: not called CC=1 SCAR=6.9
Pod undocumented
1164 0 @{$self->{successors}};
1165 }
1166  
1167 sub clear_cache {
1168 15 ▶ my $self = shift;
Subroutine clear_cache: called CC=1 SCAR=0.0
Pod documented
1169 15 delete $self->{url_cache};
1170 15 delete $self->{results};
1171 15 1;
1172 }
1173  
1174 sub result_modes {
1175 0 ▶ my $self = shift;
Subroutine result_modes: not called CC=2 SCAR=17.9
Pod undocumented
1176 0 ▶ return () unless $self->{results};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"results"} 0 0 0
1177 0 sort keys %{$self->{results}};
1178 }
1179  
1180 sub result_symbols {
1181 5 ▶ my($self, $target_mode) = @_;
Subroutine result_symbols: called CC=3 SCAR=11.8
Pod undocumented
1182 5 ▶ $target_mode ||= $self->target_mode;
Condition33%1/3
$target_mode ||= $self->target_mode
l!l&&r!l&&!r
500
MC/DC0%0/2
$target_mode ||= $self->target_mode
$target_mode $self->target_mode
Truth table33%1/3
A ||= B
A= $target_modeB= $self->target_mode
ABresult
1X1
011
000
1183 5 ▶ return () unless $self->{sources}{$target_mode};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sources"}{$target_mode} 0 5 5
1184 5 sort keys %{$self->{results}{$target_mode}};
1185 }
1186  
1187 sub results {
1188 10 ▶ my($self, $target_mode, $symbol) = @_;
Subroutine results: called CC=1 SCAR=0.0
Pod undocumented
1189 10 $self->{results}{$target_mode}{$symbol};
1190 }
1191  
1192 0 ▶sub quote_source { shift->source(shift, 'quote') }
Subroutine quote_source: not called CC=1 SCAR=6.9
Pod documented
1193 0 ▶sub dividend_source { shift->source(shift, 'dividend') }
Subroutine dividend_source: not called CC=1 SCAR=6.9
Pod documented
1194 0 ▶sub split_source { shift->source(shift, 'split') }
Subroutine split_source: not called CC=1 SCAR=6.9
Pod documented
1195 0 ▶sub intraday_source { shift->source(shift, 'intraday') }
Subroutine intraday_source: not called CC=1 SCAR=6.9
Pod undocumented
1196  
1197 5 ▶sub row_filter { shift->{row_filter} }
Subroutine row_filter: called CC=1 SCAR=0.0
Pod documented
1198  
1199 sub source {
1200 0 ▶ my($self, $symbol, $target_mode) = @_;
Subroutine source: not called CC=4 SCAR=30.0
Pod undocumented
1201 0 ▶ croak "Ticker symbol required\n" unless $symbol;
Branch: 1 branch
BranchTrueFalseTotal
unless $symbol 0 0 0
1202 0 ▶ $target_mode ||= $self->target_mode;
Condition0%0/3
$target_mode ||= $self->target_mode
l!l&&r!l&&!r
000
MC/DC0%0/2
$target_mode ||= $self->target_mode
$target_mode $self->target_mode
Truth table0%0/3
A ||= B
A= $target_modeB= $self->target_mode
ABresult
1X1
011
000
1203 0 ▶ $self->{sources}{$target_mode}{$symbol} || '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{"sources"}{$target_mode}{$symbol} or "" 0 0 0
1204 }
1205  
1206 sub _target_source {
1207 5 ▶ my($self, $target_mode, $symbol, $source) = @_;
Subroutine _target_source: called CC=4 SCAR=14.3
1208 5 ▶ croak "Target mode required\n" unless $target_mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $target_mode 0 5 5
1209 5 ▶ croak "Ticker symbol required\n" unless $symbol;
Branch: 1 branch
BranchTrueFalseTotal
unless $symbol 0 5 5
1210 5 $symbol = uc $symbol;
1211 5 ▶ if ($source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source) 5 0 5
1212 5 $self->{sources}{$target_mode}{$symbol} = $source;
1213 }
1214 5 $self->{sources}{$target_mode}{$symbol};
1215 }
1216  
1217 ###
1218  
1219 sub _summon_champion {
1220 # Instantiate the next class in line if this class failed in
1221 # fetching any quotes. Make sure and pass along the remaining
1222 # champions to the new champion.
1223 0 ▶ my($self, $champion_class, @bad_symbols) = @_;
Subroutine _summon_champion: not called CC=5 SCAR=34.0
1224 0 ▶ return undef unless ref $self->{lineup} && @{$self->{lineup}};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"lineup"} and @{$self->{"lineup"};} 0 0 0
Condition0%0/3
ref $self->{"lineup"} and @{$self->{"lineup"};}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{"lineup"} and @{$self->{"lineup"};}
ref $self->{"lineup"} @{$self->{"lineup"};}
Truth table0%0/3
A and B
A= ref $self->{"lineup"}B= @{$self->{"lineup"};}
ABresult
0X0
100
111
1225 0 ▶ print STDERR "Loading $champion_class\n" if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
1226 0 eval "require $champion_class;";
1227 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1228 my $champion = $champion_class->new
1229 (
1230 symbols => [@bad_symbols],
1231 start_date => $self->{start_date},
1232 end_date => $self->{end_date},
1233 adjusted => $self->{adjusted},
1234 verbose => $self->{verbose},
1235 0 lineup => [],
1236 );
1237 0 $champion;
1238 }
1239  
1240 ### Toolbox
1241  
1242 0 ▶sub save_query { shift->_save_restore_query(1) }
Subroutine save_query: not called CC=1 SCAR=6.9
Pod undocumented
1243 0 ▶sub restore_query { shift->_save_restore_query(0) }
Subroutine restore_query: not called CC=1 SCAR=6.9
Pod undocumented
1244 sub _save_restore_query {
1245 0 ▶ my($self, $save) = @_;
Subroutine _save_restore_query: not called CC=5 SCAR=34.0
1246 0 ▶ $save = 1 unless defined $save;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $save 0 0 0
1247 0 foreach (qw(parse_mode target_mode start_date end_date granularity quiet)) {
1248 0 my $qstr = "_query_$_";
1249 0 ▶ if ($save) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save) { } 0 0 0
1250 0 $self->{$qstr} = $self->{$_};
1251 }
1252 else {
1253 0 ▶ $self->{$_} = $self->{$qstr} if exists $self->{$qstr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$qstr} 0 0 0
1254 }
1255 }
1256 0 $self;
1257 }
1258  
1259 sub ymd {
1260 349 ▶ my $self = shift;
Subroutine ymd: called CC=1 SCAR=0.0
Pod undocumented
1261 349 my @res = $_[0] =~ /^\s*(\d{4})(\d{2})(\d{2})/o;
1262 349 shift =~ /^\s*(\d{4})(\d{2})(\d{2})/o;
1263 }
1264  
1265 sub date_iterator {
1266 0 ▶ my $self = shift;
Subroutine date_iterator: not called CC=9 SCAR=45.0
Pod undocumented
1267 0 my %parms = @_;
1268 0 my $start_date = $parms{start_date};
1269 0 ▶ my $end_date = $parms{end_date} || 'today';
Condition0%0/2
$parms{'end_date'} || 'today'
l!l
00
MC/DC0%0/1
$parms{'end_date'} || 'today'
$parms{'end_date'}
Truth table0%0/2
A
A= $parms{'end_date'}
Aresult
11
00
1270 0 my $increment = $parms{increment};
1271 0 ▶ my $units = $parms{units} || 'days';
Condition0%0/2
$parms{'units'} || 'days'
l!l
00
MC/DC0%0/1
$parms{'units'} || 'days'
$parms{'units'}
Truth table0%0/2
A
A= $parms{'units'}
Aresult
11
00
1272 0 ▶ $increment && $increment > 0 or croak "Increment > 0 required\n";
Branch: 1 branch
BranchTrueFalseTotal
$increment and $increment > 0 or croak("Increment > 0 required\n") 0 0 0
Condition0%0/3
$increment and $increment > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$increment and $increment > 0
$increment $increment > 0
Truth table0%0/3
A and B
A= $incrementB= $increment > 0
ABresult
0X0
100
111
1273 0 ▶ $start_date = ParseDate($start_date) if $start_date;
Branch: 1 branch
BranchTrueFalseTotal
if $start_date 0 0 0
1274 0 ▶ $end_date = ParseDate($end_date) if $end_date;
Branch: 1 branch
BranchTrueFalseTotal
if $end_date 0 0 0
1275 0 ▶ if ($start_date && $start_date gt $end_date) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_date and $start_date gt $end_date) 0 0 0
Condition0%0/3
$start_date and $start_date gt $end_date
!ll&&!rl&&r
000
MC/DC0%0/2
$start_date and $start_date gt $end_date
$start_date $start_date gt $end_date
Truth table0%0/3
A and B
A= $start_dateB= $start_date gt $end_date
ABresult
0X0
100
111
1276 0 ($start_date, $end_date) = ($end_date, $start_date);
1277 }
1278 0 my($low_date, $high_date);
1279 0 $high_date = $end_date;
1280 sub {
1281 0 ▶ return () unless $end_date;
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
unless $end_date 0 0 0
1282 0 $low_date = DateCalc($high_date, "- $increment $units");
1283 0 ▶ if ($start_date && $low_date lt $start_date) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_date and $low_date lt $start_date) 0 0 0
Condition0%0/3
$start_date and $low_date lt $start_date
!ll&&!rl&&r
000
MC/DC0%0/2
$start_date and $low_date lt $start_date
$start_date $low_date lt $start_date
Truth table0%0/3
A and B
A= $start_dateB= $low_date lt $start_date
ABresult
0X0
100
111
1284 0 $low_date = $start_date;
1285 0 undef $start_date;
1286 0 undef $end_date;
1287 0 ▶ return () if $low_date eq $high_date;
Branch: 1 branch
BranchTrueFalseTotal
if $low_date eq $high_date 0 0 0
1288 }
1289 0 my @date_pair = ($low_date, $high_date);
1290 0 $high_date = $low_date;
1291 0 @date_pair;
1292 }
1293 0 }
1294  
1295 5 1;
1296  
1297 __END__
↑ Summary QuoteHist/Yahoo.pm »