X-Git-Url: https://git.donarmstrong.com/?p=perltidy.git;a=blobdiff_plain;f=examples%2Fperltidy_hide.pl;fp=examples%2Fperltidy_hide.pl;h=d30efe70f8fd1ce16981387e684c5f5c1049db6a;hp=0000000000000000000000000000000000000000;hb=57d829ae0e2c75828f8ecc9c7139579350927dbc;hpb=7f27e55dce5925b2bbe8fcfca64f385e917a52be diff --git a/examples/perltidy_hide.pl b/examples/perltidy_hide.pl new file mode 100755 index 0000000..d30efe7 --- /dev/null +++ b/examples/perltidy_hide.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl +package main; +use Perl::Tidy; + +# Note: This program is no longer necessary because this capability is now +# built into perltidy, but the prograim is a good example of the use of +# prefilters and postfilters. + +=pod + +Hide sections of as script from perltidy which are between special comments, +like this: + +#<>V' is hidden from perltidy but seen by perl + +#>>V + +This works by converting #<>V into =cut before +processing, and then converting back after processing. + +This was created for issue git #65. + +=cut + +my $arg_string = undef; + +exit Perl::Tidy::perltidy( + argv => $arg_string, + prefilter => sub { + $_ = $_[0]; + s/^(#<>V\b.*)$/=cut $1/gm; + return $_; + }, + postfilter => sub { + $_ = $_[0]; + s/^=pod (#<>V\b)/$1/gm; + return $_; + }, +);