Created
July 19, 2012 10:02
-
-
Save Ovid/3142826 to your computer and use it in GitHub Desktop.
Integrating perlcritic and vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# in your .vimrc | |
# " quickfix for Perl error formats | |
# set errorformat+=%m\ at\ %f\ line\ %l\. | |
# set errorformat+=%m\ at\ %f\ line\ %l | |
# noremap ,c :!time perlc --critic %<cr> | |
use 5.10.0; | |
use File::Temp 'tempfile'; | |
use IO::All; | |
use Getopt::Long; | |
use autodie; | |
GetOptions( | |
critic => \my $critic, | |
) or die; | |
my $libcustom = '.libcustom'; | |
my $prog = shift // die "Usage: $0 perlfile"; | |
my $PERL5LIB = $ENV{PERL5LIB} // ''; | |
if ( -f $libcustom ) { | |
chomp( my @libs = io($libcustom)->slurp ); | |
$PERL5LIB = join ':' => $PERL5LIB, @libs; | |
} | |
my ( undef, $tempfile ) = tempfile(); | |
my $perl = "PERL5LIB=$PERL5LIB perl "; | |
my $command = "$perl -c $prog 2>$tempfile 1>$tempfile"; | |
# if anything goes to STDERR and the program completes successfully, don't | |
# show anything because we're going to rerun with warnings::unused and we | |
# don't need to duplicate the messages to STDERR | |
my $error = system($command); | |
$error and do { | |
print io($tempfile)->slurp; | |
exit $error; | |
}; | |
$command = "$perl -Mwarnings::unused -MVi::QuickFix -c $prog"; | |
system($command); | |
if ($critic) { | |
my $output = join "" => `perlcritic --quiet --verbose "%f:%l:%m\\n" $prog`; | |
if ( $output ) { | |
print $output; | |
$output >> io('errors.err'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment