]> git.donarmstrong.com Git - perltidy.git/blob - examples/perltidy_hide.pl
New upstream version 20210717
[perltidy.git] / examples / perltidy_hide.pl
1 #!/usr/bin/perl
2 package main;
3 use Perl::Tidy;
4
5 # Note: This program is no longer necessary because this capability is now
6 # built into perltidy, but the prograim is a good example of the use of
7 # prefilters and postfilters.
8
9 =pod
10
11 Hide sections of as script from perltidy which are between special comments,
12 like this:
13
14 #<<V
15
16 anything between '#<<V' and '#>>V' is hidden from perltidy but seen by perl
17
18 #>>V
19
20 This works by converting #<<V into =pod and #>>V into =cut before
21 processing, and then converting back after processing.
22
23 This was created for issue git #65. 
24
25 =cut
26
27 my $arg_string = undef;
28
29 exit Perl::Tidy::perltidy(
30     argv      => $arg_string,
31     prefilter => sub {
32         $_ = $_[0];
33         s/^(#<<V\b.*)$/=pod $1/gm;
34         s/^(#>>V\b.*)$/=cut $1/gm;
35         return $_;
36     },
37     postfilter => sub {
38         $_ = $_[0];
39         s/^=pod (#<<V\b)/$1/gm;
40         s/^=cut (#>>V\b)/$1/gm;
41         return $_;
42     },
43 );