2 # Copyright (C) 2006, David Muir Sharnoff <muir@idiom.com>
4 package Daemon::Generic::Event;
8 require Daemon::Generic;
12 our @ISA = qw(Daemon::Generic Exporter);
13 our @EXPORT = @Daemon::Generic::EXPORT;
18 local($Daemon::Generic::caller) = caller() || 'main';
19 local($Daemon::Generic::package) = __PACKAGE__;
20 Daemon::Generic::newdaemon(@_);
26 my $reload_event = Event->signal(
28 desc => 'reload on SIGHUP',
31 $self->gd_reconfig_event;
32 $self->{gd_timer}->cancel()
34 $self->gd_setup_timer();
37 my $quit_event = Event->signal(
39 cb => sub { $self->gd_quit_event; },
46 if ($self->can('gd_run_body')) {
47 my $interval = ($self->can('gd_interval') && $self->gd_interval()) || 1;
48 $self->{gd_timer} = Event->timer(
49 cb => [ $self, 'gd_run_body' ],
50 interval => $interval,
59 $self->gd_setup_timer();
66 print STDERR "Quitting...\n";
74 Daemon::Generic::Event - Generic daemon framework with Event.pm
78 use Daemon::Generic::Event;
80 @ISA = qw(Daemon::Generic::Event);
88 Daemon::Generic::Event is a subclass of L<Daemon::Generic> that
89 predefines some methods:
95 Setup a periodic callback to C<gd_run_body()> if there is a C<gd_run_body()>.
96 Call C<Event::loop()>.
98 =item gd_setup_signals()
100 Bind SIGHUP to call C<gd_reconfig_event()>.
101 Bind SIGINT to call C<gd_quit_event()>.
105 To use Daemon::Generic::Event, you have to provide a C<gd_preconfig()>
106 method. It can be empty if you have a C<gd_run_body()>.
108 Set up your own events in C<gd_preconfig()> and C<gd_postconfig()>.
110 If you have a C<gd_run_body()> method, it will be called once per
111 second or every C<gd_interval()> seconds if you have a C<gd_interval()>
112 method. Unlike in L<Daemon::Generic::While1>, C<gd_run_body()> should
113 not include a call to C<sleep()>.
115 =head1 THANK THE AUTHOR
117 If you need high-speed internet services (T1, T3, OC3 etc), please
118 send me your request-for-quote. I have access to very good pricing:
119 you'll save money and get a great service.
123 Copyright(C) 2006 David Muir Sharnoff <muir@idiom.com>.
124 This module may be used and distributed on the same terms