Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Duplicate CGI::Carp Output

by InfiniteSilence (Curate)
on Jul 17, 2016 at 01:00 UTC ( #1167895=perlquestion: print w/replies, xml ) Need Help??

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

When I use the set_die_handler I get duplicate output (it is not STDERR output because I redirect that in the script):

#!/usr/bin/perl -w use strict; use CGI::Carp qw|set_die_handler|; use Foobar; BEGIN { sub extra_special_die_handler { my ($msg) = shift; print qq|Content-Type: text/html\n\n|; print qq|<html><body>|; print qq|<h1>Error</h1>|; print qq|$msg</body></html>|; } set_die_handler(\&extra_special_die_handler); } open( STDERR, '>>', 'testerror.log'); my $foo = Foobar->new(); print $foo->fooish(); print qq|\n\nall okay\n|; close(STDERR); in a separate file:

package Foobar; sub new { return bless {}; } sub fooish { my ($self, $somevar) = @_; if ($somevar) { return "Empty nest!"; } else { die "I died here!"; } }


Content-Type: text/html <html><body><h1>Error</h1>I died here!</body></html>Content-Type: text +/html <html><body><h1>Error</h1>[Sat Jul 16 19:57:35 2016] +I died here! at line 12. </body></html>

Any ideas on how I can just get one or the other output?

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re: Duplicate CGI::Carp Output ( set_die_handler, $main::SIG{__DIE__} )
by Anonymous Monk on Jul 17, 2016 at 01:43 UTC

    I've never seen someone try to use set_die_handler, so if you're trying to do it all yourself, forget all about CGI::Carp and use do

    BEGIN { $main::SIG{__DIE__} = \&extra_special_die_handler; }

    The double/output is bugs in CGI::Carp

    its either inadequate documentation explaining how to best use this feature

    logic error in "sub CGI::Carp::die" in that it realdie's after calling die_handler even though that will just call diehandler again

    no signal/sentinel to die_handler that its being called by realdie

    or still overriding CORE::die with CGI::Carp::die despite using set_die_handler, so having die_handler get called twice


    could be argued (i feel) set_die_handler should not exist at all -- $main::SIG{__DIE__} is known/documented in perlvar

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1167895]
Approved by stevieb
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2022-01-17 05:27 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (51 votes). Check out past polls.