You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by ???? ???????? <vl...@immo.ru> on 2003/07/22 18:56:04 UTC

Which way is right for precompiling code in Apache perl handler:

1: doing like in Registry:

my $eval = join(
	'',
      'package ',
      $package,
      ';use Apache qw(exit);',
      'sub handler {',
      $sub,
      "\n}", # last line comment without newline?
      );
compile($eval);

sub compile {
    my $eval = shift;
    Apache->untaint($eval);
    eval $eval;
}

====== or
2:

my $eval = join(
	'',
      'package ',
      $package,
      ';use Apache qw(exit);',
      $sub                         
      );

precompile($eval);

sub precompile {
    my $eval = shift;
    ...
    eval("\$func = sub {" . $eval . "};");
    return $func
}

======= and calling it later
1:
my $cv = \&{"$package\::handler"};
eval { &{$cv}($r, @_) } if $r->seqno;

2:
$func = $SomePkgCache{..
&{$func};

-vlad



Re: Which way is right for precompiling code in Apache perl handler:

Posted by Perrin Harkins <pe...@elem.com>.
They are equivalent.  You can use either one.

- Perrin