Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
Sometimes when I'm writing POD, I find that I want something like this:
use Test::More 'no_plan';
ok 1, '"1" is true';
is "foo", "foo", '"foo" equals itself';
__END__
ok 1 - "1" is true
ok 2 - "foo" equals itself
1..2
In other words, I want a snippet of code with the output displayed after the __END__ block. However, that means copying the code to a file, pasting the code, fixing the inevitable errors, rerunning, copying the output, putting vim in paste mode, typing the __END__ token, pasting in the output and putting vim back in nopaste mode.
That's a pain. Now I can just type
vnoremap <silent>
,rs :!perl ~/bin/eval<cr>
And ~/bin/eval script is:
#!/usr/bin/env perl
use strict;
use warnings;
use File::Temp 'tempfile';
# create a temporary perl script file
my ( $fh, $snippet ) = tempfile(
'eval_XXXX',
SUFFIX => '.pl',
DIR => '/var/tmp'
);
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, " __END__\n";
my $output = ' ' . qx{ $perl $snippet 2>&1 };
$output =~ s/\n/\n/g;
print $output;
That will run the snippet and automatically put the results after an __END__ token. This is a very dangerous (and fragile) technique, so use it with care.
Nice, but Name Clash (Score:1)
Hey, that's nifty.
But having ~/bin/eval may get confusing, the name clashing with the buit-in shell command
eval.perlevalwould be less confusing (and a longer name doesn't really matter, since your mapping does the typing for you).Re: (Score:2)
Ah, good point. I'll make a change locally. Thanks!
Nifty (Score:1)
Nice idea. I used it in my .emacs but slightly differently. This evals the contents of the current region w/ perl-run-snippet-command and inserts it afterward as comments.