| 1 | package Web::Compare; | ||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 5 | ▶ | use HTTP::Request; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use Furl; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use Diff::LibXDiff; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 5 | ▶ | use Class::Accessor::Lite ( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 5 | ro => [qw/ | |||||||||||||||||||
| 10 | req | ||||||||||||||||||||
| 11 | ua | ||||||||||||||||||||
| 12 | diff | ||||||||||||||||||||
| 13 | hook_before | ||||||||||||||||||||
| 14 | hook_after | ||||||||||||||||||||
| 15 | on_error | ||||||||||||||||||||
| 16 | /], | ||||||||||||||||||||
| 17 | 5 | ); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 5 | our $VERSION = '0.04'; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 8 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 22 | 8 | my ($class, $left, $right, $options) = @_; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | bless { | ||||||||||||||||||||
| 25 | req => [ _init_req($left), _init_req($right) ], | ||||||||||||||||||||
| 26 | ua => $options->{ua} || Furl->new, | ||||||||||||||||||||
| 27 | diff => $options->{diff}, | ||||||||||||||||||||
| 28 | hook_before => $options->{hook_before}, | ||||||||||||||||||||
| 29 | hook_after => $options->{hook_after}, | ||||||||||||||||||||
| 30 | on_error => $options->{on_error}, | ||||||||||||||||||||
| 31 | 8 | ▶ | }, $class; | ||||||||||||||||||
|
Condition66%2/3
$options->{'ua'} || 'Furl'->new
MC/DC0%0/2
$options->{'ua'} || 'Furl'->new
$options->{'ua'}
'Furl'->new
Truth table66%2/3
A || B
A= $options->{'ua'}B= 'Furl'->new
| |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 16 | ▶ | sub _init_req { | ||||||||||||||||||
|
Subroutine
_init_req: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 35 | 16 | my $u = shift; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 16 | ▶ | unless (ref $u eq 'HTTP::Request') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 14 | $u = HTTP::Request->new(GET => $u); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 16 | return $u; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 8 | ▶ | sub report { | ||||||||||||||||||
|
Subroutine
report: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 45 | 8 | my $self = shift; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 8 | my $responses = $self->_request; | |||||||||||||||||||
| 48 | 7 | my $diff = $self->_diff($responses); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 7 | return $diff; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 8 | ▶ | sub _request { | ||||||||||||||||||
|
Subroutine
_request: called CC=6 SCAR=17.9
| |||||||||||||||||||||
| 54 | 8 | my $self = shift; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 8 | my @responses; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 8 | for my $req ( @{ $self->req } ) { | |||||||||||||||||||
| 59 | 15 | ▶ | if ($self->hook_before) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 4 | $self->hook_before->($self, $req); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 15 | my $res = $self->ua->request($req); | |||||||||||||||||||
| 63 | 15 | ▶ | unless ($res->is_success) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 1 | ▶ | if ($self->on_error) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 1 | $self->on_error->($self, $res, $req); | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 1 | die 'Error: '.$req->uri. "\n". $res->status_line. "\n"; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 14 | ▶ | my $content = $self->hook_after | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | ? $self->hook_after->($self, $res, $req) : $res->content; | ||||||||||||||||||||
| 71 | 14 | push @responses, $content; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 7 | return \@responses; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 7 | ▶ | sub _diff { | ||||||||||||||||||
|
Subroutine
_diff: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 78 | 7 | my ($self, $responses) = @_; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 7 | my $diff; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 7 | ▶ | if ($self->diff) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 1 | $diff = $self->diff->(@{$responses}); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||
| 86 | 6 | $diff = Diff::LibXDiff->diff(@{$responses}); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 7 | return $diff; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 5 | 1; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||