Professional Web Applications Themes

$SIG{__DIE__} doesn't make sense when using CGI::Carp - PERL Miscellaneous

Me and my cgi-script have the following problem. I'm using the package CGI::Carp (which installs internally some $SIG{__DIE___} handlers). In addition my script defines an own handler methods for $SIG{__DIE__}. My suggestion was, that my definition is "overwritting" the defintion of CGI::Carp. But that doesn't seem to be right. Here is my example: Perl-Skript: --------------- use CGI::Carp; $SIG{__DIE__} = \&myDie; sub myDie { print "<b>ERROR-Message: $_[0]</b>"; } eval { print "Content-type: text/html\n\n"; print "Just some text<br>"; die "I'm dying. Please help!"; print "some text never shown"; }; When running the skript I get the following message (notice the wrong module ...

  1. #1

    Default $SIG{__DIE__} doesn't make sense when using CGI::Carp

    Me and my cgi-script have the following problem.

    I'm using the package CGI::Carp (which installs internally some
    $SIG{__DIE___} handlers).
    In addition my script defines an own handler methods for
    $SIG{__DIE__}.

    My suggestion was, that my definition is "overwritting" the defintion
    of CGI::Carp.
    But that doesn't seem to be right.

    Here is my example:

    Perl-Skript:
    ---------------
    use CGI::Carp;

    $SIG{__DIE__} = \&myDie;
    sub myDie {
    print "<b>ERROR-Message: $_[0]</b>";
    }
    eval {
    print "Content-type: text/html\n\n";
    print "Just some text<br>";

    die "I'm dying. Please help!";

    print "some text never shown";
    };


    When running the skript I get the following message (notice the wrong
    module and line number)

    Just some text
    ERROR-Message: I'm dying. Please help! at
    d:/dev_soft/apache/Perl/lib/CGI/Carp.pm line 301.


    So it seems that the CGI:Carp definition of $SIG{__DIE__} is somewhat
    alive. It is called before my own signal-handler is activated.

    What is the way to undo the CGI::Carp handler definitions?
    Just wanna know 1.) why CGI::Carp::die handler is still active when I
    overwrite it with my own handler and 2.) how I can
    prevent it?

    By the way:
    The above example-script simplifies the core problem for discussion!
    In real life there are two scripts installed running under mod_perl.
    One of it uses CGI::Carp. The otherone defines the signal handler.


    Thanks and Greetings!
    Jo Oberman Guest

  2. #2

    Default Re: $SIG{__DIE__} doesn't make sense when using CGI::Carp

    Jo Oberman wrote:
    > When running the skript I get the following message (notice the wrong
    > module and line number)
    >
    > Just some text
    > ERROR-Message: I'm dying. Please help! at
    > d:/dev_soft/apache/Perl/lib/CGI/Carp.pm line 301.
    To me this seems alright: the exception is _raised_
    ( by calling die()) in Carp.pm, but it is still
    _your_ handler that is called.

    Or am I wrong?

    Amir


    Amir Kadic Guest

  3. #3

    Default Re: $SIG{__DIE__} doesn't make sense when using CGI::Carp

    On Fri, 12 Sep 2003 22:37:34 +0200
    Jo Oberman <johanobermgmx.de> wrote:
    <snip>
    > $SIG{__DIE__} = \&myDie;
    > sub myDie {
    > print "<b>ERROR-Message: $_[0]</b>";
    Can be simplified and changed to:
    $SIG{__DIE__} = sub{print "<b>ERROR-Message: $_[0]</b>\n";};

    Notice the new line character at the end of the line. If it is
    omited, then the line number of the error will be printed. Bad move
    for a CGI script. The user does _NOT_ need that information.
    > }
    > eval {
    > print "Content-type: text/html\n\n";
    > print "Just some text<br>";
    >
    > die "I'm dying. Please help!";
    >
    > print "some text never shown";
    > };
    Why are you doing an 'eval' here? And, again, no new line in the
    'die' statement - bad move.

    If the 'eval' is done away with, you get your message .... if you use
    the 'eval', you get your message .. so, what's the question again?

    <snip>
    > What is the way to undo the CGI::Carp handler definitions?
    > Just wanna know 1.) why CGI::Carp::die handler is still active when
    > I overwrite it with my own handler and 2.) how I can
    > prevent it?
    >
    > By the way:
    > The above example-script simplifies the core problem for discussion!
    > In real life there are two scripts installed running under mod_perl.
    > One of it uses CGI::Carp. The otherone defines the signal handler.
    Use one or the other, but not both. I posted a similar question about
    2 months ago. That's the way I handled it - because the effort to go
    through was too much (although, my question related to a script having
    a signal handler and the moudle it used and _I_ wrote used a signal
    handler and one was over riding the other).

    You can override one in favor of the other, but, IMHO, it's more
    effort than it's worth.

    An alterante method that _may_ work is ...

    ==untested==
    BEGIN{
    $SIG{__DIE__} = sub { print "<b>ERROR-Message: $_[0]</b>"; };
    }
    use CGI::Carp;

    eval{
    print "Content-type: text/html\n\n";
    print "Just some text<br>";

    die "I'm dying. Please help!";

    print "some text never shown";
    };

    if($){die "DIED";}

    Here, you're using the BEGIN block to set up the error handling. It
    _may_ do what you want it to do. Although, my first thoughts should
    apply - use one or the other.

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
    for more information.

    a fortune quote ...
    Certainly there are things in life that money can't buy, but it's
    very funny-- Did you ever try buying them without money? --
    Ogden Nash
    James Willmore Guest

  4. #4

    Default Re: $SIG{__DIE__} doesn't make sense when using CGI::Carp

    >To me this seems alright: the exception is _raised_
    >( by calling die()) in Carp.pm, but it is still
    >_your_ handler that is called.
    >
    >Or am I wrong?
    Sorry, you are wrong.
    I'm reasing the exception in my example. The message should
    be something like
    ERROR-Message: I'm dying. Please help! at
    d:/dev_soft/myDir/Perl/example.pl line 19

    >Jo Oberman wrote:
    >
    >> When running the skript I get the following message (notice the wrong
    >> module and line number)
    >>
    >> Just some text
    >> ERROR-Message: I'm dying. Please help! at
    >> d:/dev_soft/apache/Perl/lib/CGI/Carp.pm line 301.
    >
    >To me this seems alright: the exception is _raised_
    >( by calling die()) in Carp.pm, but it is still
    >_your_ handler that is called.
    >
    >Or am I wrong?
    >
    >Amir
    >
    Jo Oberman Guest

  5. #5

    Default Re: $SIG{__DIE__} doesn't make sense when using CGI::Carp

    Jo Oberman <johanobermgmx.de> wrote in message news:<p8b4mv4k3mmqno0p02139v63f0m9shig7c4ax.com>. ..
    > Me and my cgi-script have the following problem.
    >
    > I'm using the package CGI::Carp (which installs internally some
    > $SIG{__DIE___} handlers).
    this is only partly true. CGI::Carp only overwrites $SIG{__DIE__} if
    you use 'fatalsToBrowser'. check the source (inside the import()
    function) of CGI::Carp to see what i mean.
    > In addition my script defines an own handler methods for
    > $SIG{__DIE__}.
    >
    > My suggestion was, that my definition is "overwritting" the defintion
    > of CGI::Carp.
    > But that doesn't seem to be right.
    >
    > Here is my example:
    >
    > Perl-Skript:
    > ---------------
    > use CGI::Carp;
    >
    > $SIG{__DIE__} = \&myDie;
    > sub myDie {
    > print "<b>ERROR-Message: $_[0]</b>";
    > }
    > eval {
    > print "Content-type: text/html\n\n";
    > print "Just some text<br>";
    >
    > die "I'm dying. Please help!";
    >
    > print "some text never shown";
    > };
    >
    >
    > When running the skript I get the following message (notice the wrong
    > module and line number)
    >
    > Just some text
    > ERROR-Message: I'm dying. Please help! at
    > d:/dev_soft/apache/Perl/lib/CGI/Carp.pm line 301.
    >
    >
    > So it seems that the CGI:Carp definition of $SIG{__DIE__} is somewhat
    > alive. It is called before my own signal-handler is activated.
    >
    > What is the way to undo the CGI::Carp handler definitions?
    technically, you can't. because CGI::Carp does its magic by
    overwritting the global die function with:

    *CORE::GLOBAL::die = \&CGI::Carp::die;

    once this is done, you can never get back the real die function.
    CGI::Carp does store the global die function inside one of its
    function named realdie().
    > Just wanna know 1.) why CGI::Carp::die handler is still active when I
    > overwrite it with my own handler and
    your $SIG{__DIE__} handler is still active and CGI::Carp never
    overwrites your handler. it's just that your die() function never
    really reach the global die function anymore so your handler is never
    called. the die function you call in your script goes to
    CGI::Carp::die which does not involve your handler.
    > 2.) how I can prevent it?
    you can't but you can fake it by saying:

    use CGI::Carp;
    use subs qw(die);

    and then provide your own version of die instead:

    sub die{
    #--
    #-- do whatever you want to do here.
    #--
    exit(1);
    }

    die "now this goes to the above die function instead, not
    CGI::Carp::die\n";

    you can, of course, hack the CGI::Carp code yourself to prevent that
    from happening but are you sure you don't think CGI::Carp is doing the
    Right Thing?
    David Guest

  6. #6

    Default Re: $SIG{__DIE__} doesn't make sense when using CGI::Carp

    [A complimentary Cc of this posting was sent to
    David
    <dz1976hotmail.com>], who wrote in article <c27dfcf4.0309131952.332067f1posting.google.com >:
    > > What is the way to undo the CGI::Carp handler definitions?
    >
    > technically, you can't. because CGI::Carp does its magic by
    > overwritting the global die function with:
    >
    > *CORE::GLOBAL::die = \&CGI::Carp::die;
    >
    > once this is done, you can never get back the real die function.
    Eh??? What about CORE::die()?

    Ilya
    Ilya Zakharevich Guest

Similar Threads

  1. does it make sense to buffer a live stream
    By Duke_of_URL in forum Macromedia Flash Flashcom
    Replies: 1
    Last Post: May 12th, 07:41 PM
  2. Does using cold fusion make sense compared to JSP?
    By kedward in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: February 26th, 04:50 PM
  3. MX2004: projector MB... make sense of this?
    By smack in forum Macromedia Director Basics
    Replies: 3
    Last Post: February 24th, 03:33 PM
  4. Incorrect Syntax near "," doesnt make sense
    By J. Muenchbourg in forum ASP
    Replies: 5
    Last Post: September 24th, 11:01 AM
  5. Having problems with an IF statement, just doesn't make sense
    By Nadim Attari in forum PHP Development
    Replies: 0
    Last Post: July 7th, 12:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139