<%filter> s/^(.*?)$/tidy($1)/se; $filter #### sub tidy { my ($output) = @_; use IPC::Open2; open2 *READER, *WRITER, "/usr/bin/tidy -i -w 0 -q -raw 2>/dev/null"; print WRITER $output; close WRITER; undef $/; $output = ; close READER; return $output; } #### sub tidy { my ($output) = @_; # Try to generate and unique filename using session_id and appending # some more randomly generated stuff using md5_hex(). The same way that # the session_id is generated in Apache::Session::Generate::MD5. my $tmp_file = "/tmp/$session{'_session_id'}-" . Digest::MD5::md5_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; }