1 package MooseX::Daemonize::Pid::File;
2 use strict; # because Kwalitee is pedantic
4 use Moose::Util::TypeConstraints;
8 use MooseX::Types::Path::Class;
9 use MooseX::Getopt::OptionTypeMap;
12 # set up some basic coercions
13 # that will come in handy
15 coerce 'MooseX::Daemonize::Pid::File'
17 => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
19 => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
20 => from 'Path::Class::File'
21 => via { MooseX::Daemonize::Pid::File->new( file => $_ ) };
24 # make sure this class plays
25 # well with MooseX::Getopt
27 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
28 'MooseX::Daemonize::Pid::File' => '=s',
31 extends 'MooseX::Daemonize::Pid';
36 $self->does_file_exist
37 ? $self->file->slurp(chomp => 1)
44 isa => 'Path::Class::File',
47 handles => [ 'remove' ]
50 sub does_file_exist { -s (shift)->file }
54 my $fh = $self->file->openw;
55 $fh->print($self->pid);
59 override 'is_running' => sub {
60 return 0 unless (shift)->does_file_exist;
72 MooseX::Daemonize::Pid::File - PID file management for MooseX::Daemonize
76 This object extends L<MooseX::Daemonize::Pid> to add persistence in a Pidfile.
78 This class sets up some basic coercion routines for itself so that it can
79 be created from a I<Str> (a file name), I<ArrayRef> (an array of path components
80 for a filename) or a I<Path::Class::File> object.
82 This class registers it's type with L<MooseX::Getopt> as well, and is expected
83 to be passed on the command line as a string (which will then go through the
84 coercion routines mentioned above).
92 This is inherited from L<MooseX:Daemonize::Pid> and extended here to
93 get it's default value from the Pidfile (if available).
95 =item I<file Path::Class::File | Str>
107 Both of these methods are inherited from L<MooseX:Daemonize::Pid> see that
108 module for more information.
112 This removes the Pidfile.
116 This writes the Pidfile.
118 =item B<does_file_exist>
120 This checks if the Pidfile exists.
124 This checks if the Pidfile exists, if it does it checks to see if the process
125 is running, if the Pidfile doesn't exist, it returns false.
129 The C<meta()> method from L<Class::MOP::Class>
137 =head1 INCOMPATIBILITIES
141 =head1 BUGS AND LIMITATIONS
143 No bugs have been reported.
145 Please report any bugs or feature requests to
146 C<bug-acme-dahut-call@rt.cpan.org>, or through the web interface at
147 L<http://rt.cpan.org>.
151 Stevan Little C<< <stevan@cpan.org> >>
153 =head1 LICENCE AND COPYRIGHT
155 Copyright (c) 2007, Chris Prather C<< <perigrin@cpan.org> >>. All rights
158 This module is free software; you can redistribute it and/or
159 modify it under the same terms as Perl itself. See L<perlartistic>.
162 =head1 DISCLAIMER OF WARRANTY
164 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
165 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
166 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
167 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
168 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
169 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
170 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
171 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
172 NECESSARY SERVICING, REPAIR, OR CORRECTION.
174 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
175 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
176 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
177 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
178 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
179 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
180 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
181 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
182 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF