r60232 - in /branches/upstream/libmoosex-daemonize-perl/current: ./ .git/ examples/ lab/ lib/MooseX/ lib/MooseX/Daemonize/ lib/MooseX/Daemonize/Pid/ lib/Test/MooseX/ t/
gregoa at users.alioth.debian.org
gregoa at users.alioth.debian.org
Sun Jul 11 19:42:32 UTC 2010
Author: gregoa
Date: Sun Jul 11 19:42:24 2010
New Revision: 60232
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=60232
Log:
[svn-upgrade] new version libmoosex-daemonize-perl (0.12)
Added:
branches/upstream/libmoosex-daemonize-perl/current/t/21.core-back-compat.t
Removed:
branches/upstream/libmoosex-daemonize-perl/current/.git/
branches/upstream/libmoosex-daemonize-perl/current/IDEAS
branches/upstream/libmoosex-daemonize-perl/current/examples/
branches/upstream/libmoosex-daemonize-perl/current/lab/
branches/upstream/libmoosex-daemonize-perl/current/t/pod-coverage.t
branches/upstream/libmoosex-daemonize-perl/current/t/pod.t
Modified:
branches/upstream/libmoosex-daemonize-perl/current/Changes
branches/upstream/libmoosex-daemonize-perl/current/MANIFEST
branches/upstream/libmoosex-daemonize-perl/current/MANIFEST.SKIP
branches/upstream/libmoosex-daemonize-perl/current/META.yml
branches/upstream/libmoosex-daemonize-perl/current/README
branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize.pm
branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Core.pm
branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid.pm
branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid/File.pm
branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/WithPidFile.pm
branches/upstream/libmoosex-daemonize-perl/current/lib/Test/MooseX/Daemonize.pm
branches/upstream/libmoosex-daemonize-perl/current/t/20.core.t
Modified: branches/upstream/libmoosex-daemonize-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/Changes?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/Changes (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/Changes Sun Jul 11 19:42:24 2010
@@ -1,4 +1,16 @@
Revision history for MooseX-Daemonize
+
+0.12 Sun. July 11, 2010
+ - release without the .git directory in it
+
+0.11 Sat. July 10, 2010
+ * MooseX::Daemonize::Core
+ - make the options to daemonize()
+ into proper attributes but still
+ retained back-compat (Thanks to Magnus Erixzon)
+ - adjusted docs and tests
+
+ - removed the pod.t and pod-coverage.t tests
0.10 Sat. April 17, 2010
- updated copyrights
Modified: branches/upstream/libmoosex-daemonize-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/MANIFEST?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/MANIFEST (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/MANIFEST Sun Jul 11 19:42:24 2010
@@ -1,78 +1,5 @@
.cvsignore
-.git/COMMIT_EDITMSG
-.git/config
-.git/description
-.git/FETCH_HEAD
-.git/HEAD
-.git/hooks/applypatch-msg
-.git/hooks/applypatch-msg.sample
-.git/hooks/commit-msg
-.git/hooks/commit-msg.sample
-.git/hooks/post-commit
-.git/hooks/post-commit.sample
-.git/hooks/post-receive
-.git/hooks/post-receive.sample
-.git/hooks/post-update
-.git/hooks/post-update.sample
-.git/hooks/pre-applypatch
-.git/hooks/pre-applypatch.sample
-.git/hooks/pre-commit
-.git/hooks/pre-commit.sample
-.git/hooks/pre-rebase
-.git/hooks/pre-rebase.sample
-.git/hooks/prepare-commit-msg.sample
-.git/hooks/update
-.git/hooks/update.sample
-.git/index
-.git/info/exclude
-.git/logs/HEAD
-.git/logs/refs/heads/master
-.git/logs/refs/remotes/origin/HEAD
-.git/logs/refs/remotes/origin/master
-.git/objects/03/30a27f596ae6a5b60e54cdef23a6e4dcefeaf3
-.git/objects/03/311a3e77237dbc385451859d9fd37954bfec39
-.git/objects/1d/85c76d2da46df3e779e574396f7eba5bf53fdb
-.git/objects/1f/070dff6004310ba11c3525f1ac8508c69ab8a5
-.git/objects/20/16ddf64674a2b5d3413095714e4a2f7900549f
-.git/objects/28/41cd7f04dbb7c8cd04c0c5fa64c939b9393615
-.git/objects/2c/bf754bef80feedd5b871cc3a353c5b9e269ff2
-.git/objects/33/aa69e3767ca7dfaeaa92119695b796e06f1bd4
-.git/objects/39/23f86b4bd0ed1fa5638724bfb2608d92216b2e
-.git/objects/3d/3f1a9ec3a0686beae2bf477da0505920708fe7
-.git/objects/42/b27b38d1db6b21b2dd5556070ac5e64f77aa79
-.git/objects/48/c580104f7f23ac2973f9d8a82ec0e92efdec6a
-.git/objects/48/c93cc033369e9dcf41d1dc074f4b742bf5d3de
-.git/objects/5b/2767c3eec31a24681fd952ff33f75053f29158
-.git/objects/69/186a4879a2ddfed228c03e7a25d5455921dfb0
-.git/objects/6b/c9738762b9a863bf2445a446c56dae003d4c91
-.git/objects/77/885d9040b5cb7ed6e7701f36058192b095432f
-.git/objects/82/46856401287180a83f163b2ace11de8c38b00b
-.git/objects/87/5a05bf2767d149d0b89ecdf1fc806ae0254751
-.git/objects/8a/3a9dc69e815c33bcca64566ae3ff04fa721136
-.git/objects/8d/095a061ff132a66a5e7be19d276da180b0aac0
-.git/objects/98/aee7aba997f43d2e36465d5efc95c36ecd0731
-.git/objects/98/d14095c497821cbdea0be1bad79a09fc65bcd8
-.git/objects/a0/a4047bbb51a28963ade7e14a5281153ca1a7f5
-.git/objects/b2/1a588c8f4cef6e4b34d23ae0cb0756590f40c4
-.git/objects/b4/100f88e15ec605aa49a2ad2cc106917c0976e8
-.git/objects/b4/5245ba12f4f031aa9e95c930c37bc85212ef44
-.git/objects/c3/6a8d77143de389841313d6eb99900d2b97ead4
-.git/objects/c6/1da0558851e649c354c0dfc73629fa253dfc89
-.git/objects/c7/be66a8c788f0d8a3793dfd9a7fd7fc906d3b53
-.git/objects/cf/2d466701c28b92b80abe2e79293e2b8d2c886c
-.git/objects/d3/786129590ff86a3296ca4e17493af92e82c715
-.git/objects/e1/eaa77b8792876d4481dc985064b19042772d58
-.git/objects/e5/5d38dd203fcab027423ef0c7f19faa7aa533db
-.git/objects/pack/pack-66b233cbc136bfadde29c1582c21e7333feb9c07.idx
-.git/objects/pack/pack-66b233cbc136bfadde29c1582c21e7333feb9c07.pack
-.git/ORIG_HEAD
-.git/packed-refs
-.git/refs/heads/master
-.git/refs/remotes/origin/HEAD
-.git/refs/remotes/origin/master
Changes
-examples/moose_room.pl
-IDEAS
inc/Module/Install.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
@@ -81,7 +8,6 @@
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
-lab/dec.pl
lib/MooseX/Daemonize.pm
lib/MooseX/Daemonize/Core.pm
lib/MooseX/Daemonize/Pid.pm
@@ -98,6 +24,5 @@
t/02.stdout.t
t/10.pidfile.t
t/20.core.t
+t/21.core-back-compat.t
t/30.with_pid_file.t
-t/pod-coverage.t
-t/pod.t
Modified: branches/upstream/libmoosex-daemonize-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/MANIFEST.SKIP?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/MANIFEST.SKIP (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/MANIFEST.SKIP Sun Jul 11 19:42:24 2010
@@ -5,6 +5,7 @@
\.bak$
CVS
\.svn
+\.git
\.DS_Store
cover_db
\..*\.sw.?$
@@ -18,4 +19,7 @@
^TODO$
^PLANS$
^benchmarks
-^\._.*$
+^\._.*$
+IDEAS
+examples
+lab
Modified: branches/upstream/libmoosex-daemonize-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/META.yml?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/META.yml (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/META.yml Sun Jul 11 19:42:24 2010
@@ -26,4 +26,4 @@
MooseX::Types::Path::Class: 0
resources:
license: http://dev.perl.org/licenses/
-version: 0.10
+version: 0.12
Modified: branches/upstream/libmoosex-daemonize-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/README?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/README (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/README Sun Jul 11 19:42:24 2010
@@ -1,4 +1,4 @@
-MooseX-Daemonize version 0.10
+MooseX-Daemonize version 0.12
INSTALLATION
Modified: branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize.pm?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize.pm (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize.pm Sun Jul 11 19:42:24 2010
@@ -3,7 +3,7 @@
use Moose::Role;
use MooseX::Types::Path::Class;
-our $VERSION = "0.10";
+our $VERSION = '0.12';
with 'MooseX::Daemonize::WithPidFile',
'MooseX::Getopt';
@@ -368,6 +368,23 @@
If true, the process won't background. Useful for debugging. This option can
be set via Getopt's -f.
+=item I<no_double_fork Bool>
+
+If true, the process will not perform the typical double-fork, which is extra
+added protection from your process accidentally aquiring a controlling terminal.
+More information can be found by Googling "double fork daemonize".
+
+=item I<ignore_zombies Bool>
+
+If true, the process will not clean up zombie processes.
+Normally you don't want this.
+
+=item I<dont_close_all_files Bool>
+
+If true, the objects open filehandles will not be closed when daemonized.
+Normally you don't want this.
+
+
=item I<is_daemon Bool>
If true, the process is the backgrounded daemon process, if false it is the
Modified: branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Core.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Core.pm?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Core.pm (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Core.pm Sun Jul 11 19:42:24 2010
@@ -3,7 +3,7 @@
use MooseX::Getopt; # to load the NoGetopt metaclass
use Moose::Role;
-our $VERSION = '0.10';
+our $VERSION = '0.12';
use POSIX ();
@@ -18,11 +18,43 @@
default => sub { 0 },
);
+has ignore_zombies => (
+ metaclass => 'Getopt',
+ isa => 'Bool',
+ is => 'rw',
+ default => sub { 0 },
+);
+
+has no_double_fork => (
+ metaclass => 'Getopt',
+ isa => 'Bool',
+ is => 'rw',
+ default => sub { 0 },
+);
+
+has dont_close_all_files => (
+ metaclass => 'Getopt',
+ isa => 'Bool',
+ is => 'rw',
+ default => sub { 0 },
+);
+
+sub _get_options {
+ my ($self, %options) = @_;
+ # backwards compability.. old code might be calling daemon_fork/_detach with options
+ foreach my $opt (qw( ignore_zombies no_double_fork dont_close_all_files )) {
+ $self->$opt( $options{ $opt } ) if ( defined $options{ $opt } );
+ }
+}
+
+
sub daemon_fork {
my ($self, %options) = @_;
+ $self->_get_options( %options );
+
$SIG{CHLD} = 'IGNORE'
- if $options{ignore_zombies};
+ if $self->ignore_zombies;;
if (my $pid = fork) {
return $pid;
@@ -38,12 +70,13 @@
return unless $self->is_daemon; # return if parent ...
+ $self->_get_options( %options );
# now we are in the daemon ...
(POSIX::setsid) # set session id
|| confess "Cannot detach from controlling process";
- unless ($options{no_double_fork}) {
+ unless ( $self->no_double_fork ) {
$SIG{'HUP'} = 'IGNORE';
fork && exit;
}
@@ -51,7 +84,7 @@
chdir '/'; # change to root directory
umask 0; # clear the file creation mask
- unless ($options{dont_close_all_files}) {
+ unless ( $self->dont_close_all_files ) {
# get the max numnber of possible file descriptors
my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX );
$openmax = 64 if !defined($openmax) || $openmax < 0;
@@ -153,38 +186,54 @@
This attribute is used to signal if we are within the
daemon process or not.
+=item I<no_double_fork (is => rw, isa => Bool)>
+
+Setting this attribute to true will cause this method to not perform the
+typical double-fork, which is extra added protection from your process
+accidentally aquiring a controlling terminal. More information can be
+found above, and by Googling "double fork daemonize".
+
+If you the double-fork behavior off, you might want to enable the
+I<ignore_zombies>.
+
+=item I<ignore_zombies (is => rw, isa => Bool)>
+
+Setting this attribute to a true value will result in setting the C<$SIG{CHLD}>
+handler to C<IGNORE>. This tells perl to clean up zombie processes. By
+default, and for the most part you don't I<need> it, only when you turn off
+the double fork behavior (with the I<no_double_fork> attribute)
+do you sometimes want this behavior.
+
+=item I<dont_close_all_files (is => rw, isa => Bool)>
+
+Setting this attribute to true will cause it to skip closing all the
+filehandles. This is useful if you are opening things like sockets
+and such in the pre-fork.
+
=back
=head1 METHODS
=over
-=item B<daemon_fork (%options)>
+=item B<daemon_fork (?%options)>
This forks off the child process to be daemonized. Just as with
the built in fork, it returns the child pid to the parent process,
0 to the child process. It will also set the is_daemon flag
appropriately.
-The C<%options> available for this function are:
-
-=over 4
-
-=item I<ignore_zombies>
-
-Setting this key to a true value will result in setting the C<$SIG{CHLD}>
-handler to C<IGNORE>. This tells perl to clean up zombie processes. By
-default, and for the most part you don't I<need> it, only when you turn off
-the double fork behavior (with the I<no_double_fork> option) in C<daemon_detach>
-do you sometimes want this behavior.
-
-=back
-
-=item B<daemon_detach (%options)>
+The C<%options> argument remains for backwards compatability, but
+it is suggested that you use the attributes listed above instead.
+
+=item B<daemon_detach (?%options)>
This detaches the new child process from the terminal by doing
the following things.
+The C<%options> argument remains for backwards compatability, but
+it is suggested that you use the attributes listed above instead.
+
=over 4
=item Becomes a session leader
@@ -205,7 +254,8 @@
=item Closes all open file descriptors.
-See below for information on how to change this part of the process.
+See the I<dont_close_all_files> attribute for information on how to
+change this part of the process.
=item Reopen STDERR, STDOUT & STDIN to /dev/null
@@ -214,39 +264,17 @@
in either of these variables and redirect STDOUT and/or STDERR to those
files. This is useful for debugging and/or testing purposes.
-=back
-
-The C<%options> available for this function are:
-
-=over 4
-
-=item I<no_double_fork>
-
-Setting this option to true will cause this method to not perform the
-typical double-fork, which is extra added protection from your process
-accidentally aquiring a controlling terminal. More information can be
-found above, and by Googling "double fork daemonize".
-
-If you the double-fork behavior off, you might want to enable the
-I<ignore_zombies> behavior in the C<daemon_fork> method.
-
-=item I<dont_close_all_files>
-
-Setting this option to true will cause it to skip closing all the
-filehandles, this is useful if you are opening things like sockets
-and such in the pre-fork.
-
-=back
-
B<NOTE>
If called from within the parent process (the is_daemon flag is set to
false), this method will simply return and do nothing.
-=item B<daemonize (%options)>
-
-This will simply call C<daemon_fork> followed by C<daemon_detach>, it will
-pass any C<%options> onto both methods.
+=item B<daemonize (?%options)>
+
+This will simply call C<daemon_fork> followed by C<daemon_detach>.
+
+The C<%options> argument remains for backwards compatability, but
+it is suggested that you use the attributes listed above instead.
=item meta()
@@ -286,7 +314,7 @@
terminal.
That said, you don't always want this to be the behavior, so you are
-free to specify otherwise using the C<%options>.
+free to specify otherwise using the I<no_double_fork> attribute.
=item Note about zombies
@@ -295,7 +323,7 @@
the init process. However, sometimes the double-fork is more than you
really need, and you want to keep your daemon processes a little closer
to you. In this case you have to watch out for zombies, you can avoid then
-by just setting the C<ignore_zombies> option (see above).
+by just setting the I<ignore_zombies> attribute (see above).
=back
Modified: branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid.pm?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid.pm (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid.pm Sun Jul 11 19:42:24 2010
@@ -2,7 +2,7 @@
use strict; # because Kwalitee is pedantic
use Moose;
use Moose::Util::TypeConstraints;
-our $VERSION = '0.10';
+our $VERSION = '0.12';
coerce 'MooseX::Daemonize::Pid'
=> from 'Int'
Modified: branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid/File.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid/File.pm?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid/File.pm (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/Pid/File.pm Sun Jul 11 19:42:24 2010
@@ -3,7 +3,7 @@
use Moose;
use Moose::Util::TypeConstraints;
-our $VERSION = '0.10';
+our $VERSION = '0.12';
use MooseX::Types::Path::Class;
use MooseX::Getopt::OptionTypeMap;
Modified: branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/WithPidFile.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/WithPidFile.pm?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/WithPidFile.pm (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/lib/MooseX/Daemonize/WithPidFile.pm Sun Jul 11 19:42:24 2010
@@ -2,7 +2,7 @@
use strict; # cause Perl::Critic errors are annoying
use MooseX::Getopt; # to load the Getopt metaclass
use Moose::Role;
-our $VERSION = '0.10';
+our $VERSION = '0.12';
use MooseX::Daemonize::Pid::File;
Modified: branches/upstream/libmoosex-daemonize-perl/current/lib/Test/MooseX/Daemonize.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/lib/Test/MooseX/Daemonize.pm?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/lib/Test/MooseX/Daemonize.pm (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/lib/Test/MooseX/Daemonize.pm Sun Jul 11 19:42:24 2010
@@ -1,7 +1,7 @@
package Test::MooseX::Daemonize;
use strict;
-our $VERSION = '0.10';
+our $VERSION = '0.12';
our $AUTHORITY = 'cpan:PERIGRIN';
# BEGIN CARGO CULTING
Modified: branches/upstream/libmoosex-daemonize-perl/current/t/20.core.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/t/20.core.t?rev=60232&op=diff
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/t/20.core.t (original)
+++ branches/upstream/libmoosex-daemonize-perl/current/t/20.core.t Sun Jul 11 19:42:24 2010
@@ -13,7 +13,7 @@
BEGIN {
use_ok('MooseX::Daemonize::Core');
- use_ok('MooseX::Daemonize::Pid');
+ use_ok('MooseX::Daemonize::Pid');
}
use constant DEBUG => 0;
@@ -24,11 +24,11 @@
{
package MyFooDaemon;
use Moose;
-
+
with 'MooseX::Daemonize::Core';
-
+
has 'daemon_pid' => (is => 'rw', isa => 'MooseX::Daemonize::Pid');
-
+
# capture the PID from the fork
around 'daemon_fork' => sub {
my $next = shift;
@@ -39,27 +39,26 @@
);
}
};
-
+
sub start {
- my $self = shift;
+ my $self = shift;
# tell it to ignore zombies ...
- $self->daemonize(
- ignore_zombies => 1,
- no_double_fork => 1,
- );
+ $self->ignore_zombies( 1 );
+ $self->no_double_fork( 1 );
+ $self->daemonize;
return unless $self->is_daemon;
# change to our local dir
# so that we can debug easier
chdir $dir;
# make it easy to find with ps
$0 = 'test-app';
- $SIG{INT} = sub {
- print "Got INT! Oh Noes!";
+ $SIG{INT} = sub {
+ print "Got INT! Oh Noes!";
exit;
- };
+ };
while (1) {
- print "Hello from $$\n";
- sleep(10);
+ print "Hello from $$\n";
+ sleep(10);
}
exit;
}
Added: branches/upstream/libmoosex-daemonize-perl/current/t/21.core-back-compat.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-daemonize-perl/current/t/21.core-back-compat.t?rev=60232&op=file
==============================================================================
--- branches/upstream/libmoosex-daemonize-perl/current/t/21.core-back-compat.t (added)
+++ branches/upstream/libmoosex-daemonize-perl/current/t/21.core-back-compat.t Sun Jul 11 19:42:24 2010
@@ -1,0 +1,103 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More 'no_plan';
+use Test::Exception;
+use Test::Moose;
+use File::Temp qw(tempdir);
+use File::Spec::Functions;
+
+my $dir = tempdir( CLEANUP => 1 );
+
+BEGIN {
+ use_ok('MooseX::Daemonize::Core');
+ use_ok('MooseX::Daemonize::Pid');
+}
+
+use constant DEBUG => 0;
+
+$ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt');
+$ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt');
+
+{
+ package MyFooDaemon;
+ use Moose;
+
+ with 'MooseX::Daemonize::Core';
+
+ has 'daemon_pid' => (is => 'rw', isa => 'MooseX::Daemonize::Pid');
+
+ # capture the PID from the fork
+ around 'daemon_fork' => sub {
+ my $next = shift;
+ my $self = shift;
+ if (my $pid = $self->$next(@_)) {
+ $self->daemon_pid(
+ MooseX::Daemonize::Pid->new(pid => $pid)
+ );
+ }
+ };
+
+ sub start {
+ my $self = shift;
+ # tell it to ignore zombies ...
+ $self->daemonize(
+ ignore_zombies => 1,
+ no_double_fork => 1,
+ );
+ return unless $self->is_daemon;
+ # change to our local dir
+ # so that we can debug easier
+ chdir $dir;
+ # make it easy to find with ps
+ $0 = 'test-app';
+ $SIG{INT} = sub {
+ print "Got INT! Oh Noes!";
+ exit;
+ };
+ while (1) {
+ print "Hello from $$\n";
+ sleep(10);
+ }
+ exit;
+ }
+}
+
+my $d = MyFooDaemon->new;
+isa_ok($d, 'MyFooDaemon');
+does_ok($d, 'MooseX::Daemonize::Core');
+
+lives_ok {
+ $d->start;
+} '... successfully daemonized from (' . $$ . ')';
+
+my $p = $d->daemon_pid;
+isa_ok($p, 'MooseX::Daemonize::Pid');
+
+ok($p->is_running, '... the daemon process is running (' . $p->pid . ')');
+
+my $pid = $p->pid;
+if (DEBUG) {
+ diag `ps $pid`;
+ diag "-------";
+ diag `ps -x | grep test-app`;
+ diag "-------";
+ diag "killing $pid";
+}
+kill INT => $p->pid;
+diag "killed $pid" if DEBUG;
+sleep(2);
+if (DEBUG) {
+ diag `ps $pid`;
+ diag "-------";
+ diag `ps -x | grep test-app`;
+}
+
+ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')');
+
+unlink $ENV{MX_DAEMON_STDOUT};
+unlink $ENV{MX_DAEMON_STDERR};
+
+
More information about the Pkg-perl-cvs-commits
mailing list