Date: | Tue, 12 Nov 2002 12:03:08 -0500 |
From: | Rocco Caputo <troc [...] netrus.net> |
To: | bug-POE [...] rt.cpan.org |
Subject: | [dmitri@netilla.com: Re: POE::Wheel::Run add'l functionality.] |
----- Forwarded message from Dmitri Tikhonov <dmitri@netilla.com> -----
Date: Fri, 8 Nov 2002 18:36:42 -0500 (EST)
From: Dmitri Tikhonov <dmitri@netilla.com>
Subject: Re: POE::Wheel::Run add'l functionality.
To: poe@perl.org
On Fri, 8 Nov 2002, Dmitri Tikhonov wrote:
Show quoted text
>
> I am thinking of adding extra argument to POE::Wheel::Run's constructor:
>
> ProgramArgs => [@args],
>
>
> Where Program is a scalar, the behavior will be
> exec($prog . ' ' . join(' ', @$args);
>
> Where Program is an array ref, the behavior will be
> exec(@$prog, @$args);
>
> Where Program is a code ref, the behavior will be
> $program->(@$args);
>
>
> The reason for doing this is that I create POE::Wheel::Run inside
> POE::Session, and Program is a closure generated based on arguments to
> POE::Session. I do not want it to be a closure, however. Thus, this evil
> intent of mine.
>
> What do you guys think? And would my patch be accepted?
>
> - Dmitri.
>
Here's the patch against Run.pm rev. 1.35:
*** Run.pm-1.35 Fri Nov 8 17:08:01 2002
--- Run.pm Fri Nov 8 16:30:41 2002
***************
*** 97,102 ****
--- 97,107 ----
my $program = delete $params{Program};
croak "$type needs a Program parameter" unless defined $program;
+ my $args = delete $params{ProgramArgs};
+ croak "ProgramArgs must be ARRAY reg"
+ if (defined($args) && 'ARRAY' ne ref($args));
+ my @args = (defined($args) ? @$args : ());
+
my $priority_delta = delete $params{Priority};
$priority_delta = 0 unless defined $priority_delta;
***************
*** 336,345 ****
# Exec the program depending on its form.
if (ref($program) eq 'ARRAY') {
! exec(@$program) or die "can't exec (@$program) in child pid $$: $!";
}
elsif (ref($program) eq 'CODE') {
! $program->();
# In case flushing them wasn't good enough.
close STDOUT if defined fileno(STDOUT);
--- 341,351 ----
# Exec the program depending on its form.
if (ref($program) eq 'ARRAY') {
! exec(@$program, @args)
! or die "can't exec (@$program) in child pid $$: $!";
}
elsif (ref($program) eq 'CODE') {
! $program->(@args);
# In case flushing them wasn't good enough.
close STDOUT if defined fileno(STDOUT);
***************
*** 350,356 ****
exit(0);
}
else {
! exec($program) or die "can't exec ($program) in child pid $$: $!";
}
die "insanity check passed";
--- 356,363 ----
exit(0);
}
else {
! exec($program . ' ' . join(' ', @args))
! or die "can't exec ($program) in child pid $$: $!";
}
die "insanity check passed";
I tested it with this example for all three kinds of arguments:
http://poe.perl.org/?POE_Cookbook/Child_Processes_2
Tell me what you think.
- Dmitri.
Show quoted text----- End forwarded message -----