3 package MooseX::Daemonize::Pid::File;
6 use Moose::Util::TypeConstraints;
10 use MooseX::Types::Path::Class;
11 use MooseX::Getopt::OptionTypeMap;
14 # set up some basic coercions
15 # that will come in handy
17 coerce 'MooseX::Daemonize::Pid::File'
19 => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
21 => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
22 => from 'Path::Class::File'
23 => via { MooseX::Daemonize::Pid::File->new( file => $_ ) };
26 # make sure this class plays
27 # well with MooseX::Getopt
29 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
30 'MooseX::Daemonize::Pid::File' => '=s',
33 extends 'MooseX::Daemonize::Pid';
38 $self->does_file_exist
39 ? $self->file->slurp(chomp => 1)
46 isa => 'Path::Class::File',
49 handles => [ 'remove' ]
52 sub does_file_exist { -s (shift)->file }
56 my $fh = $self->file->openw;
57 $fh->print($self->pid . "\n");
61 override 'is_running' => sub {
62 return 0 unless (shift)->does_file_exist;
74 MooseX::Daemonize::Pid::File - PID file management for MooseX::Daemonize
78 This object extends L<MooseX::Daemonize::Pid> to add persistence in a Pidfile.
80 This class sets up some basic coercion routines for itself so that it can
81 be created from a I<Str> (a file name), I<ArrayRef> (an array of path components
82 for a filename) or a I<Path::Class::File> object.
84 This class registers it's type with L<MooseX::Getopt> as well, and is expected
85 to be passed on the command line as a string (which will then go through the
86 coercion routines mentioned above).
94 This is inherited from L<MooseX:Daemonize::Pid> and extended here to
95 get it's default value from the Pidfile (if available).
97 =item I<file Path::Class::File | Str>
109 Both of these methods are inherited from L<MooseX:Daemonize::Pid> see that
110 module for more information.
114 This removes the Pidfile.
118 This writes the Pidfile.
120 =item B<does_file_exist>
122 This checks if the Pidfile exists.
126 This checks if the Pidfile exists, if it does it checks to see if the process
127 is running, if the Pidfile doesn't exist, it returns false.
131 The C<meta()> method from L<Class::MOP::Class>
139 =head1 INCOMPATIBILITIES
143 =head1 BUGS AND LIMITATIONS
145 No bugs have been reported.
147 Please report any bugs or feature requests to
148 C<bug-acme-dahut-call@rt.cpan.org>, or through the web interface at
149 L<http://rt.cpan.org>.
153 Stevan Little C<< <stevan.little@iinteractive.com> >>
155 =head1 LICENCE AND COPYRIGHT
157 Copyright (c) 2007-2011, Chris Prather C<< <perigrin@cpan.org> >>. All rights
160 This module is free software; you can redistribute it and/or
161 modify it under the same terms as Perl itself. See L<perlartistic>.
164 =head1 DISCLAIMER OF WARRANTY
166 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
167 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
168 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
169 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
170 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
171 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
172 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
173 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
174 NECESSARY SERVICING, REPAIR, OR CORRECTION.
176 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
177 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
178 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
179 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
180 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
181 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
182 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
183 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
184 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF