blib/lib/Dist/Zilla/Plugin/Author/Plicease/Cleaner.pm

filter: Statementstmt 98.2% 56 / 57 Branchbran 90.0% 18 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 3 totaltotal 93.6% 88 / 94 CC 17 SCAR 14.7
CC
17
Cov
96%
__ANON__
8.0
remove_file_or_dir
6.1
__ANON__
4.0
CRAP 4.3
« blib/lib/Dist/Zilla/Plugin/Author/Plicease/Core.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Author/Plicease.pm »
1 2 package Dist::Zilla::Plugin::Author::Plicease::Cleaner 2.81 {
2  
3 2 ▶ use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶ use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶ use Scalar::Util qw( refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶ use Class::Method::Modifiers qw( install_modifier );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶ use experimental qw( signatures postderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶ use true;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 with 'Dist::Zilla::Role::Plugin';
12  
13 # ABSTRACT: Clean things up
14  
15  
16 has clean => (
17 is => 'ro',
18 isa => 'ArrayRef[Str]',
19 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 2 );
21  
22 has clean_keep => (
23 is => 'ro',
24 isa => 'ArrayRef[Str]',
25 5 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 2 );
27  
28 7 ▶ sub mvp_multivalue_args { qw( clean clean_keep ) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
29  
30 7 ▶ sub BUILD ($self, $) {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
31  
32 7 my @clean_list = qw(
33 .tmp
34 _alien
35 );
36  
37 # rust: target
38 # zig: zig-cache, zig-out
39 # c: *.o *.obj *.so *.dll *.dylib
40 # Pascal: *.ppu
41 7 foreach my $x (qw( target zig-cache zig-out *.o *.obj *.so *.dll *.dylib *.ppu))
42 {
43 63 push @clean_list, join('/', 'ffi', $x), join('/', 't/ffi', $x)
44 }
45  
46 7 push @clean_list, $self->clean->@*;
47  
48 16 ▶ install_modifier 'Dist::Zilla::Dist::Builder', 'after', 'clean' => sub ($bld, $dry) {
Subroutine __ANON__: called CC=8 SCAR=20.8
49  
50 16 ▶ return unless refaddr($self->zilla) == refaddr($bld);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::refaddr($self->zilla) == builtin::refaddr($bld) 11 5 16
51  
52 5 foreach my $rule (@clean_list)
53 {
54 105 ▶ if($rule =~ m!/!)
Branch: 1 branch
BranchTrueFalseTotal
if ($rule =~ m[/]u) { } 92 13 105
55 {
56 92 foreach my $path (glob $rule =~ s!^/!!r)
57 {
58 47 ▶ next unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 20 27 47
59 27 $self->remove_file_or_dir($path, $dry);
60 }
61 }
62 else
63 {
64 13 foreach my $path (glob "$rule")
65 {
66 13 ▶ next unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 13 13
67 13 $self->remove_file_or_dir($path, $dry);
68 }
69 393 ▶ Path::Tiny->new('.')->visit(sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
70 393 my $dir = shift;
71 393 ▶ return unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 211 182 393
72 182 foreach my $path (glob "$dir/$rule")
73 {
74 151 ▶ next unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 139 12 151
75 12 $self->remove_file_or_dir($path, $dry);
76 }
77 13 }, { recurse => 1 });
78 }
79 }
80  
81 7 };
82  
83 52 ▶ sub remove_file_or_dir ($self, $path, $dry)
Subroutine remove_file_or_dir: called CC=6 SCAR=18.0
Pod undocumented
84 {
85 52 foreach my $keep ($self->clean_keep->@*)
86 {
87 21 ▶ return if $path =~ /$keep/;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ /$keep/u 2 19 21
88 }
89  
90 50 ▶ if($dry)
Branch: 1 branch
BranchTrueFalseTotal
if ($dry) { } 12 38 50
91 {
92 12 $self->log("clean: would remove $path");
93 }
94 else
95 {
96 38 $self->log("clean: removing $path");
97 38 ▶ if(-d $path)
Branch: 2 branches
BranchTrueFalseTotal
if (-d $path) { } 22 16 38
elsif (-e $path) { } 16 0 16
98 {
99 22 Path::Tiny->new($path)->remove_tree;
100 }
101 elsif(-e $path)
102 {
103 16 Path::Tiny->new($path)->remove;
104 }
105 else
106 {
107 0 $self->log("clean: is neither a file nor directory? $path");
108 }
109 }
110 }
111  
112 }
113  
114 2 __PACKAGE__->meta->make_immutable;
115  
116 }
117  
118 __END__
« blib/lib/Dist/Zilla/Plugin/Author/Plicease/Core.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Author/Plicease.pm »