lib/WWW/RaptureReady.pm

filter: Statementstmt 98.2% 56 / 57 Branchbran 60.0% 12 / 20 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 11 / 11 Podpod 100% 6 / 6 totaltotal 78.0% 89 / 114 CC 15 SCAR 12.5
CC
15
Cov
81%
change
5.9
index
4.5
updated
4.3
CRAP 3.5
↑ Summary script/rapture-ready.pl »
1 package WWW::RaptureReady;
2  
3  
4 3 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use LWP::UserAgent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 3 our $VERSION = '0.2';
12  
13  
14 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
15 1 my ($class, @args) = @_;
16 1 ▶ my $self = bless {}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
17 # Default location of the Rapture Index
18 1 $self->{url} = 'http://www.raptureready.com/rap2.html';
19 1 $self->{ua} = LWP::UserAgent->new;
20 1 $self->{ua}->agent('WWW::RaptureReady/' . $VERSION);
21 1 $self->{ua}->from('blair.christensen@gmail.com');
22 1 return $self;
23 }
24  
25 7 ▶sub url {
Subroutine url: called CC=3 SCAR=11.0
Pod documented
26 7 my ($self, $url) = @_;
27 7 ▶ if (defined $url) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url) 3 4 7
28 3 ▶ if ( $url =~ m{^(?:file|https?):} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /^(?:file|https?):/) { } 2 1 3
29 2 $self->{url} = $url;
30 } else {
31 1 $self->{url} = 'file:' . $url;
32 }
33 }
34 7 return $self->{url};
35 }
36  
37 1 ▶sub fetch {
Subroutine fetch: called CC=2 SCAR=7.1
Pod documented
38 1 my $self = shift;
39 1 my $rv = undef;
40 1 my $res = $self->{ua}->get($self->{url});
41 1 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 1 0 1
42 # Fetch and cache the Rapture Index HTML
43 1 $self->{content} = $res->content;
44 1 $rv = 1;
45 } else {
46 0 Carp::carp($res->status_line);
47 }
48 1 return $rv;
49 }
50  
51 3 ▶sub index {
Subroutine index: called CC=4 SCAR=15.0
Pod documented
52 3 my $self = shift;
53 3 my $rv = undef;
54 3 ▶ if ($self->{content} or $self->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} or $self->fetch) 3 0 3
Condition33%1/3
$self->{"content"} or $self->fetch
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->{"content"} or $self->fetch
$self->{"content"} $self->fetch
Truth table33%1/3
A or B
A= $self->{"content"}B= $self->fetch
ABresult
1X1
011
000
55 # TODO Make this less fragile
56 3 ▶ if ( $self->{content} =~ />&nbsp;Rapture Index (\d+)</ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} =~ />&nbsp;Rapture Index (\d+)</) 3 0 3
57 3 $rv = $1;
58 }
59 }
60 3 return $rv;
61 }
62  
63 2 ▶sub change {
Subroutine change: called CC=5 SCAR=17.8
Pod documented
64 2 my $self = shift;
65 2 my $rv = undef;
66 2 ▶ if ($self->{content} or $self->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} or $self->fetch) 2 0 2
Condition33%1/3
$self->{"content"} or $self->fetch
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->{"content"} or $self->fetch
$self->{"content"} $self->fetch
Truth table33%1/3
A or B
A= $self->{"content"}B= $self->fetch
ABresult
1X1
011
000
67 # TODO Make this less fragile
68 2 ▶ if ( $self->{content} =~ /Net Change.+?\s+(.+?)</ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} =~ /Net Change.+?\s+(.+?)</) 2 0 2
69 2 ▶ $rv = ( $1 eq 'unch' ? 0 : $1 );
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'unch' ? : 2 0 2
70 }
71 }
72 2 return $rv;
73 }
74  
75 2 ▶sub updated {
Subroutine updated: called CC=4 SCAR=14.6
Pod documented
76 2 my $self = shift;
77 2 my $rv = undef;
78 2 ▶ if ($self->{content} or $self->fetch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} or $self->fetch) 2 0 2
Condition33%1/3
$self->{"content"} or $self->fetch
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->{"content"} or $self->fetch
$self->{"content"} $self->fetch
Truth table33%1/3
A or B
A= $self->{"content"}B= $self->fetch
ABresult
1X1
011
000
79 # TODO Make this less fragile
80 2 ▶ if ( $self->{content} =~ /Updated(.+)?<\/p>/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} =~ m[Updated(.+)?</p>]) 2 0 2
81 2 $rv = $1;
82 # Sigh...
83 2 $rv =~ s/&nbsp;//g;
84 2 $rv =~ s/<.+?>//g;
85 }
86 }
87 2 return $rv;
88 }
89  
90 3 1; # End of WWW::RaptureReady
91  
92  
93 __END__
↑ Summary script/rapture-ready.pl »