* Lincoln A. Baxter <[EMAIL PROTECTED]> [2004-01-12 10:02]:
> On Sun, 2004-01-11 at 15:50, Tim Bunce wrote:
> > It might also be worth adding some mechanism to integrate with Sys::Signal
> > http://search.cpan.org/src/DOUGM/Sys-Signal/Signal.pm
> 
> I took a look that this. It is little bit of perlxs glue which
> uses perl's internals to set signal handlers, and have them
> restored when the object returned gets destroyed as it goes out
> of scope.   It does not help us with our problem however, as it
> just does what perl does. I see no real benefit to this over:
> 
>    eval {
>       local $SIG{ALRM} = sub { ... };
>    }
> 
> Perhaps there was a time when the above trick was not well
> known, and Sys::Signal was implemented to do that.  After
> looking at the truss and strace outputs for the way the above
> code works, I would say that Sys::Signal is pretty unnecessary.  

Actually, I think it is much worth pursuing, given this:

* Lincoln A. Baxter <[EMAIL PROTECTED]> [2004-01-11 15:19]:
> This module is almost as convenient to use as the above:
>    #timeout a system call:
>    use POSIX ':signal_h' ;
>    use SignalHandler qw( set_handler );
> 
>    eval {
>       local $SIG{ALRM};
>       set_handler( 'mypackage::mysubname' ,SIGALRM );
>       alarm(2)
>       #... do something you want to timeout for instance:
>       $dbh = DBI->connect( "dbi:Oracle:$dbn", $usr, $pwd 
>          ,{  AutoCommit=>$self->auto_commit() 
>             ,RaiseError=>1
>             ,PrintError=>$self->print_err() 
>           } );
>       alarm(0);
>    };
>    #perl clears the handler here... because of the local dec above
>    alarm(0); 
>    if ( $@ ) ...

IMO it would be much neater not to have to separately localize
$SIG{ALRM} but to have restoration optionally done by your module
on request. I believe the clearest way to handle the syntax would
be a check for context in sig_set_handler() and returning an
object that auto-restores the signal in question on destruction
only if the context is not void.

That way people could write

    my $restore = sig_set_handler( ... );

when they want it undone and simply

    sig_set_handler( ... );

when they do want the change to persist until explicit change.

-- 
Regards,
Aristotle
 
"If you can't laugh at yourself, you don't take life seriously enough."

Reply via email to