File Coverage

blib/lib/MooseX/Daemonize/WithPidFile.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1 11     11   6709 use strict;
  11         12  
  11         289  
2 11     11   32 use warnings;
  11         18  
  11         452  
3             package MooseX::Daemonize::WithPidFile;
4             # ABSTRACT: A Role with the core daemonization and pidfile management
5              
6             our $VERSION = '0.21';
7              
8 11     11   41 use MooseX::Getopt; # to load the Getopt metaclass
  11         32  
  11         188  
9 11     11   33 use Moose::Role;
  11         10  
  11         62  
10 11     11   37686 use namespace::autoclean;
  11         17  
  11         47  
11              
12 11     11   4094 use MooseX::Daemonize::Pid::File;
  11         21  
  11         1370  
13              
14             with 'MooseX::Daemonize::Core';
15              
16             requires 'init_pidfile';
17              
18             has pidfile => (
19             # NOTE:
20             # this should always be accessible
21             # from the command line IMO
22             # - SL
23             metaclass => 'Getopt',
24             isa => 'MooseX::Daemonize::Pid::File',
25             is => 'rw',
26             lazy => 1,
27             coerce => 1,
28             predicate => 'has_pidfile',
29             builder => 'init_pidfile',
30             );
31              
32             after 'daemonize' => sub {
33             my $self = shift;
34             # NOTE:
35             # make sure that we do not have
36             # any bad PID values stashed around
37             # - SL
38             $self->pidfile->clear_pid;
39             if ($self->is_daemon) {
40             $self->pidfile->write;
41             }
42             };
43              
44             1;
45              
46             __END__
47              
48             =pod
49              
50             =encoding UTF-8
51              
52             =head1 NAME
53              
54             MooseX::Daemonize::WithPidFile - A Role with the core daemonization and pidfile management
55              
56             =head1 VERSION
57              
58             version 0.21
59              
60             =head1 SYNOPSIS
61              
62             package My::Daemon;
63             use Moose;
64              
65             with 'MooseX::Daemonize::WithPidFile';
66              
67             sub start {
68             my $self = shift;
69             # daemonize me ...
70             $self->daemonize; # << this will write the pidfile for you
71             # return from the parent,...
72             return unless $self->is_daemon;
73             # but continue on in the child (daemon)
74             }
75              
76             =head1 DESCRIPTION
77              
78             This is a slightly extended basic daemonization Role, it provides
79             Pidfile management along with the core daemonization features
80             found in L<MooseX::Daemonize::Core>.
81              
82             =head1 ATTRIBUTES
83              
84             =over
85              
86             =item I<pidfile (is => rw, isa => MooseX::Daemonize::Pid::File)>
87              
88             This attribute holds the L<MooseX::Daemonize::Pid::File> object used
89             to manage the Pidfile. It will initialize the object using the
90             C<init_pidfile> method (which is required by this role).
91              
92             =back
93              
94             =head1 REQUIRED METHODS
95              
96             =over 4
97              
98             =item I<init_pidfile>
99              
100             This method is used to build the I<pidfile> attribute's object. It should
101             return a L<MooseX::Daemonize::Pid::File> object.
102              
103             =item B<has_pidfile>
104              
105             This is a predicate method to tell you if your I<pidfile> attribute has
106             been initialized yet.
107              
108             =back
109              
110             =head1 METHODS
111              
112             =over 4
113              
114             =item B<daemonize>
115              
116             This adds an C<after> method modifier to the C<daemonize> method (from
117             L<MooseX::Daemonize::Core>) and handles writing your Pidfile for you.
118              
119             =item B<meta>
120              
121             The C<meta()> method from L<Class::MOP::Class>
122              
123             =back
124              
125             =head1 DEPENDENCIES
126              
127             L<Moose::Role>, L<MooseX::Getopt> and L<MooseX::Daemonize::Pid::File>
128              
129             =head1 COPYRIGHT AND LICENCE
130              
131             Portions heavily borrowed from L<Proc::Daemon> which is copyright Earl Hood.
132              
133             =head1 SUPPORT
134              
135             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Daemonize>
136             (or L<bug-MooseX-Daemonize@rt.cpan.org|mailto:bug-MooseX-Daemonize@rt.cpan.org>).
137              
138             There is also a mailing list available for users of this distribution, at
139             L<http://lists.perl.org/list/moose.html>.
140              
141             There is also an irc channel available for users of this distribution, at
142             L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
143              
144             =head1 AUTHORS
145              
146             =over 4
147              
148             =item *
149              
150             Stevan Little <stevan.little@iinteractive.com>
151              
152             =item *
153              
154             Chris Prather <chris@prather.org>
155              
156             =back
157              
158             =head1 COPYRIGHT AND LICENCE
159              
160             This software is copyright (c) 2007 by Chris Prather.
161              
162             This is free software; you can redistribute it and/or modify it under
163             the same terms as the Perl 5 programming language system itself.
164              
165             =cut