You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by James G Smith <JG...@JameSmith.Com> on 2000/04/04 08:46:21 UTC

Re: Custom $SIG{__DIE__} problem (and "I'm glad to be back")

"Russell D. Weiss" <rw...@inforelay.com> wrote:
>
>So, onto the problem.  Within the constructor for the wrapper object, I want
>to do:
> bless $self, $class;
> $main::SIG{'__DIE__'} = $self->custom_die;

Try

  bless $self, $class;
  $main::SIG{'__DIE__'} = sub { $self->custom_die(@_) };

This will make sure $self is the first argument to custom_die, it
will be the same $self as when the signal handler was called, and
the signal handling mechanism won't have to know about it.
------------------------------------+-----------------------------------------
James Smith - jgsmith@jamesmith.com | http://www.jamesmith.com/
            jsmith@sourcegarden.org | http://sourcegarden.org/
              jgsmith@tamu.edu      | http://cis.tamu.edu/systems/opensystems/
------------------------------------+------------------------------------------

Re: Custom $SIG{__DIE__} problem (and "I'm glad to be back")

Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "James" == James G Smith <JG...@JameSmith.Com> writes:

James> "Russell D. Weiss" <rw...@inforelay.com> wrote:
>> 
>> So, onto the problem.  Within the constructor for the wrapper object, I want
>> to do:
>> bless $self, $class;
>> $main::SIG{'__DIE__'} = $self->custom_die;

James> Try

James>   bless $self, $class;
James>   $main::SIG{'__DIE__'} = sub { $self->custom_die(@_) };

James> This will make sure $self is the first argument to custom_die, it
James> will be the same $self as when the signal handler was called, and
James> the signal handling mechanism won't have to know about it.

But ensure that $self is a lexical ("my") variable.  If it's a package
variable (even with local()) this will not work, because a closure
reference will not get made.  You also don't need the $main:: because
%SIG (actually *SIG) is forced to main::.

Just another couple of Perl tips from someone who wrangles Perl all day
every day... :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

RE: Custom $SIG{__DIE__} problem (and "I'm glad to be back")

Posted by "Russell D. Weiss" <rw...@inforelay.com>.
Thanks James,

Great little trick.... It worked!

Thanks for the help,
Russ

Russell Weiss
Founder and Technical Manager
InfoRelay Online Systems, Inc.
http://www.InfoRelay.net/
 


> Try
> 
>   bless $self, $class;
>   $main::SIG{'__DIE__'} = sub { $self->custom_die(@_) };
> 
> This will make sure $self is the first argument to custom_die, it
> will be the same $self as when the signal handler was called, and
> the signal handling mechanism won't have to know about it.
> ------------------------------------+-----------------------------
> ------------
> James Smith - jgsmith@jamesmith.com | http://www.jamesmith.com/
>             jsmith@sourcegarden.org | http://sourcegarden.org/
>               jgsmith@tamu.edu      | 
> http://cis.tamu.edu/systems/opensystems/
> ------------------------------------+-----------------------------
> -------------
>