httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: libapreq-1.2 release candidate
Date Sat, 03 May 2003 08:22:29 GMT
David Wheeler wrote:
> On Friday, May 2, 2003, at 05:56  PM, Stas Bekman wrote:
> 
>> Try this patch. It now forwards the import call.
>>
>> plus you have to do:
>>
>> find t/ | xargs perl -pi -e 's|use Apache::Test;|use Apache::TestLoad;|'
> 
> 
> When I do that in the Apache::Test sources, it seems that the import 
> still doesn't work:

Mea culpa, I haven't tested the latest change. I've assumed that this will work

[...]

> I imagine that this is because Apache::Test::import thinks that 
> Apache::TestLoad is the calling package and exports into 
> Apache::TestLoad instead of the package loading Apache::TestLoad. Hrm....
> 
> /me experiments for a while...
> 
> Okay, the only thing I found that works is this (in TestLoad.pm):
> 
> sub import {
>     my $caller = caller;
>     eval "package $caller; use Apache::Test;";
> }
> 
> This ensures that Apache::Test->import is called from the calling 
> package. I tried using a code ref, but it didn't work:
> 
> *import = \&Apache::Test::import;
> 
> sub import {
>     my $c = Apache::Test->can('import');
>     goto $c;
> }

shouldn't this be 'goto &$c' ala AUTOLOAD? I guess both ways work.

In any case the calling package is wrong in the above both versions, so it 
gets exported to the wrong namespace.

Either in the caller:

require Apache::TestLoad;
Apache::Test->import();

but that's ugly. Or:

sub import {
     my $package = shift;
     unshift @_, 'Apache::Test';
     goto &Apache::Test::import;
}


I don't remember if Exporter relies on the package name in the first arg, or 
the caller() function.

How about:

package Apache::TestLoad;
...
sub import {
     my $package = shift;
     package Apache::Test;
     Apache::Test->import(@_)
}

Again untested...
> Neither of these worked. :-( But the string eval works fine.
> 
> After that, I switched over to the libapreq sources fixed the test scripts:
> 
>> find t/ | xargs perl -pi -e 's|use Apache::Test;|use Apache::TestLoad;|'
> 
> 
> And all tests passed.

Cool.

Any alternative naming suggestions to TestLoad?


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Mime
View raw message