| 1 | package Finance::QuoteHist::Yahoo; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | $VERSION = '1.05'; | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Finance::QuoteHist::Generic; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | @ISA = qw(Finance::QuoteHist::Generic); | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use HTML::TableExtract 2.07; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Date::Manip; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | Date::Manip::Date_Init("TZ=GMT"); | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Example for HTML output: | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # http://finance.yahoo.com/q/hp?s=IBM&a=00&b=2&c=1800&d=04&e=8&f=2005&g=d&z=66&y=66 | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # * s - ticker symbol | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # * a - start month | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # * b - start day | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # * c - start year | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # * d - end month | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # * e - end day | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # * f - end year | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # * g - resolution (e.g. 'd' is daily, 'w' is weekly, 'm' is monthly) | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # * y is the offset (cursor) from the start date | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # * z is the number of results to return starting at the cursor (66 | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # maximum, apparently) | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Note alternate url: | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # http://table.finance.yahoo.com/d?a=1&b=1&c=1800&d=3&e=1&f=2006&s=yhoo&y=200&g=d | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Example for CSV output: | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # http://ichart.finance.yahoo.com/table.csv?s=IBM&a=00&b=2&c=1800&d=04&e=8&f=2005&g=d&ignore=.csv | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # (historically could use table.finance.yahoo.com as well) | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Note that Yahoo implements month numbering with Jan=0 and Dec=11. | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # For CSV output, date ranges are unlimited; the output is adjusted and | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # does not include any split or dividend notices. | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # URL for splits and dividends: | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # These are either extracted from within the historical quote results | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # (non_quote_row()) or found directly: | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # http://finance.yahoo.com/q/hp?s=IBM&a=00&b=2&c=1800&d=04&e=8&f=2005&g=v | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # http://table.finance.yahoo.com/table.csv?s=IBM&a=00&b=2&c=1800&d=04&e=8&f=2005&g=v&ignore=.csv | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Example URL for weekly: | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # http://finance.yahoo.com/q/hp?s=IBM&a=00&b=2&c=1962&d=01&e=27&f=2006&g=w | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Example URL for monthly: | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # http://finance.yahoo.com/q/hp?s=IBM&a=00&b=2&c=1962&d=01&e=27&f=2006&g=m | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | ▶ | my $that = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | ▶ | my $class = ref($that) || $that; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | my %parms = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | ▶ | $parms{parse_mode} ||= 'csv'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$parms{"parse_mode"} ||= "csv"
MC/DC0%0/1
$parms{"parse_mode"} ||= "csv"
$parms{"parse_mode"}
Truth table50%1/2
A
A= $parms{"parse_mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | my $self = __PACKAGE__->SUPER::new(%parms); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | $self->set_label_pattern( | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | target_mode => 'dividend', | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | parse_mode => 'html', | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | label => 'div', | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | pattern => qr/(Open|Div)/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # override these for other Yahoo sites | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | ▶ | sub url_base_csv { 'http://ichart.finance.yahoo.com/table.csv' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url_base_csv: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub url_base_html { 'http://finance.yahoo.com/q/hp' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url_base_html: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | sub url_base_splits { 'http://finance.yahoo.com/q/bc' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url_base_splits: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub granularities { qw( daily weekly monthly ) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
granularities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Yahoo can fetch dividends and splits. They can be extracted from | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # regular quote results or queried directly. | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | sub html_parser { | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | my($self, %parms) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html_parser: called CC=3 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | my $target_mode = $parms{target_mode} || $self->target_mode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$parms{'target_mode'} || $self->target_mode
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | return $self->SUPER::html_parser(%parms) unless $target_mode eq 'split'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | my $data = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=34.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | my $html_string; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | ▶ | if (ref $data) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | local($/); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $html_string = <$data>; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | $html_string = $data; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | my %te_parms = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | headers => ['Splits:'], | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | debug => $self->{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my $te = HTML::TableExtract->new(%te_parms); | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | $te->parse($html_string); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | my $table = $te->first_table_found || return []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$te->first_table_found || (return [])
MC/DC0%0/1
$te->first_table_found || (return [])
$te->first_table_found
Truth table50%1/2
A
A= $te->first_table_found
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my($split_line) = grep(defined && /split/i, $table->hrow); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $_ && /split/i
MC/DC0%0/2
defined $_ && /split/i
defined $_
/split/i
Truth table0%0/3
A && B
A= defined $_B= /split/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $split_line =~ s/^\s*splits:?\s*//i; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | foreach (grep(/\w+/, split(/\]\s*,\s+/, $split_line))) { | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | next if /none/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | next unless s/\s*\[(\d+):(\d+).*$//; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my($post, $pre) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | my $date = ParseDate($_) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | or croak "Problem parsing date string '$_'\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | push(@rows, [$date, $post, $pre]); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | \@rows; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | sub labels { | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 18 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
labels: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 18 | my %parms = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 18 | my $target_mode = $self->target_mode; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 18 | my @labels = $self->SUPER::labels(%parms); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 18 | ▶ | push(@labels, 'adj') if $target_mode eq 'quote'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 18 | @labels; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | sub extractors { | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Override. If we are pulling CSV, save some time by skipping | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # extraction attempts | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extractors: called CC=7 SCAR=35.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | my %parms = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | ▶ | my $target_mode = $parms{target_mode} || $self->target_mode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$parms{'target_mode'} || $self->target_mode
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | ▶ | my $parse_mode = $parms{parse_mode} || $self->parse_mode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$parms{'parse_mode'} || $self->parse_mode
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | ▶ | return () if $parse_mode eq 'csv'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | return () unless $target_mode eq 'quote' || $target_mode eq 'dividend'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$target_mode eq "quote" or $target_mode eq "dividend"
MC/DC0%0/2
$target_mode eq "quote" or $target_mode eq "dividend"
$target_mode eq "quote"
$target_mode eq "dividend"
Truth table0%0/3
A or B
A= $target_mode eq "quote"B= $target_mode eq "dividend"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $date_column = $self->label_column('date'); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $split_column = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my %extractors; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | # for both quote and dividend results in html mode | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | $extractors{'split'} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my $row = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | die "row as array ref required" unless ref $row; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # example split: "3 : 1 Stock Split" | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my($post, $pre) = $row->[$split_column] =~ /(\d+)\s*:\s*(\d+).*Split/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | return undef unless $post && $pre; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$post and $pre
MC/DC0%0/2
$post and $pre
$post
$pre
Truth table0%0/3
A and B
A= $postB= $pre
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | [ $row->[$date_column], $post, $pre ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ($target_mode eq 'quote') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $div_column = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | $extractors{dividend} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Get a row as array ref, see if it contains dividend info. If so, | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # return another array ref with the extracted info. | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my $row = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | die "row as array ref required\n" unless ref $row; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # example dividend: "$0.01 Cash Dividend" | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my($div) = $row->[$div_column] =~ /\$*(\d*\.\d+).*Dividend/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return undef unless defined $div; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | [ $row->[$date_column], $row->[$div_column] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | %extractors; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | sub url_maker { | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 10 | ▶ | my($self, %parms) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url_maker: called CC=26 SCAR=36.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 10 | ▶ | my $target_mode = $parms{target_mode} || $self->target_mode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$parms{'target_mode'} || $self->target_mode
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 10 | ▶ | my $parse_mode = $parms{parse_mode} || $self->parse_mode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$parms{'parse_mode'} || $self->parse_mode
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # *always* block unknown target mode and parse mode combinations for | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # cascade to work properly! | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 10 | ▶ | return undef unless $target_mode eq 'quote' || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$target_mode eq "quote" or $target_mode eq "split" or $target_mode eq "dividend"
$target_mode eq "quote" or $target_mode eq "split"
MC/DC0%0/3
$target_mode eq "quote" or $target_mode eq "split" or $target_mode eq "dividend"
$target_mode eq "quote"
$target_mode eq "split"
$target_mode eq "dividend"
Truth table75%3/4
A or B or C
A= $target_mode eq "quote"B= $target_mode eq "split"C= $target_mode eq "dividend"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | $target_mode eq 'split' || | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | $target_mode eq 'dividend'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 10 | ▶ | return undef unless $parse_mode eq 'html' || $parse_mode eq 'csv'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$parse_mode eq "html" or $parse_mode eq "csv"
MC/DC0%0/2
$parse_mode eq "html" or $parse_mode eq "csv"
$parse_mode eq "html"
$parse_mode eq "csv"
Truth table33%1/3
A or B
A= $parse_mode eq "html"B= $parse_mode eq "csv"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 10 | ▶ | my $granularity = lc($parms{granularity} || $self->granularity); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$parms{'granularity'} || $self->granularity
MC/DC0%0/2
$parms{'granularity'} || $self->granularity
$parms{'granularity'}
$self->granularity
Truth table33%1/3
A || B
A= $parms{'granularity'}B= $self->granularity
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 10 | my $grain = 'd'; | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 10 | $granularity =~ /^\s*(\w)/; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 10 | ▶ | $grain = $1 if $1 eq 'w' || $1 eq 'm'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$1 eq "w" or $1 eq "m"
MC/DC100%2/2
$1 eq "w" or $1 eq "m"
$1 eq "w"
$1 eq "m"
Truth table100%3/3
A or B
A= $1 eq "w"B= $1 eq "m"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | my($ticker, $start_date, $end_date) = | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 10 | @parms{qw(symbol start_date end_date)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | ▶ | $start_date ||= $self->start_date; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$start_date ||= $self->start_date
MC/DC0%0/2
$start_date ||= $self->start_date
$start_date
$self->start_date
Truth table33%1/3
A ||= B
A= $start_dateB= $self->start_date
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 10 | ▶ | $end_date ||= $self->end_date; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$end_date ||= $self->end_date
MC/DC0%0/2
$end_date ||= $self->end_date
$end_date
$self->end_date
Truth table33%1/3
A ||= B
A= $end_dateB= $self->end_date
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 10 | ▶ | if ($start_date && $end_date && $start_date gt $end_date) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$start_date and $end_date and $start_date gt $end_date
$start_date and $end_date
MC/DC0%0/3
$start_date and $end_date and $start_date gt $end_date
$start_date
$end_date
$start_date gt $end_date
Truth table25%1/4
A and B and C
A= $start_dateB= $end_dateC= $start_date gt $end_date
| |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ($start_date, $end_date) = ($end_date, $start_date); | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 | ▶ | if ($target_mode eq 'split') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | $self->parse_mode('html'); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | my @urls = $self->url_base_splits() . "?s=$ticker&t=my"; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | return sub { pop @urls }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 8 | ▶ | my $base_url = $parse_mode eq 'csv' ? $self->url_base_csv() : | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | $self->url_base_html(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 8 | my @base_parms; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 8 | ▶ | if ($start_date) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 8 | my($y, $m, $d) = $self->ymd($start_date); | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 8 | $m = sprintf("%02d", $m - 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | push(@base_parms, "a=$m", "b=$d", "c=$y"); | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | ▶ | if ($end_date) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 8 | my($y, $m, $d) = $self->ymd($end_date); | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 8 | $m = sprintf("%02d", $m - 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | push(@base_parms, "d=$m", "e=$d", "f=$y"); | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | ▶ | my $g = $target_mode eq 'quote' ? $grain : 'v'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | ▶ | $ticker ||= 'BOOLEAN'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ticker ||= "BOOLEAN"
MC/DC0%0/1
$ticker ||= "BOOLEAN"
$ticker
Truth table50%1/2
A
A= $ticker
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | push(@base_parms, "g=$g", "s=$ticker"); | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 8 | ▶ | if ($parse_mode eq 'html' && $target_mode eq 'quote' || $target_mode eq 'dividend') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$parse_mode eq "html" and $target_mode eq "quote" or $target_mode eq "dividend"
$parse_mode eq "html" and $target_mode eq "quote"
MC/DC33%1/3
$parse_mode eq "html" and $target_mode eq "quote" or $target_mode eq "dividend"
$parse_mode eq "html"
$target_mode eq "quote"
$target_mode eq "dividend"
Truth table40%2/5
A and B or C
A= $parse_mode eq "html"B= $target_mode eq "quote"C= $target_mode eq "dividend"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | my $cursor = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | my $window = 66; | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 2 | ▶ | my $url = $base_url . '?' . | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | join('&', @base_parms, | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | "z=$window", "y=$cursor"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | ▶ | $url .= '&ignore=.csv' if $parse_mode eq 'csv'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | $cursor += $window; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | $url; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 6 | my @urls = $base_url . '?' . join('&', @base_parms); | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | ▶ | $urls[0] .= '&ignore=.csv' if $parse_mode eq 'csv'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 6 | ▶ | return sub { pop @urls } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 6 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||