Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
package Template::Plugin::PerlTidy; use strict; use Template::Plugin::Filter; use Perl::Tidy; use base qw( Template::Plugin::Filter ); use vars qw($VERSION); $VERSION = 0.01; use vars qw( $DYNAMIC ); $DYNAMIC = 1; =pod =head1 NAME Template::Plugin::PerlTidy - Perl::Tidy filter =head1 SYNOPSIS # HTML Syntax Coloring, no reformatting [% USE PerlTidy 'html' 'nnn' 'pre' %] [% FILTER $PerlTidy %] #!/usr/bin/perl -w use strict; my@foo=(1,2,'a',4); for(1,3,5){print" $_\n"} my %hash =( 1=>'foo',foo=>'bar',); [% END %] # Chained filter, code reformatting and syntax coloring [%- USE PerlTidy -%] [%- FILTER $PerlTidy 'html' 'nnn' -%] [%- FILTER $PerlTidy i=10 -%] ... perl code goes here ... [%- END -%] [%- END -%] =head1 DESCRIPTION This modules is a Template Toolkit Filter for Perl::Tidy. It can be us +ed to automatically display coloured and formatted perl code in web pages +. =head1 OPTIONS All the options available in perltidy should be also available in this plugin. The options defined in Perl::Tidy::perltidy() are also supported (C<stderr>, C<perltidyrc>, C<logfile>, C<errorfile>). The C<source> an +d <destination> options are handled by the filter. Note that options which does not take any arguments (like -html or -pr +e) should be enclosed in quotes (i.e. C<[% USE PerlTidy 'html' %]>), and options which take an argument are not enclosed in quotes (i.e. C<[% U +SE PerlTidy i=8 %]>). =cut sub filter { my ( $self, $text, $args, $conf ) = @_; $args = $self->merge_args($args); $conf = $self->merge_config($conf); my %options = %{$conf}; my ( $stderr, $perltidyrc, $logfile, $errorfile ) = @options{qw( stderr perltidyrc logfile errorfile )}; delete @options{qw( stderr perltidyrc logfile errorfile )}; foreach my $args ( @{$args} ) { $options{$args} = undef unless exists $options{$args}; } my $argv; foreach my $key ( keys %options ) { $argv .= $options{$key} ? qq' -$key="$options{$key}"' : " -$ke +y"; } my $formated; perltidy( source => \$text, destination => \$formated, argv => $argv, stderr => $stderr, perltidyrc => $perltidyrc, logfile => $logfile, errorfile => $errorfile, ); return $formated; } 1; __END__ =pod =head1 AUTHOR Briac Pilpré <> =head1 COPYRIGHT This module is distributed under the same terms as perl itself. =head1 SEE ALSO Template::Plugin::Filter, Perl::Tidy =cut

In reply to Template::Plugin::PerlTidy by OeufMayo

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2018-05-26 06:41 GMT
    Find Nodes?
      Voting Booth?