Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Saturday November 14, 2009
05:25 AM

Vim: Does Your Pod Have Valid Perl?

[ #39896 ]

After writing some vim code to run your POD code, I realized I needed another snippet to simply tell me if my POD code compiled (without running it). The vim mapping:

vnoremap <silent> <leader>c :!perl ~/bin/validperl<cr>

Select a region of Perl code, hit ",c" (or whatever your leader is) and if no compilation errors are detected, you'll see no change. Otherwise, they will be added after an "__END__" token. Here's the code for validperl:

#!/usr/bin/env perl

use strict;
use warnings;
use File::Temp 'tempfile';

my $tmpdir = '/var/tmp';

my ( $fh, $snippet ) = tempfile(
    'eval_XXXX',
    SUFFIX => '.pl',
    DIR    => $tmpdir,
);
my $code = do { local $/; <STDIN> };
print $fh $code or die "Could not print code to ($snippet): $!";
close $fh or die "Could not close ($snippet): $!";

my $perl = $^X;
print $code;
my $output = qx{ $perl -Ilib -c $snippet 2>&1 };
exit if $output =~ m{^$tmpdir/eval_\w+.pl syntax OK$};
$output =~ s/\n/\n /g;
print " __END__\n $output";

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • This is not working with incomplete sample code, is it? Code that does not include the necessary (but trivial) use Foo::Bar lines, or object instantiation (Foo::Bar->new)?

    Just because code is incomplete, doesn't mean that it's wrong.

    And adding redundant code is not making examples clearer.

    • It's certainly not perfect for all things and that's unfortunate. I don't know of any other way around that. I've thought of various tricks (s/use/require/), but that breaks other things. In short, it won't work for everyone, but if it does, it's a nice check.