| 1 | package Finance::QuoteHist::Google; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | $VERSION = '1.01'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Finance::QuoteHist::Generic; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | @ISA = qw(Finance::QuoteHist::Generic); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Date::Manip; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | Date::Manip::Date_Init("TZ=GMT"); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # Example URL: | ||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||
| 17 | # http://www.google.com/finance/historical?q=IBM&startdate=Nov%2011%2C%202008&enddate=Feb%27%2C%202009&output=csv | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | # This also works: | ||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||
| 21 | # http://www.google.com/finance/historical?q=IBM&startdate=2008-11-11&enddate=2009-02-27&output=csv | ||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||
| 23 | # weekly: | ||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||
| 25 | # http://www.google.com/finance/historical?cid=99624&startdate=2008-11-11&enddate=2009-02-27&histperiod=weekly&output=csv | ||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||
| 27 | # Note: regular symbols have csv available, but some such as .DJI do not. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub new { | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $that = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $class = ref($that) || $that; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||
| 32 | 0 | my %parms = @_; | |||||||||||||||||||||||||||
| 33 | 0 | my $self = __PACKAGE__->SUPER::new(%parms); | |||||||||||||||||||||||||||
| 34 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 35 | 0 | $self->parse_mode('csv'); | |||||||||||||||||||||||||||
| 36 | 0 | $self; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub url_base_csv { 'http://www.google.com/finance/historical' } | ||||||||||||||||||||||||||
|
Subroutine
url_base_csv: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub granularities { qw( daily weekly ) } | ||||||||||||||||||||||||||
|
Subroutine
granularities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub url_maker { | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my($self, %parms) = @_; | ||||||||||||||||||||||||||
|
Subroutine
url_maker: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $target_mode = $parms{target_mode} || $self->target_mode; | ||||||||||||||||||||||||||
|
Condition0%0/3
$parms{'target_mode'} || $self->target_mode
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
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $parse_mode = $parms{parse_mode} || $self->parse_mode; | ||||||||||||||||||||||||||
|
Condition0%0/3
$parms{'parse_mode'} || $self->parse_mode
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
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $grain = $parms{granularity} || $self->granularity; | ||||||||||||||||||||||||||
|
Condition0%0/3
$parms{'granularity'} || $self->granularity
MC/DC0%0/2
$parms{'granularity'} || $self->granularity
$parms{'granularity'}
$self->granularity
Truth table0%0/3
A || B
A= $parms{'granularity'}B= $self->granularity
| |||||||||||||||||||||||||||||
| 48 | # *always* block unknown target/mode cominations | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return undef unless $target_mode eq 'quote' && $parse_mode eq 'csv'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$target_mode eq "quote" and $parse_mode eq "csv"
MC/DC0%0/2
$target_mode eq "quote" and $parse_mode eq "csv"
$target_mode eq "quote"
$parse_mode eq "csv"
Truth table0%0/3
A and B
A= $target_mode eq "quote"B= $parse_mode eq "csv"
| |||||||||||||||||||||||||||||
| 50 | my($ticker, $start_date, $end_date) = | ||||||||||||||||||||||||||||
| 51 | 0 | @parms{qw(symbol start_date end_date)}; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | $start_date ||= $self->start_date; | ||||||||||||||||||||||||||
|
Condition0%0/3
$start_date ||= $self->start_date
MC/DC0%0/2
$start_date ||= $self->start_date
$start_date
$self->start_date
Truth table0%0/3
A ||= B
A= $start_dateB= $self->start_date
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $end_date ||= $self->end_date; | ||||||||||||||||||||||||||
|
Condition0%0/3
$end_date ||= $self->end_date
MC/DC0%0/2
$end_date ||= $self->end_date
$end_date
$self->end_date
Truth table0%0/3
A ||= B
A= $end_dateB= $self->end_date
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my($sy, $sm, $sd) = $self->ymd($start_date); | |||||||||||||||||||||||||||
| 56 | 0 | my($ey, $em, $ed) = $self->ymd($end_date); | |||||||||||||||||||||||||||
| 57 | 0 | my @base_parms = ( | |||||||||||||||||||||||||||
| 58 | "q=$ticker", | ||||||||||||||||||||||||||||
| 59 | "startdate=$sy-$sm-$sd", "enddate=$ey-$em+$ed", | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | push(@base_parms, 'histperiod=weekly') if $grain && $grain =~ /^w/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$grain and $grain =~ /^w/i
MC/DC0%0/2
$grain and $grain =~ /^w/i
$grain
$grain =~ /^w/i
Truth table0%0/3
A and B
A= $grainB= $grain =~ /^w/i
| |||||||||||||||||||||||||||||
| 62 | 0 | push(@base_parms, "output=csv"); | |||||||||||||||||||||||||||
| 63 | 0 | my @urls = join('?', $self->url_base_csv, join('&', @base_parms)); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub { pop @urls }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | 1; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||