App-Critique
view release on metacpan or search on metacpan
lib/App/Critique/Command/process.pm view on Meta::CPAN
$document->save( $abs_filename );
1;
} or do {
error('Unable to save file(%s) because (%s)', $abs_filename, $@);
};
info(BOLD('File(%s) saved successfully!'), $abs_filename);
}
else {
system $cmd;
}
my $statuses = $git->status;
my @changed = $statuses->get('changed');
my $did_edit = scalar grep { my $from = $_->from; $abs_filename =~ /$from/ } @changed;
if ( $did_edit ) {
info(HR_DARK);
info('Changes detected, generating diff.');
info(HR_LIGHT);
info('%s', join "\n" => $git->RUN('diff', { 'color' => $App::Critique::CONFIG{COLOR} }));
my $policy_name = $violation->policy;
$policy_name =~ s/^Perl\:\:Critic\:\:Policy\:\://;
my $commit_msg = sprintf "%s - critique(%s)" => $violation->description, $policy_name;
CHOOSE:
info(HR_LIGHT);
my $commit_this_change = prompt_str(
(
BOLD('Commit Message:').
"\n\n ".(join "\n " => split /\n/ => $commit_msg)."\n\n".
BOLD("Press ENTER to accept this message, enter text to be appended to the commit message, or (n)o for more options.\n")
),
);
if ( !$commit_this_change ) {
info(HR_DARK);
info('Adding and commiting file (%s) to git', $abs_filename);
info(HR_LIGHT);
info('%s', join "\n" => $git->add($rel_filename, { v => 1 }));
info('%s', join "\n" => $git->commit({ v => 1, message => $commit_msg }));
my ($sha) = $git->rev_parse('HEAD');
$file->remember('shas' => [ @{ $file->recall('shas') || [] }, $sha ]);
$file->remember('commited' => ($file->recall('commited') || 0) + 1);
return 1;
}
elsif ( lc($commit_this_change) eq 'n' ) {
info(HR_LIGHT);
my $what_now = prompt_str(
BOLD('What would you like to do? edit the (f)ile, edit the (c)ommit message or (a)ppend the commit message'),
{ valid => sub { $_[0] =~ m/[fca]{1}/ } }
);
if ( $what_now eq 'c' ) {
info(HR_LIGHT);
$commit_msg = prompt_str( BOLD('Please write a commit message') );
$commit_msg =~ s/\\n/\n/g; # un-escape any newlines ...
goto CHOOSE;
}
elsif ( $what_now eq 'a' ) {
info(HR_LIGHT);
$commit_msg .= "\n\n" . prompt_str( BOLD('Please append the commit message') );
goto CHOOSE;
}
elsif ( $what_now eq 'f' ) {
goto EDIT;
}
}
else {
$commit_msg .= "\n\n" . $commit_this_change;
goto CHOOSE;
}
}
else {
RETRY:
info(HR_LIGHT);
my $what_now = prompt_str(
BOLD('No edits found, would like to (e)dit again, (s)kip this violation or (b)lame the file?'),
{ valid => sub { $_[0] =~ m/[esb]{1}/ } }
);
if ( $what_now eq 'e' ) {
goto EDIT;
}
elsif ( $what_now eq 's' ) {
return 0;
}
elsif ( $what_now eq 'b' ) {
info(HR_LIGHT);
info('%s', $self->blame_violation(
$session,
$rel_filename,
$violation->line_number
));
goto RETRY;
}
}
return 0;
}
1;
=pod
=head1 NAME
App::Critique::Command::process - Critique all the files.
=head1 VERSION
version 0.05
=head1 DESCRIPTION
This command will start or resume the critique session, allowing you to
step through the files and critique them. This current state of this
( run in 2.913 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )