On Fri, 8 Nov 2002, Dmitri Tikhonov wrote:

> 
> 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.


Reply via email to