I currently have this bit of code in my autohandler file for indeng all the HTML that is outputted with the HTML tidy utility, First off to capture all of the page and send it off to work:
<%filter> s/^(.*?)$/tidy($1)/se; $filter
And the actual sub:
sub tidy { my ($output) = @_; use IPC::Open2; open2 *READER, *WRITER, "/usr/bin/tidy -i -w 0 -q -raw 2>/dev/nu +ll"; print WRITER $output; close WRITER; undef $/; $output = <READER>; close READER; return $output; }
This code seems to only be working in a standalone script on the system but doesn't when trying to use it with Mason. So I had to come up with an alternate method for the moment with:
sub tidy { my ($output) = @_; # Try to generate and unique filename using session_id and appen +ding # some more randomly generated stuff using md5_hex(). The same w +ay that # the session_id is generated in Apache::Session::Generate::MD5. my $tmp_file = "/tmp/$session{'_session_id'}-" . Digest::MD5::md +5_hex(Digest::MD5::md5_hex(time().{}. rand(). $$)); return "output file not correct ($tmp_file)." unless $tmp_file = +~ /^\/tmp\/[\w-]+$/; open TMP, ">$tmp_file" or die $!; chmod 0600, $tmp_file; print TMP $output; close TMP; $output = `/usr/bin/tidy -i -w 0 -q -raw $tmp_file 2>/dev/null`; unlink $tmp_file; return $output; }
Of couse this just a cheap hack of how I wanted it to work in the first place. So any help in getting the first sub working would be greatly appreciated. Thanks.

In reply to Tidy with HTML::Mason by rendler

Title:
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, details, 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, summary, 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.