| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::Critique::Command::remove; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 689 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 4 | 1 |  |  | 1 |  | 3 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 38 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION   = '0.04'; | 
| 7 |  |  |  |  |  |  | our $AUTHORITY = 'cpan:STEVAN'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 3 | use App::Critique::Session; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 17 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 1 |  |  | 1 |  | 2 | use App::Critique -command; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub opt_spec { | 
| 14 | 0 |  |  | 0 | 1 |  | my ($class) = @_; | 
| 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 |  |  | 0 | 1 |  | my ($self, $opt, $args) = @_; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 0 |  |  |  |  |  | my $session_file = App::Critique::Session->locate_session_file( $opt->git_work_tree ); | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 0 | 0 |  |  |  |  | if (not -e $session_file) { | 
| 28 | 0 | 0 |  |  |  |  | if ( $opt->verbose ) { | 
| 29 | 0 |  | 0 |  |  |  | warning( | 
| 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 | 0 |  |  |  |  | if ( $opt->dry_run ) { | 
| 40 | 0 |  |  |  |  |  | info('[dry-run] Found session file (%s), not removing.', $session_file); | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | else { | 
| 43 | 0 | 0 |  |  |  |  | if ( $session_file->remove ) { | 
| 44 | 0 |  |  |  |  |  | info('Successfully removed session file (%s).', $session_file); | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | else { | 
| 47 | 0 | 0 |  |  |  |  | if ( $opt->verbose ) { | 
| 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 | 0 |  |  |  |  | if ( my @children = $branch->children ) { | 
| 61 | 0 |  |  |  |  |  | info('Branch directory (%s) is not empty, it will not be removed', $branch); | 
| 62 | 0 | 0 |  |  |  |  | if ( $opt->verbose ) { | 
| 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 | 0 |  |  |  |  | if ( $branch->remove_tree ) { | 
| 70 | 0 |  |  |  |  |  | info('Successfully removed empty branch directory (%s).', $branch); | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  | else { | 
| 73 | 0 | 0 |  |  |  |  | if ( $opt->verbose ) { | 
| 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 | 0 |  |  |  |  | if ( my @children = $repo->children ) { | 
| 86 | 0 |  |  |  |  |  | info('Branch directory (%s) is not empty, it will not be removed', $repo); | 
| 87 | 0 | 0 |  |  |  |  | if ( $opt->verbose ) { | 
| 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 | 0 |  |  |  |  | if ( $repo->remove_tree ) { | 
| 95 | 0 |  |  |  |  |  | info('Successfully removed empty repo directory (%s).', $repo); | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  | else { | 
| 98 | 0 | 0 |  |  |  |  | if ( $opt->verbose ) { | 
| 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; | 
| 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.04 | 
| 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 |  |  |  |  |  |  |  |