okay,.. I think this is ready for release
[gitmo/MooseX-Daemonize.git] / lib / MooseX / Daemonize / WithPidFile.pm
CommitLineData
d9e417f4 1package MooseX::Daemonize::WithPidFile;
4327fe98 2use strict; # cause Perl::Critic errors are annoying
3use MooseX::Getopt; # to load the Getopt metaclass
d9e417f4 4use Moose::Role;
5
d8985b7d 6use MooseX::Daemonize::Pid::File;
d9e417f4 7
8our $VERSION = 0.01;
9
d02fc704 10with 'MooseX::Daemonize::Core';
11
d9e417f4 12requires 'init_pidfile';
13
14has pidfile => (
4327fe98 15 # NOTE:
16 # this should always be accessible
17 # from the command line IMO
18 # - SL
19 metaclass => 'Getopt',
d8985b7d 20 isa => 'MooseX::Daemonize::Pid::File',
d9e417f4 21 is => 'rw',
22 lazy => 1,
23 required => 1,
24 coerce => 1,
25 predicate => 'has_pidfile',
26 builder => 'init_pidfile',
27);
28
d02fc704 29after 'daemonize' => sub {
1ddf8f0c 30 my $self = shift;
d02fc704 31 # NOTE:
32 # make sure that we do not have
33 # any bad PID values stashed around
34 # - SL
1ddf8f0c 35 $self->pidfile->clear_pid;
36 $self->pidfile->write if $self->is_daemon;
d02fc704 37};
38
d9e417f4 391;
40
8ac4733f 41__END__
42
43=pod
44
4327fe98 45=head1 NAME
46
47MooseX::Daemonize::WithPidFile - A Role with the core daemonization and pidfile management
48
49=head1 SYNOPSIS
50
51 package My::Daemon;
52 use Moose;
53
54 with 'MooseX::Daemonize::WithPidFile';
55
56 sub start {
57 my $self = shift;
58 # daemonize me ...
59 $self->daemonize; # << this will write the pidfile for you
60 # return from the parent,...
61 return unless $self->is_daemon;
62 # but continue on in the child (daemon)
63 }
64
65=head1 DESCRIPTION
66
67This is a slightly extended basic daemonization Role, it provides
68Pidfile management along with the core daemonization features
69found in L<MooseX::Daemonize::Core>.
70
71=head1 ATTRIBUTES
72
73=over
74
75=item I<pidfile (is => rw, isa => MooseX::Daemonize::Pid::File)>
76
77This attribute holds the L<MooseX::Daemonize::Pid::File> object used
78to manage the Pidfile. It will initialize the object using the
79C<init_pidfile> method (which is required by this role).
80
81=back
82
83=head1 REQUIRED METHODS
84
85=over 4
86
87=item I<init_pidfile>
88
89This method is used to build the I<pidfile> attribute's object. It should
90return a L<MooseX::Daemonize::Pid::File> object.
91
92=item B<has_pidfile>
93
94This is a predicate method to tell you if your I<pidfile> attribute has
95been initialized yet.
96
97=back
98
99=head1 METHODS
100
101=over 4
102
103=item B<daemonize>
104
105This adds an C<after> method modifier to the C<daemonize> method (from
106L<MooseX::Daemonize::Core>) and handles writing your Pidfile for you.
107
108=item B<meta>
109
110The C<meta()> method from L<Class::MOP::Class>
111
112=back
113
114=head1 DEPENDENCIES
115
116L<Moose::Role>, L<MooseX::Getopt> and L<MooseX::Daemonize::Pid::File>
117
118=head1 INCOMPATIBILITIES
119
120None reported.
121
122=head1 BUGS AND LIMITATIONS
123
124No bugs have been reported.
125
126Please report any bugs or feature requests to
127C<bug-acme-dahut-call@rt.cpan.org>, or through the web interface at
128L<http://rt.cpan.org>.
129
130=head1 AUTHOR
131
132Stevan Little C<< <stevan.little@iinteractive.com> >>
133
134=head1 LICENCE AND COPYRIGHT
135
136Copyright (c) 2007, Chris Prather C<< <perigrin@cpan.org> >>. All rights
137reserved.
138
139Portions heavily borrowed from L<Proc::Daemon> which is copyright Earl Hood.
140
141This module is free software; you can redistribute it and/or
142modify it under the same terms as Perl itself. See L<perlartistic>.
143
144=head1 DISCLAIMER OF WARRANTY
145
146BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
147FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
148OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
149PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
150EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
151WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
152ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
153YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
154NECESSARY SERVICING, REPAIR, OR CORRECTION.
155
156IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
157WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
158REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
159LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
160OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
161THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
162RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
163FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
164SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
165SUCH DAMAGES.
166
167=cut