| 1 | package Finance::TickerSymbols; | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use bytes ; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp ; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | our @EXPORT = qw'symbols_list | |||||||||||||||||||||||||||||||||||||||||||
| 14 | industries_list | ||||||||||||||||||||||||||||||||||||||||||||
| 15 | industry_list | ||||||||||||||||||||||||||||||||||||||||||||
| 16 | ' ; | ||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | our $VERSION = '3.11'; | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | our $long; | |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | our %inds ; | |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | sub _carp(@) { carp "@_\n" ; ()} | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_carp: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub _http2name($){ | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_http2name: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $n = shift ; | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | for($n) { | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | s/^\s+//s ; | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | s/\s+$//s ; | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | s/\s+/ /sg ; | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | s/\&\;/&/g ; | |||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 34 | $n | ||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | my $_ua ; | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | sub _ua() { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ua: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | use LWP ; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | use File::Temp 'tempfile' ; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | my $ua = new LWP::UserAgent(Accept => "text/html, */*;q=0.1", referer => 'http://google.com') ; | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # my $ua = new LWP::UserAgent() ; | ||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | $ua -> env_proxy() ; | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | $ua -> cookie_jar( new HTTP::Cookies (file => tempfile())); | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # print STDERR "I am chrome\n"; | ||||||||||||||||||||||||||||||||||||||||||||
| 48 | # $ua -> agent(""); | ||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | $ua | |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | ▶ | sub _brws(@) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_brws: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | warn "\n@_\n" ; # if $ENV{DEBUG_TICKER_SYMBOL_URL}; | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | ▶ | $_ua ||= _ua() ; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_ua ||= &_ua()
MC/DC0%0/2
$_ua ||= &_ua()
$_ua
&_ua()
Truth table66%2/3
A ||= B
A= $_uaB= &_ua()
| |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | my $res = $_ua->get(@_) ; | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | ▶ | return $res -> content() if $res -> is_success() ; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | $res = $_ua->get(@_) ; | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | return $res -> content() if $res -> is_success() ; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | return _carp "download (@_):", $res->status_line() ; | |||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | ▶ | sub _gimi($$;@) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gimi: called CC=19 SCAR=51.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 7 | my $prs = shift ; | |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 7 | ▶ | local $_ = _brws(@_) or return ; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | if ($prs eq 'nas' and $long) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition33%1/3
$prs eq "nas" and $Finance::TickerSymbols::long
MC/DC0%0/2
$prs eq "nas" and $Finance::TickerSymbols::long
$prs eq "nas"
$Finance::TickerSymbols::long
Truth table33%1/3
A and B
A= $prs eq "nas"B= $Finance::TickerSymbols::long
| |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my @ret ; | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | while ( m/^ | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 70 | \s* \" ([\w+\.]+) \" \s* \, | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | \s* \" (.*? (?:[^\\] | \\ \\ )) \" | ||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | /xgm ) { push @ret, "$1:$2" } | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | shift @ret if @ret and $ret[0] eq 'Symbol:Name' ; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@ret and $ret[0] eq "Symbol:Name"
MC/DC0%0/2
@ret and $ret[0] eq "Symbol:Name"
@ret
$ret[0] eq "Symbol:Name"
Truth table0%0/3
A and B
A= @retB= $ret[0] eq "Symbol:Name"
| |||||||||||||||||||||||||||||||||||||||||||||
| 74 | return @ret | ||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||
| 76 | elsif ($prs eq 'nas') { | ||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my @ret ; | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | while (m/^ \s* \" ([\w+\.]+) \" | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | /xgm ) { push @ret, $1 } | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | shift @ret if @ret and $ret[0] eq 'Symbol' ; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@ret and $ret[0] eq "Symbol"
MC/DC0%0/2
@ret and $ret[0] eq "Symbol"
@ret
$ret[0] eq "Symbol"
Truth table0%0/3
A and B
A= @retB= $ret[0] eq "Symbol"
| |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return @ret ; | |||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 83 | ▶ | elsif ($prs eq 'ind' and $long) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$prs eq "ind" and $Finance::TickerSymbols::long
MC/DC0%0/2
$prs eq "ind" and $Finance::TickerSymbols::long
$prs eq "ind"
$Finance::TickerSymbols::long
Truth table33%1/3
A and B
A= $prs eq "ind"B= $Finance::TickerSymbols::long
| |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my @ret ; | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | while ( m{ a \s+ | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 86 | href\=\"/quote/(\w+)\?p\=\w+\" \s+ | ||||||||||||||||||||||||||||||||||||||||||||
| 87 | title\=\"([^\"]+)\" | ||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | }xgs ) {push @ret, $1 . ':'. _http2name $2 } | |||||||||||||||||||||||||||||||||||||||||||
| 89 | return @ret | ||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ($prs eq 'ind') { | ||||||||||||||||||||||||||||||||||||||||||||
| 92 | return | ||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | m{a \s+ | |||||||||||||||||||||||||||||||||||||||||||
| 94 | href\=\"/quote/(\w+)\?p\=\w+\" \s+ | ||||||||||||||||||||||||||||||||||||||||||||
| 95 | title\=\"[^\"]+\" | ||||||||||||||||||||||||||||||||||||||||||||
| 96 | }xgs | ||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 98 | elsif ($prs eq 'inds') { | ||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | while (m{href\=\"/industry/([^\"]+)\"\s+title=\"([^\"]+)\"}g) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my ($d, $n) = ($1, $2) ; | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $inds{ _http2name $n } = $d if $d =~ /\w/ and $n =~ /\w/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$d =~ /\w/ and $n =~ /\w/
MC/DC0%0/2
$d =~ /\w/ and $n =~ /\w/
$d =~ /\w/
$n =~ /\w/
Truth table0%0/3
A and B
A= $d =~ /\w/B= $n =~ /\w/
| |||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | return keys %inds; | |||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | ▶ | sub _gimi_nasdaq($) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gimi_nasdaq: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | my $url = 'http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=' . shift ; | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # my $dummy = _brws($url); | ||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | _gimi nas => $url . '&render=download'; | |||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | sub symbols_list($) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbols_list: called CC=4 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | my $wt = shift || '?'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || '?'
MC/DC0%0/1
shift() || '?'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | my @all = qw/nasdaq amex nyse/ ; | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | return _gimi_nasdaq uc $wt if grep {$_ eq $wt } @all ; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return map {_gimi_nasdaq uc $_ } @all if $wt eq 'all'; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return _carp "bad parameter: should be " . join '|', @all, 'all' ; | |||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | ▶ | sub industries_list { _gimi inds => 'https://finance.yahoo.com/industries/' } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
industries_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | sub industry_list($) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
industry_list: called CC=4 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | %inds or industries_list() ; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | my $name = shift ; | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | $name or return _carp "Illegal arg" ; # undef, 0, '' | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my $n = $inds{$name} or return _carp "'$name' is not recognized" ; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | # my $p = 'pub' ; # shift || ''; $p = 'pub' unless $p eq 'prv' or $p eq 'all' ; | ||||||||||||||||||||||||||||||||||||||||||||
| 132 | # # ?? TODO ?? | ||||||||||||||||||||||||||||||||||||||||||||
| 133 | # # support Private/Foreign ? what for? | ||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | _gimi ind => "https://finance.yahoo.com/industry/$n" | |||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||