Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I like this quite a lot... only problem being that signals are unique to processes, not objects, so if you try to instantiate more than 1 of your objects and attach it to a signal handler, only the last object attached will actually have the signal handler installed.

For example, if I have this code:

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) { }
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?

All the same, it's a nice little method. :)

In reply to RE: Setting up signal handlers for an object with access to $self by btrott
in thread Setting up signal handlers for an object with access to $self by ZZamboni

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-17 14:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found