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