Midgen/Role/Experimental.pm

filter: Statementstmt 24.7% 27 / 109 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 61.5% 8 / 13 Podpod 100% 3 / 3 totaltotal 20.6% 38 / 184 CC 32 SCAR 51.2
CC
32
Cov
16%
remove_twins
272.0
remove_noisy_children
210.0
degree_separation
12.0
CRAP 167.0
« Midgen.pm ↑ Summary Midgen/Role/Output/Dist.pm »
1 package App::Midgen::Role::Experimental;
2  
3 2 our $VERSION = '0.34';
4 2 $VERSION = eval $VERSION; ## no critic
5  
6 2 ▶use constant {THREE => 3,};
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Types::Standard qw( Bool );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 #requires qw( debug );
11  
12 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Data::Printer {caller_info => 1,};
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Term::ANSIColor qw( :constants colored colorstrip );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use List::MoreUtils qw(firstidx);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 #######
19 # composed method degree of separation
20 # parent A::B - child A::B::C
21 #######
22 0 ▶sub degree_separation {
Subroutine degree_separation: not called CC=3 SCAR=24.8
Pod documented
23 0 my $self = shift;
24 0 my $parent = shift;
25 0 my $child = shift;
26  
27 # Use of implicit split to @_ is deprecated
28 0 my $parent_score = @{[split /::/, $parent]};
29 0 my $child_score = @{[split /::/, $child]};
30 0 ▶ warn 'parent - ' . $parent . ' score - ' . $parent_score if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
31 0 ▶ warn 'child - ' . $child . ' score - ' . $child_score if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
32  
33 # switch around for a positive number
34 0 return $child_score - $parent_score;
35 }
36  
37  
38 #######
39 # remove_noisy_children
40 #######
41 0 ▶sub remove_noisy_children {
Subroutine remove_noisy_children: not called CC=14 SCAR=53.5
Pod documented
42 0 my $self = shift;
43 0 ▶ my $required_ref = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
44 0 my @sorted_modules;
45  
46 0 foreach my $module_name (sort keys %{$required_ref}) {
47 0 push @sorted_modules, $module_name;
48 }
49  
50 0 ▶ p @sorted_modules if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
51  
52 0 foreach my $parent_name (@sorted_modules) {
53 0 ▶ my $outer_index = firstidx { $_ eq $parent_name } @sorted_modules;
Subroutine __ANON__: not called CC=1 SCAR=6.9
54  
55 # inc so we don't end up with parent eq child
56 0 $outer_index++;
57 0 foreach my $inner_index ($outer_index .. $#sorted_modules) {
58 0 my $child_name = $sorted_modules[$inner_index];
59  
60 # we just caught an undef
61 0 ▶ next if not defined $child_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $child_name 0 0 0
62 0 ▶ if ($child_name =~ /^ $parent_name ::/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child_name =~ /^ $parent_name ::/x) { } 0 0 0
63  
64 0 my $valied_seperation = 1;
65  
66 # as we only do this against -x, why not be extra vigilant
67 0 ▶ $valied_seperation = THREE
Branch: 1 branch
BranchTrueFalseTotal
if $parent_name =~ /^Dist::Zilla|Moose|MooseX|Moo|Mouse/ 0 0 0
68 if $parent_name =~ /^Dist::Zilla|Moose|MooseX|Moo|Mouse/;
69  
70 # Checking for one degree of separation
71 # ie A::B -> A::B::C is ok but A::B::C::D is not
72 0 ▶ if ($self->degree_separation($parent_name, $child_name)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->degree_separation($parent_name, $child_name) <= $valied_seperation) 0 0 0
73 <= $valied_seperation)
74 {
75  
76 # Test for same version number
77 0 ▶ if (colorstrip($required_ref->{$parent_name}) eq
Branch: 1 branch
BranchTrueFalseTotal
if (colorstrip($required_ref->{$parent_name}) eq colorstrip($required_ref->{$child_name})) { } 0 0 0
78 colorstrip($required_ref->{$child_name}))
79 {
80 0 ▶ if (not $self->quiet) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 0 0
81 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
82 0 print BRIGHT_BLACK;
83 print 'delete miscreant noisy child '
84 . $child_name . ' => '
85 0 . $required_ref->{$child_name};
86 0 print CLEAR. "\n";
87 }
88 }
89 0 ▶ try {
Subroutine __ANON__: not called CC=2 SCAR=17.9
90 0 delete $required_ref->{$child_name};
91 0 splice @sorted_modules, $inner_index, 1;
92  
93 0 ▶ unless ($self->{modules}{$parent_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"modules"}{$parent_name}) 0 0 0
94 0 $self->{modules}{$parent_name}{prereqs} = 'expermental';
95 $self->{modules}{$parent_name}{version}
96 0 = $required_ref->{$parent_name};
97 0 $self->{modules}{$parent_name}{count} += 1;
98 }
99 0 };
100 0 ▶ p @sorted_modules if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
101  
102 # we need to redo as we just deleted a child
103 0 redo;
104  
105 }
106 else {
107  
108 # not my child so lets try the next one
109 0 next;
110 }
111 }
112 }
113 else {
114  
115 # no more like the parent so lets start again
116 0 last;
117 }
118 }
119 }
120 0 return;
121 }
122  
123  
124 #######
125 # remove_twins
126 #######
127 0 ▶sub remove_twins {
Subroutine remove_twins: not called CC=16 SCAR=56.1
Pod documented
128 0 my $self = shift;
129 0 ▶ my $required_ref = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
130 0 my @sorted_modules;
131 0 foreach my $module_name (sort keys %{$required_ref}) {
132 0 push @sorted_modules, $module_name;
133 }
134  
135 0 ▶ p @sorted_modules if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
136  
137 # exit if only 1 Module found
138 0 ▶ return if $#sorted_modules == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $#sorted_modules == 0 0 0 0
139  
140 0 my $n = 0;
141 0 ▶ while ($sorted_modules[$n]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sorted_modules[$n]) 0 0 0
142  
143 0 my $dum_name = $sorted_modules[$n];
144 0 my $dum_parient = $dum_name;
145 0 $dum_parient =~ s/(::\w+)$//;
146  
147 0 my $dee_parient;
148 my $dee_name;
149 0 ▶ if (($n + 1) <= $#sorted_modules) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n + 1 <= $#sorted_modules) 0 0 0
150 0 $n++;
151 0 $dee_name = $sorted_modules[$n];
152 0 $dee_parient = $dee_name;
153 0 $dee_parient =~ s/(::\w+)$//;
154 }
155  
156 # Checking for same patient and score
157 0 ▶ if ( $dum_parient eq $dee_parient
Branch: 1 branch
BranchTrueFalseTotal
if ($dum_parient eq $dee_parient and $self->degree_separation($dum_name, $dee_name) == 0) 0 0 0
Condition0%0/3
$dum_parient eq $dee_parient and $self->degree_separation($dum_name, $dee_name) == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$dum_parient eq $dee_parient and $self->degree_separation($dum_name, $dee_name) == 0
$dum_parient eq $dee_parient $self->degree_separation($dum_name, $dee_name) == 0
Truth table0%0/3
A and B
A= $dum_parient eq $dee_parientB= $self->degree_separation($dum_name, $dee_name) == 0
ABresult
0X0
100
111
158 && $self->degree_separation($dum_name, $dee_name) == 0)
159 {
160  
161 # Test for same version number
162 0 ▶ if ($required_ref->{$sorted_modules[$n - 1]} eq
Branch: 1 branch
BranchTrueFalseTotal
if ($$required_ref{$sorted_modules[$n - 1]} eq $$required_ref{$sorted_modules[$n]}) 0 0 0
163 $required_ref->{$sorted_modules[$n]})
164 {
165 0 ▶ if (not $self->quiet) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->quiet) 0 0 0
166 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
167 0 print BRIGHT_BLACK;
168  
169 # stdout - 'i have found twins';
170 print $dum_name . ' => '
171 0 . $required_ref->{$sorted_modules[$n - 1]};
172 print BRIGHT_BLACK ' <-twins-> '
173 . $dee_name . ' => '
174 0 . $required_ref->{$sorted_modules[$n]};
175 0 print CLEAR "\n";
176 }
177 }
178  
179 #Check for valid parent
180 0 my $version;
181  
182 0 $version = $self->get_module_version($dum_parient);
183  
184 0 ▶ if (version::is_lax($version)) {
Branch: 1 branch
BranchTrueFalseTotal
if (version::is_lax($version)) 0 0 0
185  
186 #Check parent version against a twins version
187 0 ▶ if ($version eq $required_ref->{$sorted_modules[$n]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version eq $$required_ref{$sorted_modules[$n]}) 0 0 0
188 0 ▶ print $dum_parient . ' -> '
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
189 . $version
190 . " is the parent of these twins\n"
191 if $self->verbose;
192 0 $required_ref->{$dum_parient} = $version;
193 0 $self->_set_found_twins(1);
194 }
195 }
196 }
197 }
198 0 ▶ $n++ if ($n == $#sorted_modules);
Branch: 1 branch
BranchTrueFalseTotal
if $n == $#sorted_modules 0 0 0
199 }
200 0 return;
201 }
202  
203 2 ▶no Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
204  
205 2 1;
206  
207 __END__
« Midgen.pm ↑ Summary Midgen/Role/Output/Dist.pm »