File Coverage

blib/lib/App/Critique/Command/clean.pm
Criterion Covered Total %
statement 12 38 31.5
branch 0 8 0.0
condition 0 3 0.0
subroutine 4 6 66.6
pod 2 2 100.0
total 18 57 31.5


line stmt bran cond sub pod time code
1             package App::Critique::Command::clean;
2              
3 1     1   1010 use strict;
  1         3  
  1         26  
4 1     1   5 use warnings;
  1         2  
  1         42  
5              
6             our $VERSION = '0.05';
7             our $AUTHORITY = 'cpan:STEVAN';
8              
9 1     1   6 use App::Critique::Session;
  1         2  
  1         19  
10              
11 1     1   4 use App::Critique -command;
  1         2  
  1         7  
12              
13             sub opt_spec {
14 0     0 1   my ($class) = @_;
15             return (
16 0           [ 'dry-run', 'display the pruned list of files, but do not overwrite' ],
17             [],
18             $class->SUPER::opt_spec,
19             );
20             }
21              
22             sub execute {
23 0     0 1   my ($self, $opt, $args) = @_;
24              
25 0           my $session = $self->cautiously_load_session( $opt, $args );
26              
27 0           info('Session file loaded.');
28              
29 0           my @removed_files;
30             my @preserved_files;
31            
32 0           my @tracked_files = $session->tracked_files;
33            
34 0           info('Reviewing %s file(s).', format_number(scalar @tracked_files));
35            
36 0           foreach my $file ( @tracked_files ) {
37 0 0         if ( -e $file->path ) {
38 0           push @preserved_files => $file;
39             }
40             else {
41 0           push @removed_files => $file;
42             }
43             }
44            
45 0 0         if ( @removed_files ) {
46 0           info('Found %s removed file(s).', format_number(scalar @removed_files));
47            
48 0 0 0       if ( $opt->verbose || $opt->dry_run ) {
49 0           info(HR_LIGHT);
50 0           info($_->path) foreach @removed_files;
51 0           info(HR_LIGHT);
52             }
53            
54 0 0         if ( $opt->dry_run ) {
55 0           info('[dry-run] Would have updated list of %s file(s).', format_number(scalar @preserved_files));
56             }
57             else {
58 0           $session->set_tracked_files( @preserved_files );
59 0           $session->reset_file_idx;
60 0           info('Sucessfully updated list of %s file(s).', format_number(scalar @preserved_files));
61              
62 0           $self->cautiously_store_session( $session, $opt, $args );
63 0           info('Session file stored successfully (%s).', $session->session_file_path);
64             }
65             }
66             else {
67 0           info('Nothing to remove, so nothing to change, so session file is untouched.');
68             }
69              
70             }
71              
72             1;
73              
74             =pod
75              
76             =head1 NAME
77              
78             App::Critique::Command::clean - Clean up the set of file for the current critique session
79              
80             =head1 VERSION
81              
82             version 0.05
83              
84             =head1 DESCRIPTION
85              
86             This command will clean up the set of files for the current critique
87             session. If a file has been deleted in the filesystem, this will also
88             remove that file from the critique session as well.
89              
90             NOTE: This will reset the current file index, but not any of the
91             accumulated statistics.
92              
93             =head1 AUTHOR
94              
95             Stevan Little <stevan@cpan.org>
96              
97             =head1 COPYRIGHT AND LICENSE
98              
99             This software is copyright (c) 2016 by Stevan Little.
100              
101             This is free software; you can redistribute it and/or modify it under
102             the same terms as the Perl 5 programming language system itself.
103              
104             =cut
105              
106             __END__
107              
108             # ABSTRACT: Clean up the set of file for the current critique session
109