in reply to Setting up signal handlers for an object with access to $self
For example, if I have this code:
and I run this little script, then give it a USR1 signal, the only object that's ever going to catch that signal will be obj2. See what I'm saying?package Obj; sub new { my $class = shift; my $self = { @_ }; bless $self, $class; $self->set_signal_handlers; $self; } sub name { shift->{'name'}; } sub set_signal_handlers { my $self = shift; $SIG{USR1} = sub { $self->handle_USR1() } } sub handle_USR1 { my $self = shift; print "handling USR1 for ", $self->name, "\n"; } package main; my $obj1 = new Obj(name => 'obj1'); my $obj2 = new Obj(name => 'obj2'); while (1) { }
All the same, it's a nice little method. :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Setting up signal handlers for an object with access to $self
by ZZamboni (Curate) on Apr 20, 2000 at 01:39 UTC | |
by chromatic (Archbishop) on Apr 20, 2000 at 02:41 UTC |