Permalink
Browse files

localize $? on destructor.

  • Loading branch information...
1 parent 9803fa3 commit ae35387147caabd4d614990eadd72557de7c186e @tokuhirom committed Aug 15, 2011
Showing with 23 additions and 1 deletion.
  1. +6 −0 README.mkdn
  2. +17 −1 lib/Proc/Guard.pm
View
@@ -81,6 +81,12 @@ Starts process.
Stops process.
+# VARIABLES
+
+- $Proc::Guard::EXIT_STATUS
+
+The last exit status code by `$proc->stop`.
+
# AUTHOR
Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM>
View
@@ -5,6 +5,8 @@ use 5.00800;
our $VERSION = '0.05';
use Carp ();
+our $EXIT_STATUS;
+
# functional interface
our @EXPORT = qw/proc_guard/;
use Exporter 'import';
@@ -72,13 +74,17 @@ sub stop {
kill $sig, $self->pid;
1 while waitpid( $self->pid, 0 ) <= 0;
+ $EXIT_STATUS = $?;
$self->pid(undef);
}
sub DESTROY {
my $self = shift;
- $self->stop() if defined $self->pid && $$ == $self->{_owner_pid};
+ if (defined $self->pid && $$ == $self->{_owner_pid}) {
+ local $?; # "END" function and destructors can change the exit status by modifying $?.(perldoc -f exit)
+ $self->stop()
+ }
}
1;
@@ -181,6 +187,16 @@ Stops process.
=back
+=head1 VARIABLES
+
+=over 4
+
+=item $Proc::Guard::EXIT_STATUS
+
+The last exit status code by C<< $proc->stop >>.
+
+=back
+
=head1 AUTHOR
Tokuhiro Matsuno E<lt>tokuhirom AAJKLFJEF GMAIL COME<gt>

0 comments on commit ae35387

Please sign in to comment.