blib/lib/MooseX/Daemonize/Pid/File.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 12 / 14 Podpod 100% 2 / 2 totaltotal 93.5% 58 / 62 SCAR 11.0
CC
3
Cov
96%
__ANON__
2.0
__ANON__
2.0
__ANON__
2.0
CRAP 3.0
« blib/lib/Test/MooseX/Daemonize.pm ↑ Summary blib/lib/MooseX/Daemonize/Pid.pm »
1 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package MooseX::Daemonize::Pid::File;
4 # ABSTRACT: PID file management for MooseX::Daemonize
5  
6 10 our $VERSION = '0.22';
7  
8 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Moose::Util::TypeConstraints qw(coerce from via);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use MooseX::Getopt::OptionTypeMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # NOTE:
16 # set up some basic coercions
17 # that will come in handy
18 # - SL
19 coerce 'MooseX::Daemonize::Pid::File'
20 => from 'Str'
21 3 ▶ => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
22 => from 'ArrayRef'
23 0 ▶ => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 => from 'Path::Class::File'
25 0 ▶ => via { MooseX::Daemonize::Pid::File->new( file => $_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
26  
27 # NOTE:
28 # make sure this class plays
29 # well with MooseX::Getopt
30 # - SL
31 10 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
32 'MooseX::Daemonize::Pid::File' => '=s',
33 );
34  
35 10 extends 'MooseX::Daemonize::Pid';
36  
37 has '+pid' => (
38 default => sub {
39 8 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
40 8 ▶ $self->does_file_exist
Branch: 1 branch
BranchTrueFalseTotal
$self->does_file_exist ? : 3 5 8
41 ? $self->file->slurp(chomp => 1)
42 : $$
43 }
44 10 );
45  
46 10 has 'file' => (
47 is => 'ro',
48 isa => 'Path::Class::File',
49 coerce => 1,
50 required => 1,
51 handles => [ 'remove' ]
52 );
53  
54 27 ▶sub does_file_exist { -s (shift)->file }
Subroutine does_file_exist: called CC=1 SCAR=0.0
Pod documented
55  
56 sub write {
57 4 ▶ my $self = shift;
Subroutine write: called CC=1 SCAR=0.0
Pod documented
58 4 my $fh = $self->file->openw;
59 4 $fh->print($self->pid . "\n");
60 4 $fh->close;
61 }
62  
63 override 'is_running' => sub {
64 17 ▶ return 0 unless (shift)->does_file_exist;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless (shift())->does_file_exist 10 7 17
65 7 super();
66 10 };
67  
68 10 __PACKAGE__->meta->make_immutable;
69 10 1;
70  
71 __END__
72  
73 =pod
74  
75 =encoding UTF-8
76  
77 =head1 NAME
78  
79 MooseX::Daemonize::Pid::File - PID file management for MooseX::Daemonize
80  
81 =head1 VERSION
82  
83 version 0.22
84  
85 =head1 DESCRIPTION
86  
87 This object extends L<MooseX::Daemonize::Pid> to add persistence in a Pidfile.
88  
89 This class sets up some basic coercion routines for itself so that it can
90 be created from a I<Str> (a file name), I<ArrayRef> (an array of path components
91 for a filename) or a I<Path::Class::File> object.
92  
93 This class registers it's type with L<MooseX::Getopt> as well, and is expected
94 to be passed on the command line as a string (which will then go through the
95 coercion routines mentioned above).
96  
97 =head1 ATTRIBUTES
98  
99 =over
100  
101 =item I<pid Int>
102  
103 This is inherited from L<MooseX:Daemonize::Pid> and extended here to
104 get it's default value from the Pidfile (if available).
105  
106 =item I<file Path::Class::File | Str>
107  
108 =back
109  
110 =head1 METHODS
111  
112 =over
113  
114 =item B<clear_pid>
115  
116 =item B<has_pid>
117  
118 Both of these methods are inherited from L<MooseX:Daemonize::Pid> see that
119 module for more information.
120  
121 =item B<remove>
122  
123 This removes the Pidfile.
124  
125 =item B<write>
126  
127 This writes the Pidfile.
128  
129 =item B<does_file_exist>
130  
131 This checks if the Pidfile exists.
132  
133 =item B<is_running>
134  
135 This checks if the Pidfile exists, if it does it checks to see if the process
136 is running, if the Pidfile doesn't exist, it returns false.
137  
138 =item meta()
139  
140 The C<meta()> method from L<Class::MOP::Class>
141  
142 =back
143  
144 =head1 SUPPORT
145  
146 Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Daemonize>
147 (or L<bug-MooseX-Daemonize@rt.cpan.org|mailto:bug-MooseX-Daemonize@rt.cpan.org>).
148  
149 There is also a mailing list available for users of this distribution, at
150 L<http://lists.perl.org/list/moose.html>.
151  
152 There is also an irc channel available for users of this distribution, at
153 L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
154  
155 =head1 AUTHORS
156  
157 =over 4
158  
159 =item *
160  
161 Stevan Little <stevan.little@iinteractive.com>
162  
163 =item *
164  
165 Chris Prather <chris@prather.org>
166  
167 =back
168  
169 =head1 COPYRIGHT AND LICENCE
170  
171 This software is copyright (c) 2007 by Chris Prather.
172  
173 This is free software; you can redistribute it and/or modify it under
174 the same terms as the Perl 5 programming language system itself.
175  
176 =cut
« blib/lib/Test/MooseX/Daemonize.pm ↑ Summary blib/lib/MooseX/Daemonize/Pid.pm »