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