rendler has asked for the wisdom of the Perl Monks concerning the following question:
And the actual sub:<%filter> s/^(.*?)$/tidy($1)/se; $filter
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) = @_; 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; }
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.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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tidy with HTML::Mason
by Fletch (Bishop) on May 10, 2002 at 07:08 UTC | |
|
Re: Tidy with HTML::Mason
by IlyaM (Parson) on May 10, 2002 at 11:12 UTC |