DMOSS/Plugin/LinkValidator.pm

filter: Statementstmt 39.7% 27 / 68 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 8 / 16 Podpod 100% 6 / 6 totaltotal 38.3% 41 / 107 CC 12 SCAR 24.2
CC
12
Cov
33%
report
30.0
grade
20.0
reduce
12.0
CRAP 11.3
« DMOSS/Plugin/CommentLines.pm ↑ Summary DMOSS/Plugin/VerifyLicense.pm »
1 package DMOSS::Plugin::LinkValidator;
2 1 $DMOSS::Plugin::LinkValidator::VERSION = '0.01_2';
3 # ABSTRACT: DMOSS link validator plugin
4 1 ▶use parent qw/DMOSS::Plugin/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use URI::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Slurp qw/read_file/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #our $SKIP = 1;
15 1 our @types = qw/README INSTALL/;
16  
17 0 ▶sub name { 'Link Validator' }
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
18  
19 0 ▶sub process {
Subroutine process: not called CC=1 SCAR=6.9
Pod documented
20 0 my ($self, $dmoss, $file) = @_;
21 0 my $content = read_file $file->fullpath;
22  
23 0 my $res;
24 my $finder = URI::Find->new(
25 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
26 0 my ($uri, $orig_uri) = @_;
27 0 ▶ return if ($orig_uri =~ m/(localhost|hostname|localdomain)/i);
Branch: 1 branch
BranchTrueFalseTotal
if $orig_uri =~ /(localhost|hostname|localdomain)/i 0 0 0
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 0 ▶sub reduce {
Subroutine reduce: not called CC=3 SCAR=24.8
Pod documented
37 0 my ($self, $dmoss, @attrs) = @_;
38  
39 0 my $res;
40 0 foreach (@attrs) {
41 0 foreach my $i (keys %{ $_->value }) {
42 0 $res->{$i} = $_->value->{$i};
43 }
44 }
45  
46 0 $dmoss->add_attr('links', $res);
47 }
48  
49 0 ▶sub report {
Subroutine report: not called CC=5 SCAR=34.0
Pod documented
50 0 my ($self, $dmoss, $attr) = @_;
51 0 ▶ return unless ($attr->value and keys %{$attr->value});
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->value and keys %{$attr->value;} 0 0 0
Condition0%0/3
$attr->value and keys %{$attr->value;}
!ll&&!rl&&r
000
MC/DC0%0/2
$attr->value and keys %{$attr->value;}
$attr->value keys %{$attr->value;}
Truth table0%0/3
A and B
A= $attr->valueB= keys %{$attr->value;}
ABresult
0X0
100
111
52  
53 0 my $final = [];
54 0 foreach (keys %{$attr->value}) {
55 0 ▶ push @$final, [ $_, ($attr->value->{$_} ? 'ok' : 'nok') ];
Branch: 1 branch
BranchTrueFalseTotal
$attr->value->{$_} ? : 0 0 0
56 }
57  
58 0 return $final;
59
60 }
61  
62 0 ▶sub report_headers {
Subroutine report_headers: not called CC=1 SCAR=6.9
Pod documented
63 0 my ($self, $dmoss) = @_;
64  
65 0 return ['URL', 'Status'];
66 }
67  
68 0 ▶sub grade {
Subroutine grade: not called CC=4 SCAR=30.0
Pod documented
69 0 my ($self, $dmoss, $attr) = @_;
70  
71 0 my ($total, $valid) = (0, 0);
72 0 foreach (keys %{ $attr->value }) {
73 0 $total++;
74 0 ▶ $valid++ if $attr->value->{$_}
Branch: 1 branch
BranchTrueFalseTotal
if $attr->value->{$_} 0 0 0
75 }
76  
77 0 ▶ return ($total ? ($valid/$total) : 0);
Branch: 1 branch
BranchTrueFalseTotal
$total ? : 0 0 0
78 }
79  
80 # auxiliary function
81 0 ▶sub __test_link {
Subroutine __test_link: not called CC=2 SCAR=17.9
82 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 ▶ if ($response->is_success) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
89 0 else { return -1; }
90 }
91  
92 1 1;
93  
94 __END__
« DMOSS/Plugin/CommentLines.pm ↑ Summary DMOSS/Plugin/VerifyLicense.pm »