Subject: | Allow min_spare and max_spare with values of 0 |
Hi,
We wanted to run our POE::Component::Daemon code the same way for different devel and live environments, which led us to want, in some situations, to only have one child forked off, but still managed the same way.
To do this, we figured we needed min_spare of 0.
Because the defaults are imposed with truth or, this isn't possible.
The attached patch just replaces ||= with //=.
If you want to stay compatible with < 5.10, then I guess you can implement it manually.
Either way, it'd be great if you could support our use case, so that we don't have to keep darkpanning your module!
Plus, you know, that means you get a release in 2013!
Regards
Gareth
(gbjk on irc.perl.org)
Subject: | Daemon.pm.patch |
--- Daemon.pm 2013-07-12 19:58:10.935060224 +0100
+++ /home/staff/gbjk/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/POE/Component/Daemon.pm 2013-07-12 19:59:31.531075140 +0100
@@ -201,22 +201,22 @@
my($self)=@_;
if($self->{max_children}) {
if($self->{max_spare}) {
- $self->{min_spare} ||= int($self->{max_spare} /2);
+ $self->{min_spare} //= int($self->{max_spare} /2);
}
else {
- $self->{min_spare} ||= int($self->{max_children} * 0.2);
- $self->{max_spare} ||= int($self->{max_children} * 0.8);
+ $self->{min_spare} //= int($self->{max_children} * 0.2);
+ $self->{max_spare} //= int($self->{max_children} * 0.8);
}
- $self->{min_spare} ||=1;
- $self->{max_spare} ||=2;
+ $self->{min_spare} //=1;
+ $self->{max_spare} //=2;
if( $self->{max_spare} < $self->{min_spare} ) {
confess "Max_spare can't be smaller then $self->{min_spare}; madness follows.";
}
}
else {
# We couldn't be here unless start_children is set
- $self->{min_spare} ||= $self->{start_children};
- $self->{max_spare} ||= 2*$self->{min_spare};
+ $self->{min_spare} //= $self->{start_children};
+ $self->{max_spare} //= 2*$self->{min_spare};
$self->{max_children} = $self->{start_children}
+ $self->{max_spare};
}