remove extra $VERSION declaration that does not belong
[gitmo/MooseX-Daemonize.git] / lib / MooseX / Daemonize / Pid / File.pm
index 2b3c88a..0f5177e 100644 (file)
@@ -1,21 +1,37 @@
+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' 
+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 'Path::Class::File' 
+    => from 'ArrayRef'
+        => via { MooseX::Daemonize::Pid::File->new( 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 +52,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 +71,58 @@ __END__
 
 MooseX::Daemonize::Pid::File - PID file management for MooseX::Daemonize
 
-=head1 SYNOPSIS
-     
 =head1 DESCRIPTION
 
+This object extends L<MooseX::Daemonize::Pid> 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<Str> (a file name), I<ArrayRef> (an array of path components
+for a filename) or a I<Path::Class::File> object.
+
+This class registers it's type with L<MooseX::Getopt> 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<pid Int>
+
+This is inherited from L<MooseX:Daemonize::Pid> and extended here to
+get it's default value from the Pidfile (if available).
+
+=item I<file Path::Class::File | Str>
 
 =back
 
-=head1 METHODS 
+=head1 METHODS
 
 =over
 
-=item remove
+=item B<clear_pid>
+
+=item B<has_pid>
+
+Both of these methods are inherited from L<MooseX:Daemonize::Pid> see that
+module for more information.
+
+=item B<remove>
+
+This removes the Pidfile.
+
+=item B<write>
+
+This writes the Pidfile.
+
+=item B<does_file_exist>
 
-=item write
+This checks if the Pidfile exists.
 
-=item does_file_exist
+=item B<is_running>
 
-=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 +148,11 @@ L<http://rt.cpan.org>.
 
 =head1 AUTHOR
 
-Stevan Little  C<< <stevan@cpan.org> >>
+Stevan Little  C<< <stevan.little@iinteractive.com> >>
 
 =head1 LICENCE AND COPYRIGHT
 
-Copyright (c) 2007, Chris Prather C<< <perigrin@cpan.org> >>. All rights 
+Copyright (c) 2007-2011, Chris Prather C<< <perigrin@cpan.org> >>. All rights
 reserved.
 
 This module is free software; you can redistribute it and/or
@@ -137,4 +182,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