X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FDaemonize%2FPid%2FFile.pm;h=fec7b6db2b13459d24bda1e46d63a84c25d3a81c;hb=5231273c6ddb272733286beb5e3d5faf94cfd437;hp=2b3c88af2f4f99375d46d7fe74ebf365e184d395;hpb=8ac4733fe6918fb1449262f56b5c371315c6cfb8;p=gitmo%2FMooseX-Daemonize.git diff --git a/lib/MooseX/Daemonize/Pid/File.pm b/lib/MooseX/Daemonize/Pid/File.pm index 2b3c88a..fec7b6d 100644 --- a/lib/MooseX/Daemonize/Pid/File.pm +++ b/lib/MooseX/Daemonize/Pid/File.pm @@ -1,21 +1,39 @@ +use strict; +use warnings; package MooseX::Daemonize::Pid::File; -use strict; # because Kwalitee is pedantic + use Moose; use Moose::Util::TypeConstraints; -use MooseX::Types::Path::Class; -coerce 'MooseX::Daemonize::Pid::File' - => from 'Str' +our $VERSION = '0.15'; + +use MooseX::Types::Path::Class; +use MooseX::Getopt::OptionTypeMap; + +# NOTE: +# set up some basic coercions +# that will come in handy +# - SL +coerce 'MooseX::Daemonize::Pid::File' + => from 'Str' + => via { MooseX::Daemonize::Pid::File->new( file => $_ ) } + => from 'ArrayRef' => via { MooseX::Daemonize::Pid::File->new( file => $_ ) } - => from 'Path::Class::File' + => from 'Path::Class::File' => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }; -our $VERSION = '0.01'; +# NOTE: +# make sure this class plays +# well with MooseX::Getopt +# - SL +MooseX::Getopt::OptionTypeMap->add_option_type_to_map( + 'MooseX::Daemonize::Pid::File' => '=s', +); extends 'MooseX::Daemonize::Pid'; has '+pid' => ( - default => sub { + default => sub { my $self = shift; $self->does_file_exist ? $self->file->slurp(chomp => 1) @@ -36,7 +54,7 @@ sub does_file_exist { -s (shift)->file } sub write { my $self = shift; my $fh = $self->file->openw; - $fh->print($self->pid); + $fh->print($self->pid . "\n"); $fh->close; } @@ -55,29 +73,58 @@ __END__ MooseX::Daemonize::Pid::File - PID file management for MooseX::Daemonize -=head1 SYNOPSIS - =head1 DESCRIPTION +This object extends L to add persistence in a Pidfile. + +This class sets up some basic coercion routines for itself so that it can +be created from a I (a file name), I (an array of path components +for a filename) or a I object. + +This class registers it's type with L as well, and is expected +to be passed on the command line as a string (which will then go through the +coercion routines mentioned above). + =head1 ATTRIBUTES =over -=item file Path::Class::File | Str +=item I + +This is inherited from L and extended here to +get it's default value from the Pidfile (if available). + +=item I =back -=head1 METHODS +=head1 METHODS =over -=item remove +=item B + +=item B + +Both of these methods are inherited from L see that +module for more information. + +=item B + +This removes the Pidfile. + +=item B + +This writes the Pidfile. + +=item B -=item write +This checks if the Pidfile exists. -=item does_file_exist +=item B -=item is_running +This checks if the Pidfile exists, if it does it checks to see if the process +is running, if the Pidfile doesn't exist, it returns false. =item meta() @@ -103,11 +150,11 @@ L. =head1 AUTHOR -Stevan Little C<< >> +Stevan Little C<< >> =head1 LICENCE AND COPYRIGHT -Copyright (c) 2007, Chris Prather C<< >>. All rights +Copyright (c) 2007-2011, Chris Prather C<< >>. All rights reserved. This module is free software; you can redistribute it and/or @@ -137,4 +184,4 @@ FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -=cut \ No newline at end of file +=cut