| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Web::Compare; |
|
2
|
1
|
|
|
1
|
|
25494
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
4
|
1
|
|
|
1
|
|
903
|
use HTTP::Request; |
|
|
1
|
|
|
|
|
29721
|
|
|
|
1
|
|
|
|
|
38
|
|
|
5
|
1
|
|
|
1
|
|
1048
|
use Furl; |
|
|
1
|
|
|
|
|
42918
|
|
|
|
1
|
|
|
|
|
32
|
|
|
6
|
1
|
|
|
1
|
|
1398
|
use Diff::LibXDiff; |
|
|
1
|
|
|
|
|
7591
|
|
|
|
1
|
|
|
|
|
128
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
|
9
|
1
|
|
|
|
|
14
|
ro => [qw/ |
|
10
|
|
|
|
|
|
|
req |
|
11
|
|
|
|
|
|
|
ua |
|
12
|
|
|
|
|
|
|
diff |
|
13
|
|
|
|
|
|
|
hook_before |
|
14
|
|
|
|
|
|
|
hook_after |
|
15
|
|
|
|
|
|
|
on_error |
|
16
|
|
|
|
|
|
|
/], |
|
17
|
1
|
|
|
1
|
|
12
|
); |
|
|
1
|
|
|
|
|
2
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
|
22
|
0
|
|
|
0
|
1
|
|
my ($class, $left, $right, $options) = @_; |
|
23
|
|
|
|
|
|
|
|
|
24
|
0
|
|
0
|
|
|
|
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
|
|
|
|
|
|
|
}, $class; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _init_req { |
|
35
|
0
|
|
|
0
|
|
|
my $u = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
unless (ref $u eq 'HTTP::Request') { |
|
38
|
0
|
|
|
|
|
|
$u = HTTP::Request->new(GET => $u); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return $u; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub report { |
|
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $responses = $self->_request; |
|
48
|
0
|
|
|
|
|
|
my $diff = $self->_diff($responses); |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $diff; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _request { |
|
54
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my @responses; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
for my $req ( @{ $self->req } ) { |
|
|
0
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ($self->hook_before) { |
|
60
|
0
|
|
|
|
|
|
$self->hook_before->($self, $req); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
my $res = $self->ua->request($req); |
|
63
|
0
|
0
|
|
|
|
|
unless ($res->is_success) { |
|
64
|
0
|
0
|
|
|
|
|
if ($self->on_error) { |
|
65
|
0
|
|
|
|
|
|
$self->on_error->($self, $res, $req); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
|
|
|
|
|
die 'Error: '.$req->uri. "\n". $res->status_line. "\n"; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
0
|
0
|
|
|
|
|
my $content = $self->hook_after |
|
70
|
|
|
|
|
|
|
? $self->hook_after->($self, $res, $req) : $res->content; |
|
71
|
0
|
|
|
|
|
|
push @responses, $content; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return \@responses; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _diff { |
|
78
|
0
|
|
|
0
|
|
|
my ($self, $responses) = @_; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $diff; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
if ($self->diff) { |
|
83
|
0
|
|
|
|
|
|
$diff = $self->diff->(@{$responses}); |
|
|
0
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
else { |
|
86
|
0
|
|
|
|
|
|
$diff = Diff::LibXDiff->diff(@{$responses}); |
|
|
0
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $diff; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |