Commit | Line | Data |
d9e417f4 |
1 | package MooseX::Daemonize::WithPidFile; |
4327fe98 |
2 | use strict; # cause Perl::Critic errors are annoying |
3 | use MooseX::Getopt; # to load the Getopt metaclass |
d9e417f4 |
4 | use Moose::Role; |
5 | |
d8985b7d |
6 | use MooseX::Daemonize::Pid::File; |
d9e417f4 |
7 | |
8 | our $VERSION = 0.01; |
9 | |
d02fc704 |
10 | with 'MooseX::Daemonize::Core'; |
11 | |
d9e417f4 |
12 | requires 'init_pidfile'; |
13 | |
14 | has 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, |
d9e417f4 |
23 | coerce => 1, |
24 | predicate => 'has_pidfile', |
25 | builder => 'init_pidfile', |
26 | ); |
27 | |
d02fc704 |
28 | after 'daemonize' => sub { |
1ddf8f0c |
29 | my $self = shift; |
d02fc704 |
30 | # NOTE: |
31 | # make sure that we do not have |
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 |
40 | 1; |
41 | |
8ac4733f |
42 | __END__ |
43 | |
44 | =pod |
45 | |
4327fe98 |
46 | =head1 NAME |
47 | |
48 | MooseX::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 | |
68 | This is a slightly extended basic daemonization Role, it provides |
69 | Pidfile management along with the core daemonization features |
70 | found 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 | |
78 | This attribute holds the L<MooseX::Daemonize::Pid::File> object used |
79 | to manage the Pidfile. It will initialize the object using the |
80 | C<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 | |
90 | This method is used to build the I<pidfile> attribute's object. It should |
91 | return a L<MooseX::Daemonize::Pid::File> object. |
92 | |
93 | =item B<has_pidfile> |
94 | |
95 | This is a predicate method to tell you if your I<pidfile> attribute has |
96 | been initialized yet. |
97 | |
98 | =back |
99 | |
100 | =head1 METHODS |
101 | |
102 | =over 4 |
103 | |
104 | =item B<daemonize> |
105 | |
106 | This adds an C<after> method modifier to the C<daemonize> method (from |
107 | L<MooseX::Daemonize::Core>) and handles writing your Pidfile for you. |
108 | |
109 | =item B<meta> |
110 | |
111 | The C<meta()> method from L<Class::MOP::Class> |
112 | |
113 | =back |
114 | |
115 | =head1 DEPENDENCIES |
116 | |
117 | L<Moose::Role>, L<MooseX::Getopt> and L<MooseX::Daemonize::Pid::File> |
118 | |
119 | =head1 INCOMPATIBILITIES |
120 | |
121 | None reported. |
122 | |
123 | =head1 BUGS AND LIMITATIONS |
124 | |
125 | No bugs have been reported. |
126 | |
127 | Please report any bugs or feature requests to |
128 | C<bug-acme-dahut-call@rt.cpan.org>, or through the web interface at |
129 | L<http://rt.cpan.org>. |
130 | |
131 | =head1 AUTHOR |
132 | |
133 | Stevan Little C<< <stevan.little@iinteractive.com> >> |
134 | |
135 | =head1 LICENCE AND COPYRIGHT |
136 | |
df3c463b |
137 | Copyright (c) 2007-2008, Chris Prather C<< <perigrin@cpan.org> >>. All rights |
4327fe98 |
138 | reserved. |
139 | |
140 | Portions heavily borrowed from L<Proc::Daemon> which is copyright Earl Hood. |
141 | |
142 | This module is free software; you can redistribute it and/or |
143 | modify it under the same terms as Perl itself. See L<perlartistic>. |
144 | |
145 | =head1 DISCLAIMER OF WARRANTY |
146 | |
147 | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
148 | FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
149 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
150 | PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
151 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
152 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
153 | ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
154 | YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
155 | NECESSARY SERVICING, REPAIR, OR CORRECTION. |
156 | |
157 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
158 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
159 | REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE |
160 | LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
161 | OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
162 | THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
163 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
164 | FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
165 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
166 | SUCH DAMAGES. |
167 | |
168 | =cut |