| 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
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 28 | 3 | ▶ | if ( $url =~ m{^(?:file|https?):} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->{"content"} or $self->fetch
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
| |||||||||||||||||||||||||||||
| 55 | # TODO Make this less fragile | ||||||||||||||||||||||||||||
| 56 | 3 | ▶ | if ( $self->{content} =~ /> Rapture Index (\d+)</ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->{"content"} or $self->fetch
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
| |||||||||||||||||||||||||||||
| 67 | # TODO Make this less fragile | ||||||||||||||||||||||||||||
| 68 | 2 | ▶ | if ( $self->{content} =~ /Net Change.+?\s+(.+?)</ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | $rv = ( $1 eq 'unch' ? 0 : $1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->{"content"} or $self->fetch
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
| |||||||||||||||||||||||||||||
| 79 | # TODO Make this less fragile | ||||||||||||||||||||||||||||
| 80 | 2 | ▶ | if ( $self->{content} =~ /Updated(.+)?<\/p>/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 2 | $rv = $1; | |||||||||||||||||||||||||||
| 82 | # Sigh... | ||||||||||||||||||||||||||||
| 83 | 2 | $rv =~ s/ //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__ | ||||||||||||||||||||||||||||