Jeff wrote:
> So here is my strategy that I would like a sanity check from anyone on.  
> Go through and quickly clean up my existing code by adding use strict 
> and localizing all my variables (with 'my' and 'local' for special 
> variables) and then run is under mod_Perl using the Apache::PerlRun.  
> Write all my new code so that it will run under Apache::Registry and 
> then when I have spare time (ya right) go work on porting the older code.

PerlRun works reasonably well, and I have used it to quickly port a 
large amount of legacy CGI code that made extensive use of globals. 
However, it is only very slightly different from Apache::Regsitry.  The 
difference is that globals get cleared after each invocation, so you 
don't have to worry about them retaining values.

You will not have problems with subroutines creating closures if you're 
using global variables.  You also won't have problems if you're passing 
varaibles to subroutines.  You will only have trouble if you use 
lexicals in your subs that are defined outside the scope of the sub.

This is bad:

my $foo = 7;
print_foo();

sub print_foo {
     print "$foo\n";
}

But this is not:

my $foo = 7;
print_foo($foo);

sub print_foo {
     my $foo = shift;
     print "$foo\n";
}

One thing that I had to change when moving to PerlRun was that the 
existing scripts made extensive use of libraries that were not proper 
modules, i.e. they did not declare packages, but just used a simple 
"require lib.pl" to define a bunch of stuff in the current namespace. 
That doesn't work with PerlRun or Registry.  There are various 
approaches for dealing with this, the quickest and worst being to change 
the "require file" to a "do file".  The best is to make them actual modules.

- Perrin

Reply via email to