Critique/Command/remove.pm

filter: Statementstmt 26.7% 15 / 56 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 22.5% 21 / 93 CC 17 SCAR 54.7
CC
17
Cov
18%
execute
306.0
opt_spec
2.0
BEGIN
1.0
CRAP 236.7
« Critique/Command/status.pm ↑ Summary Critique/Command/collect.pm »
1 package App::Critique::Command::remove;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.03';
7 1 our $AUTHORITY = 'cpan:STEVAN';
8  
9 1 ▶use App::Critique::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use App::Critique -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub opt_spec {
14 0 ▶ my ($class) = @_;
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
15 return (
16 0 [ 'dry-run', 'display list of files to be removed, but do not remove them' ],
17 [],
18 $class->SUPER::opt_spec,
19 );
20 }
21  
22 sub execute {
23 0 ▶ my ($self, $opt, $args) = @_;
Subroutine execute: not called CC=17 SCAR=57.2
Pod documented
24  
25 0 my $session_file = App::Critique::Session->locate_session_file( $opt->git_work_tree );
26  
27 0 ▶ if (not -e $session_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $session_file) 0 0 0
28 0 ▶ if ( $opt->verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->verbose) 0 0 0
29 0 ▶ warning(
Condition0%0/2
$session_file // "undef"
l!l
00
MC/DC0%0/1
$session_file // "undef"
$session_file
Truth table0%0/2
A
A= $session_file
Aresult
11
00
30 'Unable to locate session file, looking for (%s)',
31 $session_file // 'undef'
32 );
33 }
34 0 error('No session file found, nothing removed.');
35 }
36  
37 0 info('Attempting to remove session file ...');
38  
39 0 ▶ if ( $opt->dry_run ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->dry_run) { } 0 0 0
40 0 info('[dry-run] Found session file (%s), not removing.', $session_file);
41 }
42 else {
43 0 ▶ if ( $session_file->remove ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session_file->remove) { } 0 0 0
44 0 info('Successfully removed session file (%s).', $session_file);
45 }
46 else {
47 0 ▶ if ( $opt->verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->verbose) 0 0 0
48 0 warning(
49 'Could not remove session file (%s) because: %s',
50 $session_file,
51 $!
52 );
53 }
54 0 error('Unable to remove session file.');
55 }
56  
57 0 info('Attempting to clean up session directory ...');
58  
59 0 my $branch = $session_file->parent;
60 0 ▶ if ( my @children = $branch->children ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@children) = $branch->children) { } 0 0 0
61 0 info('Branch directory (%s) is not empty, it will not be removed', $branch);
62 0 ▶ if ( $opt->verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->verbose) 0 0 0
63 0 info('Branch directory (%s) contains:', $branch);
64 0 info(' %s', $_) foreach @children;
65 }
66 }
67 else {
68 0 info('Attempting to remove empty branch directory ...');
69 0 ▶ if ( $branch->remove_tree ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($branch->remove_tree) { } 0 0 0
70 0 info('Successfully removed empty branch directory (%s).', $branch);
71 }
72 else {
73 0 ▶ if ( $opt->verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->verbose) 0 0 0
74 0 warning(
75 'Could not remove empty branch directory (%s) because: %s',
76 $branch,
77 $!
78 );
79 }
80 0 error('Unable to remove empty branch directory file.');
81 }
82 }
83  
84 0 my $repo = $branch->parent;
85 0 ▶ if ( my @children = $repo->children ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@children) = $repo->children) { } 0 0 0
86 0 info('Branch directory (%s) is not empty, it will not be removed', $repo);
87 0 ▶ if ( $opt->verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->verbose) 0 0 0
88 0 info('Repo directory (%s) contains:', $repo);
89 0 info(' %s', $_) foreach @children;
90 }
91 }
92 else {
93 0 info('Attempting to remove empty repo directory ...');
94 0 ▶ if ( $repo->remove_tree ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repo->remove_tree) { } 0 0 0
95 0 info('Successfully removed empty repo directory (%s).', $repo);
96 }
97 else {
98 0 ▶ if ( $opt->verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->verbose) 0 0 0
99 0 warning(
100 'Could not remove empty repo directory (%s) because: %s',
101 $branch,
102 $!
103 );
104 }
105 0 error('Unable to remove empty repo directory file.');
106 }
107 }
108 }
109  
110 }
111  
112 1 1;
113  
114 =pod
115  
116 =head1 NAME
117  
118 App::Critique::Command::remove - Remove critique session files
119  
120 =head1 VERSION
121  
122 version 0.03
123  
124 =head1 DESCRIPTION
125  
126 This command will remove the current session file, after which
127 it will attempt to delete the branch (../) directory and the
128 repository (../../) directory if they are empty.
129  
130 =head1 AUTHOR
131  
132 Stevan Little <stevan@cpan.org>
133  
134 =head1 COPYRIGHT AND LICENSE
135  
136 This software is copyright (c) 2016 by Stevan Little.
137  
138 This is free software; you can redistribute it and/or modify it under
139 the same terms as the Perl 5 programming language system itself.
140  
141 =cut
142  
143 __END__
144  
145 # ABSTRACT: Remove critique session files
146  
« Critique/Command/status.pm ↑ Summary Critique/Command/collect.pm »