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