"Fossies" - the Fresh Open Source Software Archive

Member "Perl-Tidy-20210717/examples/perltidy_hide.pl" (19 Jun 2021, 933 Bytes) of package /linux/misc/Perl-Tidy-20210717.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 );