| 1 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package MooseX::Daemonize::WithPidFile; | ||||||||||
| 4 | # ABSTRACT: A Role with the core daemonization and pidfile management | ||||||||||
| 5 | |||||||||||
| 6 | 9 | our $VERSION = '0.22'; | |||||||||
| 7 | |||||||||||
| 8 | 9 | ▶ | use MooseX::Getopt; # to load the Getopt metaclass | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 9 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 9 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 9 | ▶ | use MooseX::Daemonize::Pid::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 9 | with 'MooseX::Daemonize::Core'; | |||||||||
| 15 | |||||||||||
| 16 | 9 | requires 'init_pidfile'; | |||||||||
| 17 | |||||||||||
| 18 | 9 | 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 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 34 | # NOTE: | ||||||||||
| 35 | # make sure that we do not have | ||||||||||
| 36 | # any bad PID values stashed around | ||||||||||
| 37 | # - SL | ||||||||||
| 38 | 4 | $self->pidfile->clear_pid; | |||||||||
| 39 | 4 | ▶ | if ($self->is_daemon) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1 | $self->pidfile->write; | |||||||||
| 41 | } | ||||||||||
| 42 | 9 | }; | |||||||||
| 43 | |||||||||||
| 44 | 9 | 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.22 | ||||||||||
| 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 SUPPORT | ||||||||||
| 130 | |||||||||||
| 131 | Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Daemonize> | ||||||||||
| 132 | (or L<bug-MooseX-Daemonize@rt.cpan.org|mailto:bug-MooseX-Daemonize@rt.cpan.org>). | ||||||||||
| 133 | |||||||||||
| 134 | There is also a mailing list available for users of this distribution, at | ||||||||||
| 135 | L<http://lists.perl.org/list/moose.html>. | ||||||||||
| 136 | |||||||||||
| 137 | There is also an irc channel available for users of this distribution, at | ||||||||||
| 138 | L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. | ||||||||||
| 139 | |||||||||||
| 140 | =head1 AUTHORS | ||||||||||
| 141 | |||||||||||
| 142 | =over 4 | ||||||||||
| 143 | |||||||||||
| 144 | =item * | ||||||||||
| 145 | |||||||||||
| 146 | Stevan Little <stevan.little@iinteractive.com> | ||||||||||
| 147 | |||||||||||
| 148 | =item * | ||||||||||
| 149 | |||||||||||
| 150 | Chris Prather <chris@prather.org> | ||||||||||
| 151 | |||||||||||
| 152 | =back | ||||||||||
| 153 | |||||||||||
| 154 | =head1 COPYRIGHT AND LICENCE | ||||||||||
| 155 | |||||||||||
| 156 | This software is copyright (c) 2007 by Chris Prather. | ||||||||||
| 157 | |||||||||||
| 158 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 159 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 160 | |||||||||||
| 161 | Portions heavily borrowed from L<Proc::Daemon> which is copyright Earl Hood. | ||||||||||
| 162 | |||||||||||
| 163 | =cut | ||||||||||