ConsistentPermissions/Check.pm

filter: Statementstmt 59.2% 48 / 81 Branchbran 42.3% 11 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 33.3% 1 / 3 totaltotal 55.0% 65 / 118 CC 16 SCAR 33.6
CC
16
Cov
55%
problems_to_fh
72.0
report_problems
9.0
_build_permissions_client
2.0
CRAP 28.9
↑ Summary ConsistentPermissions.pm »
1 package Test::PAUSE::ConsistentPermissions::Check;
2  
3 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use PAUSE::Permissions;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use List::Compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.003';
10  
11 2 has permissions_client => (is => 'ro', lazy => 1, builder => '_build_permissions_client');
12  
13 sub _build_permissions_client
14 0 ▶{
Subroutine _build_permissions_client: not called CC=1 SCAR=6.9
15 0 my $self = shift;
16 0 my $pp = PAUSE::Permissions->new(preload => 1, max_age => '1 day');
17 0 return $pp;
18 }
19  
20 sub report_problems
21 1 ▶{
Subroutine report_problems: called CC=9 SCAR=22.0
Pod documented
22 1 my $self = shift;
23 1 my $modules = shift;
24 1 my $authority_from = shift;
25  
26 1 my $pp = $self->permissions_client;
27 1 my $master = $pp->module_permissions($authority_from);
28 1 ▶ unless($master)
Branch: 1 branch
BranchTrueFalseTotal
unless ($master) 0 1 1
29 {
30 return {
31 0 module => $authority_from,
32 owner => 'UNKOWN',
33 comaint => [],
34 inconsistencies => 0,
35 problems => [
36 {
37 module => $authority_from,
38 issues => {
39 missing_authority => "$authority_from not found in permissions list",
40 }
41 }
42 ],
43 };
44 }
45 1 my $owner = $master->owner;
46 1 my @comaint = $master->co_maintainers;
47 1 my $inconsistencies = 0;
48  
49 1 my @problem_list;
50 1 for my $module (@$modules)
51 {
52 55 my $mp = $pp->module_permissions($module);
53 55 ▶ unless($mp)
Branch: 1 branch
BranchTrueFalseTotal
unless ($mp) 1 54 55
54 {
55 1 push @problem_list, { module => $module, issues => { missing_permissions => 'Permissions not found on PAUSE'} };
56 1 next;
57 }
58 54 my $mod_owner = $mp->owner;
59 54 my @mc = $mp->co_maintainers;
60 54 my $problems = {};
61 54 my $inconsistent = 0;
62 54 ▶ if($mod_owner ne $owner)
Branch: 1 branch
BranchTrueFalseTotal
if ($mod_owner ne $owner) 1 53 54
63 {
64 1 $problems->{different_owner} = $mod_owner;
65 1 $inconsistent = 1;
66 }
67 54 my $lc = List::Compare->new(\@comaint, \@mc);
68 54 ▶ unless($lc->is_LequivalentR)
Branch: 1 branch
BranchTrueFalseTotal
unless ($lc->is_LequivalentR) 1 53 54
69 {
70 1 my @missing = $lc->get_unique();
71 1 my @extra = $lc->get_complement();
72 1 ▶ $problems->{missing} = \@missing if @missing;
Branch: 1 branch
BranchTrueFalseTotal
if @missing 1 0 1
73 1 ▶ $problems->{extra} = \@extra if @extra;
Branch: 1 branch
BranchTrueFalseTotal
if @extra 1 0 1
74 1 $inconsistent = 1;
75 }
76 54 $inconsistencies += $inconsistent;
77 54 ▶ if(%$problems)
Branch: 1 branch
BranchTrueFalseTotal
if (%$problems) 2 52 54
78 {
79 2 push @problem_list, { module => $module, issues => $problems };
80 }
81 }
82  
83 return {
84 1 module => $authority_from,
85 owner => $owner,
86 comaint => \@comaint,
87 problems => \@problem_list,
88 inconsistencies => $inconsistencies,
89 };
90 }
91  
92 # FIXME: do these methods really belong here?
93 sub module_info_to_fh
94 0 ▶{
Subroutine module_info_to_fh: not called CC=1 SCAR=6.9
Pod undocumented
95 0 my $self = shift;
96 0 my $report = shift;
97 0 my $fh = shift;
98 0 print $fh "Module: " . $report->{module}, "\n";
99 0 print $fh "Owner: " . $report->{owner}, "\n";
100 0 print $fh "Comaint: " . join(', ', @{$report->{comaint}}), "\n";
101 }
102  
103 sub problems_to_fh
104 0 ▶{
Subroutine problems_to_fh: not called CC=8 SCAR=42.8
Pod undocumented
105 0 my $self = shift;
106 0 my $report = shift;
107 0 my $fh = shift;
108 0 my $problems = @{$report->{problems}};
109 0 ▶ if($problems)
Branch: 1 branch
BranchTrueFalseTotal
if ($problems) 0 0 0
110 {
111 0 print $fh "Problems found:\n";
112 0 for my $problem (@{$report->{problems}})
113 {
114 0 print $fh "Module: " . $problem->{module}. "\n";
115 0 ▶ if(exists $problem->{issues}->{different_owner})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $problem->{"issues"}{"different_owner"}) 0 0 0
116 {
117 0 print $fh " has a different owner - " . $problem->{issues}->{different_owner} . "\n";
118 }
119 0 ▶ if($problem->{issues}->{missing_authority})
Branch: 1 branch
BranchTrueFalseTotal
if ($problem->{"issues"}{"missing_authority"}) 0 0 0
120 {
121 0 print $fh " unable to find permissions for the module\n";
122 }
123 0 ▶ if($problem->{issues}->{missing_permissions})
Branch: 1 branch
BranchTrueFalseTotal
if ($problem->{"issues"}{"missing_permissions"}) 0 0 0
124 {
125 0 print $fh " unable to find permissions for the module\n";
126 }
127 0 ▶ if($problem->{issues}->{missing})
Branch: 1 branch
BranchTrueFalseTotal
if ($problem->{"issues"}{"missing"}) 0 0 0
128 {
129 0 print $fh " is missing comaintainers - " . join(', ', @{$problem->{issues}->{missing}}) . "\n";
130 }
131 0 ▶ if($problem->{issues}->{extra})
Branch: 1 branch
BranchTrueFalseTotal
if ($problem->{"issues"}{"extra"}) 0 0 0
132 {
133 0 print $fh " has additional comaintainers - " . join(', ', @{$problem->{issues}->{extra}}) . "\n";
134 }
135 }
136 }
137 }
138  
139 # achieve:
140 # report incorrect owner.
141 # report missing comaint.
142  
143 2 1;
144  
145 __END__
↑ Summary ConsistentPermissions.pm »