leocharre has asked for the wisdom of the Perl Monks concerning the following question:

I was reading about class methods- (methods that instead of managing object instance data, set classwide data, so these values are the same accross all instances). So, I was wondering.. couldn't you do some IPC with this? Setting class data is accross the whole system, right? If an instance of Fax::Job is started at 4pm, and at 5pm I start another and tell the Fax::Job class that it should finish off anything going on and exit.. it aplies to all instances?

I haven't seen much about this. It obviously would only be useful for specific needs- as the scope is total on the host machine(?).

If this kind of thing even works - Would this fall under the category of 'clever'- and thus more a 'programmer' adventure more than a 'developer' activity?

Replies are listed 'Best First'.
Re: Doing IPC via class methods?
by shmem (Chancellor) on Jul 24, 2007 at 14:37 UTC
    Setting class data is accross the whole system, right?

    Only inside the same process, lest you stuff your class data into shared memory somehow and make sure it is not overwritten by another process at class initialization.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Ahh.. makes a ton of sense. Changes everything. Sigh. I feel like when I was little and I realized dirt and water will *not* make chocolate cake.

        You may not be able to do IPC for free with class methods, but you could use a disk based cache, a database or perhaps open a unix socket to a daemon lurking in within your class to do the IPC...

        Wrapping stuff in classes can still be a good idea, and if you are keen on the idea there's no reason you can't have a go at it.

        You've got the specs for your cake, just go and get the chocolate and see what you can whip up!

        (obligatory pun about fork)

        @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Re: Doing IPC via class methods?
by ikegami (Patriarch) on Jul 24, 2007 at 16:07 UTC

    There's no need for magic. I think your needs would be adequately served by a service.

    Say you call your service/daemon "FaxIt"*,

    package FaxIt::Client; sub new { if (...[service is running]...) { if (...[service is non-responsive]...) { ...[restart the service]... } } else { ...[start the service]... } } sub send { ... ...[send request to the service]... ... }

    * — Any ressemblance to another product's name is purely coincidental.