Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Perl module to get warn or die to render as HTML

by jira0004 (Monk)
on Sep 25, 2006 at 21:55 UTC ( [id://574838]=perlquestion: print w/replies, xml ) Need Help??

jira0004 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

Here is the thing, I am working on a Perl CGI that some one else wrote. The thing that I want is a Perl module, either in the standard distribution, or from CPAN that causes a die or a warn to render as nice HTML in a web-browser for debugging purposes.

I realize I could put the CGI code in an eval block, catch the exception generated by die and then create the HTML myself, but I was wondering if there was any nice Perl module that happened to do such a thing for me. Does any one have any ideas about such a Perl module?

Thanks

  • Comment on Perl module to get warn or die to render as HTML

Replies are listed 'Best First'.
Re: Perl module to get warn or die to render as HTML
by Joost (Canon) on Sep 25, 2006 at 21:58 UTC
      And don't forget to configure things so it is turned on in development and off in production. Else you'll provide an ideal tool to help attackers debug their attacks against any flaws that they find in your site.
        Great point. At my org we have a web server error log and the number of scripts that 'use warnings' that are in production is outrageous.
        So also turn off warnings and debugging in general in production so that other web programmers don't have to sift through 100+ lines of Net::FTP
        debug output to find the line in the error log from their own script.

        T

        _________________________________________________________________________________

        I like computer programming because it's like Legos for the mind.

Re: Perl module to get warn or die to render as HTML
by blue_cowdawg (Monsignor) on Sep 27, 2006 at 20:37 UTC
        causes a die or a warn to render as nice HTML in a web-browser for debugging purposes

    Check this out:

    #!/usr/bin/perl -w use strict; use CGI qw/ :all /; $SIG{__DIE__} = \&htmldie; open FIN,"< some_stupid_nonexistant_file.or.other" or die $!; my $line=<FIN>; exit(0); sub htmldie { my @args=@_; print header,start_html,pre(join("\n",@args)),end_html; exit(0); }

    I found this by doing a quick check of perldoc -f die which shows this pattern.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://574838]
Approved by Joost
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found