in reply to Demonize Module, What are your thoughts?

These lines seem out of place:

use DBI; use LWP::Simple;

Documentation should be POD (perlpod).

Your accessor/mutator pattern is repeated. This is something a nice little framework could help with. See Tiny Frameworks or go all out with Moose.

It's nice to use signal names rather than numbers with kill.

In your log messages, it would be useful to include $$ (and use English, so you can say $PID instead of $$).

Instead of forcing me to subclass, allow me to pass in a code reference for run().

It'd be nice if I could tell it I don't want it to send email rather than forcing it to die by giving some bogus email address.

If you're doing logging, you might consider Log::Log4perl.

I've used Proc::Daemon for this before.

Replies are listed 'Best First'.
Re^2: Demonize Module, What are your thoughts?
by halfbaked (Sexton) on Dec 17, 2008 at 02:06 UTC
    Ok I've refactored the code quite a bit. I'm totally onboard with Moose. I've implemented YAML config files and cleaned up the code a bit.

      I haven't read through the rewrite.

      What I meant about passing a code reference is using an anonymous sub.

      # create code reference my $anon_sub = sub { print "Hello world!\n" }; # execute the code $anon_sub->();

      For Daemonize, it would look something like...

      my $run = sub { die 'unfinished' }; my $d = Daemonize->new( run => $run ); # later, inside Daemonize $self->{run}->( $self );

      I think it would be a good idea to pass the Daemonize object to the sub itself (as I did in the example) so it can call methods on it (like logging) if it wants to.

      I'm not quite clear about what you're trying to do with $SIG{__DIE__}, but you might want an END block or a DESTROY method instead.

        Thanks that anonymous sub makes sense.

        What I'm trying to do with $SIG{__DIE__} is to run some code when the daemon dies to let me know it died. I just want to know if the daemon dies unexpectedly (perhaps Demonize isn't the best place to put this functionality).