line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DMOSS::Plugin::LinkValidator; |
2
|
|
|
|
|
|
|
$DMOSS::Plugin::LinkValidator::VERSION = '0.01_2'; |
3
|
|
|
|
|
|
|
# ABSTRACT: DMOSS link validator plugin |
4
|
1
|
|
|
1
|
|
758
|
use parent qw/DMOSS::Plugin/; |
|
1
|
|
|
|
|
377
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
45
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
33
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
826
|
use URI::Find; |
|
1
|
|
|
|
|
14094
|
|
|
1
|
|
|
|
|
88
|
|
9
|
1
|
|
|
1
|
|
13
|
use File::Slurp qw/read_file/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
10
|
1
|
|
|
1
|
|
961
|
use HTTP::Request; |
|
1
|
|
|
|
|
12855
|
|
|
1
|
|
|
|
|
38
|
|
11
|
1
|
|
|
1
|
|
1088
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
25442
|
|
|
1
|
|
|
|
|
38
|
|
12
|
1
|
|
|
1
|
|
14
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
728
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#our $SKIP = 1; |
15
|
|
|
|
|
|
|
our @types = qw/README INSTALL/; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
1
|
|
sub name { 'Link Validator' } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub process { |
20
|
0
|
|
|
0
|
1
|
|
my ($self, $dmoss, $file) = @_; |
21
|
0
|
|
|
|
|
|
my $content = read_file $file->fullpath; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $res; |
24
|
|
|
|
|
|
|
my $finder = URI::Find->new( |
25
|
|
|
|
|
|
|
sub { |
26
|
0
|
|
|
0
|
|
|
my ($uri, $orig_uri) = @_; |
27
|
0
|
0
|
|
|
|
|
return if ($orig_uri =~ m/(localhost|hostname|localdomain)/i); |
28
|
0
|
|
|
|
|
|
$res->{$orig_uri} = __test_link($orig_uri); |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
|
); |
31
|
0
|
|
|
|
|
|
$finder->find(\$content); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$dmoss->add_attr('links', $res); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub reduce { |
37
|
0
|
|
|
0
|
1
|
|
my ($self, $dmoss, @attrs) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $res; |
40
|
0
|
|
|
|
|
|
foreach (@attrs) { |
41
|
0
|
|
|
|
|
|
foreach my $i (keys %{ $_->value }) { |
|
0
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$res->{$i} = $_->value->{$i}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$dmoss->add_attr('links', $res); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub report { |
50
|
0
|
|
|
0
|
1
|
|
my ($self, $dmoss, $attr) = @_; |
51
|
0
|
0
|
0
|
|
|
|
return unless ($attr->value and keys %{$attr->value}); |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $final = []; |
54
|
0
|
|
|
|
|
|
foreach (keys %{$attr->value}) { |
|
0
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
push @$final, [ $_, ($attr->value->{$_} ? 'ok' : 'nok') ]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $final; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub report_headers { |
63
|
0
|
|
|
0
|
1
|
|
my ($self, $dmoss) = @_; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return ['URL', 'Status']; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub grade { |
69
|
0
|
|
|
0
|
1
|
|
my ($self, $dmoss, $attr) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my ($total, $valid) = (0, 0); |
72
|
0
|
|
|
|
|
|
foreach (keys %{ $attr->value }) { |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$total++; |
74
|
0
|
0
|
|
|
|
|
$valid++ if $attr->value->{$_} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
return ($total ? ($valid/$total) : 0); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# auxiliary function |
81
|
|
|
|
|
|
|
sub __test_link { |
82
|
0
|
|
|
0
|
|
|
my $url = shift; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(GET => $url); |
85
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
86
|
0
|
|
|
|
|
|
my $response = $ua->request($request); |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ($response->is_success) { return 1; } |
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
else { return -1; } |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |