blib/lib/Finance/TickerSymbols.pm

filter: Statementstmt 66.6% 52 / 78 Branchbran 36.1% 13 / 36 Conditioncond 29.4% 5 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 92.8% 13 / 14 Podpod 100% 3 / 3 totaltotal 54.0% 86 / 159 SCAR 45.5
CC
26
Cov
53%
_gimi
119.1
symbols_list
6.5
_http2name
6.0
CRAP 94.3
↑ Summary
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 = '2.01';
19  
20 3 our $long;
21  
22 3 my %inds ;
23  
24 7 ▶sub _carp(@) { carp "@_\n" ; ()}
Subroutine _carp: called CC=1 SCAR=0.0
25  
26 sub _http2name($){
27 0 ▶ my $n = shift ;
Subroutine _http2name: not called CC=2 SCAR=17.9
28 0 for($n) {
29 0 s/^\s+//s ;
30 0 s/\s+$//s ;
31 0 s/\s+/ /sg ;
32 0 s/\&amp\;/&/g ;
33 }
34 $n
35 0 }
36  
37 my $_ua ;
38 sub _ua() {
39 3 ▶ use LWP ;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 # use HTTP::Cookies;
41 # use File::Temp 'tempfile' ;
42 # my $ua = new LWP::UserAgent(Accept => "text/html, */*;q=0.1", referer => 'http://google.com') ;
43 2 ▶ my $ua = new LWP::UserAgent() ;
Subroutine _ua: called CC=1 SCAR=0.0
44 2 $ua -> env_proxy() ;
45 # $ua -> cookie_jar( new HTTP::Cookies (file => tempfile()));
46 2 $ua -> agent("");
47 2 $ua
48 }
49  
50 sub _brws(@) {
51 7 ▶ $_ua ||= _ua() ;
Subroutine _brws: called CC=4 SCAR=14.0
Condition66%2/3
$_ua ||= &_ua()
l!l&&r!l&&!r
520
MC/DC0%0/2
$_ua ||= &_ua()
$_ua &_ua()
Truth table66%2/3
A ||= B
A= $_uaB= &_ua()
ABresult
1X1
011
000
52 7 my $res = $_ua->get(@_) ;
53 7 ▶ return $res -> content() if $res -> is_success() ;
Branch: 1 branch
BranchTrueFalseTotal
if $res->is_success 3 4 7
54 4 $res = $_ua->get(@_) ;
55 4 ▶ return $res -> content() if $res -> is_success() ;
Branch: 1 branch
BranchTrueFalseTotal
if $res->is_success 0 4 4
56 4 return _carp "download (@_):", $res->status_line() ;
57 }
58  
59 sub _gimi($$;@) {
60 7 ▶ my $prs = shift ;
Subroutine _gimi: called CC=17 SCAR=47.8
61  
62 7 ▶ local $_ = _brws(@_) or return ;
Branch: 1 branch
BranchTrueFalseTotal
local $_ = &_brws(@_) or return 4 3 7
63  
64 3 ▶ if ($prs eq 'nas' and $long) {
Branch: 5 branches
BranchTrueFalseTotal
if ($prs eq 'nas' and $Finance::TickerSymbols::long) { } 0 3 3
elsif ($prs eq 'nas') { } 3 0 3
elsif ($prs eq 'ind' and $Finance::TickerSymbols::long) { } 0 0 0
elsif ($prs eq 'ind') { } 0 0 0
elsif ($prs eq 'inds') { } 0 0 0
Condition33%1/3
$prs eq "nas" and $Finance::TickerSymbols::long
!ll&&!rl&&r
030
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
ABresult
0X0
100
111
65 0 my @ret ;
66 0 ▶ while ( m/^
Branch: 1 branch
BranchTrueFalseTotal
if (/^ \s* \" ([\w+\.]+) \" \s* \, \s* \" (.*? (?:[^\\] | \\ \\ )) \" /gmx) 0 0 0
67 \s* \" ([\w+\.]+) \" \s* \,
68 \s* \" (.*? (?:[^\\] | \\ \\ )) \"
69 0 /xgm ) { push @ret, "$1:$2" }
70 0 ▶ shift @ret if @ret and $ret[0] eq 'Symbol:Name' ;
Branch: 1 branch
BranchTrueFalseTotal
if @ret and $ret[0] eq "Symbol:Name" 0 0 0
Condition0%0/3
@ret and $ret[0] eq "Symbol:Name"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
71 return @ret
72 0 }
73 elsif ($prs eq 'nas') {
74 3 my @ret ;
75 3 ▶ while (m/^ \s* \" ([\w+\.]+) \"
Branch: 1 branch
BranchTrueFalseTotal
if (/^ \s* \" ([\w+\.]+) \" /gmx) 69 3 72
76 69 /xgm ) { push @ret, $1 }
77 3 ▶ shift @ret if @ret and $ret[0] eq 'Symbol' ;
Branch: 1 branch
BranchTrueFalseTotal
if @ret and $ret[0] eq "Symbol" 0 3 3
Condition33%1/3
@ret and $ret[0] eq "Symbol"
!ll&&!rl&&r
030
MC/DC0%0/2
@ret and $ret[0] eq "Symbol"
@ret $ret[0] eq "Symbol"
Truth table33%1/3
A and B
A= @retB= $ret[0] eq "Symbol"
ABresult
0X0
100
111
78 3 return @ret ;
79 }
80 ▶ elsif ($prs eq 'ind' and $long) {
Condition0%0/3
$prs eq "ind" and $Finance::TickerSymbols::long
!ll&&!rl&&r
000
MC/DC0%0/2
$prs eq "ind" and $Finance::TickerSymbols::long
$prs eq "ind" $Finance::TickerSymbols::long
Truth table0%0/3
A and B
A= $prs eq "ind"B= $Finance::TickerSymbols::long
ABresult
0X0
100
111
81 0 my @ret ;
82 0 ▶ while ( m{
Branch: 1 branch
BranchTrueFalseTotal
if (m[ http\://biz\.yahoo\.com/ic/\d+/\d+\.html\"\>([^\<]+).*? http\://finance\.yahoo\.com/q\?s\=([\w\.]+) ]gsx) 0 0 0
83 http\://biz\.yahoo\.com/ic/\d+/\d+\.html\"\>([^\<]+).*?
84 http\://finance\.yahoo\.com/q\?s\=([\w\.]+)
85 0 }xgs ) {push @ret, $2 . ':'. _http2name $1 }
86 return @ret
87 0 }
88 elsif ($prs eq 'ind') {
89 return
90 0 m{http\://finance\.yahoo\.com/q\?s\=([\w\.]+)\s*\"}g
91 }
92 elsif ($prs eq 'inds') {
93  
94 0 ▶ while ( m{http\://biz\.yahoo\.com/ic/(\d+)\.html\s*\"\s*\>\s*([^\<]+)}sg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[http\://biz\.yahoo\.com/ic/(\d+)\.html\s*\"\s*\>\s*([^\<]+)]gs) 0 0 0
95 0 my ($d, $n) = ($1, $2) ;
96 0 $inds{ _http2name $n } = $d ;
97 }
98 0 return keys %inds;
99 }
100 }
101  
102 sub _gimi_nasdaq($) {
103 3 ▶ my $url = 'http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=' . shift ;
Subroutine _gimi_nasdaq: called CC=1 SCAR=0.0
104 # my $dummy = _brws($url);
105 3 _gimi nas => $url . '&render=download';
106 }
107  
108 sub symbols_list($) {
109  
110 3 ▶ my $wt = shift || '?';
Subroutine symbols_list: called CC=4 SCAR=18.7
Pod documented
Condition50%1/2
shift() || '?'
l!l
30
MC/DC0%0/1
shift() || '?'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
111 3 my @all = qw/nasdaq amex nyse/ ;
112 3 ▶ return _gimi_nasdaq uc $wt if grep {$_ eq $wt } @all ;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $wt;} @all 3 0 3
113 0 ▶ return map {_gimi_nasdaq uc $_ } @all if $wt eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $wt eq "all" 0 0 0
114 0 return _carp "bad parameter: should be " . join '|', @all, 'all' ;
115 }
116  
117 4 ▶sub industries_list { _gimi inds => 'http://biz.yahoo.com/ic/ind_index.html' }
Subroutine industries_list: called CC=1 SCAR=0.0
Pod documented
118  
119 sub industry_list($) {
120 3 ▶ %inds or industries_list() ;
Subroutine industry_list: called CC=3 SCAR=13.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
%inds or industries_list() 3 0 3
121 3 my $name = shift ;
122 3 ▶ my $n = $inds{$name} or return _carp "'$name' is not recognized" ;
Branch: 1 branch
BranchTrueFalseTotal
my $n = $inds{$name} or return &_carp("'${name}' is not recognized") 3 0 3
123  
124 0 my $p = 'pub' ; # shift || ''; $p = 'pub' unless $p eq 'prv' or $p eq 'all' ;
125 # ?? TODO ??
126 # support Private/Foreign ? what for?
127 0 _gimi ind => "http://biz.yahoo.com/ic/${n}_cl_${p}.html"
128 }
129  
130 3 1;
131  
132 __END__
↑ Summary