blib/lib/Finance/SE/OMX.pm

filter: Statementstmt 36.9% 34 / 92 Branchbran 13.0% 6 / 46 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 77.7% 7 / 9 Podpod 75.0% 3 / 4 totaltotal 32.0% 51 / 159 CC 29 SCAR 42.8
CC
29
Cov
29%
stocklist_parse
132.0
get_stocklist
73.1
get_data_short
42.0
CRAP 72.0
↑ Summary
1 package Finance::SE::OMX;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $VERSION = "1.00";
5  
6 1 ▶eval "use LWP::Simple";
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
8 0 die "This module needs LWP::Simple to function properly, or at all.";
9 }
10  
11 1 ▶eval "use 5.6.0";
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
13 0 warn "This module isn't tested for versions of Perl below 5.6.0\n".
14 "Consider updating your Perl distribution\n";
15 }
16 1 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18
19  
20 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod documented
21 1 my $inv = shift;
22 1 ▶ my $class = ref($inv) || $inv;
Condition33%1/3
ref $inv || $inv
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $inv || $inv
ref $inv $inv
Truth table33%1/3
A || B
A= ref $invB= $inv
ABresult
1X1
011
000
23 1 my $self = {
24 @_
25 };
26 1 return bless $self, $class;
27 }
28  
29 0 ▶sub get_data_short {
Subroutine get_data_short: not called CC=6 SCAR=37.4
Pod documented
30 0 my $self = shift;
31 0 ▶ my $stockname = shift or die "no stockame supplied";
Branch: 1 branch
BranchTrueFalseTotal
my $stockname = shift() or die "no stockame supplied" 0 0 0
32 0 my $stockdata = get "http://www.se.omxgroup.com/stocklist.aspx?srch=$stockname&serch=true&list=all";
33 0 my @list;
34  
35 0 ▶ die "couldn't fetch data from server" unless defined $stockdata;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stockdata 0 0 0
36 0 ▶ if ($stockdata =~ /<tbody>.*?<TR>(.*?)<\/TR>.*?<\/tbody>/si) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stockdata =~ m[<tbody>.*?<TR>(.*?)</TR>.*?</tbody>]is) { } 0 0 0
37 0 @list = $self->stocklist_parse($1);
38 0 ▶ return undef unless @list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 0 0 0
39 }
40 else {
41 0 return undef;
42 }
43 0 ▶ if ($list[11] !~ /$stockname/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($list[11] =~ /$stockname/i) 0 0 0
44 0 return undef;
45 }
46 0 return @list;
47 }
48  
49 0 ▶sub stocklist_parse {
Subroutine stocklist_parse: not called CC=11 SCAR=48.8
Pod undocumented
50 0 shift;
51 0 ▶ my $table = shift || die "no table sent to table-parser";
Condition0%0/2
shift() || die('no table sent to table-parser')
l!l
00
MC/DC0%0/1
shift() || die('no table sent to table-parser')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
52 0 my @tds =();
53 0 my @retarr;
54 my $shortname;
55 0 ▶ if ($table =~ /<TD TITLE="(.*?)".*?>(.*?)<\/TD>(.*)/si) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table =~ m[<TD TITLE="(.*?)".*?>(.*?)</TD>(.*)]is) { } 0 0 0
56 0 $retarr[0] = $1;
57 0 $table = $3;
58 0 ▶ if ($2 =~ /<nobr>(.*?)<\/nobr>/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 =~ m[<nobr>(.*?)</nobr>]i) { } 0 0 0
59 0 $shortname = $1;
60 }
61 else {
62 0 die "Couldn't get shortname";
63 }
64 }
65 else {
66 0 die "couldn't get company name";
67 }
68  
69 0 foreach ($table =~ /<TD.*?>(.*?)<\/TD>/gsi) {
70 0 push @tds, $_;
71 }
72  
73 0 ▶ if (scalar(@tds) != 12) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @tds != 12) 0 0 0
74 0 die "wrong number of fields";
75 }
76 0 foreach (1 .. 2) {
77 0 ▶ if ($tds[$_] =~ /<FONT.*?>(.*?)<\/FONT>/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tds[$_] =~ m[<FONT.*?>(.*?)</FONT>]i) { } 0 0 0
78 0 $retarr[$_] = $1;
79 }
80
81 else {
82 0 $retarr[$_] = $tds[$_]; #Bättre än inget
83 }
84 }
85
86 0 foreach (3..7) {
87 0 $retarr[$_] = $tds[$_];
88 }
89
90 0 foreach(8..9) {
91 0 ▶ if ($tds[$_] =~ /<nobr>(.*?)<\/nobr>/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tds[$_] =~ m[<nobr>(.*?)</nobr>]i) { } 0 0 0
92 0 $retarr[$_] = $1;
93 }
94 else {
95 0 $retarr[$_] = $tds[$_];
96 }
97 }
98 0 $retarr[10] = $tds[11];
99 0 $retarr[11] = $shortname;
100 0 return @retarr;
101 }
102  
103 1 ▶sub get_stocklist {
Subroutine get_stocklist: called CC=13 SCAR=42.9
Pod documented
104 1 my $self = shift;
105 1 my $stocklist = shift;
106 1 ▶ if (!defined($stocklist)) { #can be zero
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stocklist) 0 1 1
107 0 die "get_stocklist() needs a list number";
108 }
109 1 my $list;
110 1 my (@retlist, @trlist);
111
112 1 ▶ die "get_stocklist() takes numerical list number" unless ($stocklist =~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $stocklist =~ /^\d+$/ 0 1 1
113 1 ▶ if ($stocklist == 0) {
Branch: 6 branches
BranchTrueFalseTotal
if ($stocklist == 0) { } 1 0 1
elsif ($stocklist == 1) { } 0 0 0
elsif ($stocklist == 2) { } 0 0 0
elsif ($stocklist == 3) { } 0 0 0
elsif ($stocklist == 4) { } 0 0 0
elsif ($stocklist == 5) { } 0 0 0
114 1 $list = get "http://www.se.omxgroup.com/stocklist.aspx?list=SSE1&group=Kursnoteringar&listname=A-lista%20samtliga";
115 }
116 elsif ($stocklist == 1) {
117 0 $list = get "http://www.se.omxgroup.com/stocklist.aspx?list=SSE2&group=Kursnoteringar&listname=A-lista%20mest%20omsatta";
118 }
119 elsif ($stocklist == 2) {
120 0 $list = get "http://www.se.omxgroup.com/stocklist.aspx?list=SSE3&group=Kursnoteringar&listname=A-lista%20%C3%B6vriga";
121 }
122 elsif ($stocklist == 3) {
123 0 $list = get "http://www.se.omxgroup.com/stocklist.aspx?list=SSE43&group=Kursnoteringar&listname=O-lista%20samtliga";
124 }
125 elsif ($stocklist == 4) {
126 0 $list = get "http://www.se.omxgroup.com/stocklist.aspx?list=SSE10&group=Kursnoteringar&listname=O-lista%20mest%20Attract40";
127 }
128 elsif ($stocklist == 5) {
129 0 $list = get "http://www.se.omxgroup.com/stocklist.aspx?list=SSE42&group=Kursnoteringar&listname=O-lista%20%EF%BF%BDvriga";
130 }
131 else {
132 0 die "get_stocklist() takes a numerical argument of 0-5";
133 }
134 1 ▶ if ($list =~ /<tbody>(.*?)<\/tbody>/si) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list =~ m[<tbody>(.*?)</tbody>]is) 0 1 1
135 0 $list = $1;
136 0 foreach ($list =~ /<TR>(.*?)<\/TR>/gs) {
137 0 push @trlist, $_;
138 }
139 0 pop @trlist; #last <tr> isn't a stock
140 0 ▶ for(my $i = 0; $i<scalar(@trlist); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @trlist) 0 0 0
141 0 my @tmparr = $self->stocklist_parse($trlist[$i]);
142 0 ▶ if (@tmparr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmparr) { } 0 0 0
143 0 $retlist[$i] = [@tmparr];
144 }
145 else {
146 0 die "error parsing \$trlist[$i]";
147 }
148 }
149 }
150 1 return @retlist;
151 }
152  
153 1 1;
154  
155 __END__
↑ Summary