httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Wheeler <>
Subject Re: libapreq-1.2 release candidate
Date Sat, 03 May 2003 23:18:57 GMT
On Saturday, May 3, 2003, at 03:22  AM, Stas Bekman wrote:

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

Yes, I agree it's ugly.

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

That wont' work because import() is a method in Exporter; it's not in 
the Apache::Test package.

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

No, that won't work, because you would be trying to import the 
functions in Apache::Test into the Apache::Test package.

I just took a look at Exporter::import, and it uses both the class name 
in the first argument in order to find the subroutines to export and 
the caller for the namespace to import them into. I hadn't made this 
connection before, and should have looked at import() before. The 
upshot is that it never worked because I hadn't changed the first 
argument to import() to 'Apache::Test' -- your example above tickled 
that for me. So here's the best solution I can see:

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

This way, the caller is the package that C<use>d Apache::Test (thanks 
to the goto), and, because the first argument is 'Apache::Test', 
import() now knows where to find the functions to actually import.

> Cool.
> Any alternative naming suggestions to TestLoad?

How 'bout Apache::Tester? If it sticks, and people just use that, you 
might eventually be able to eliminate Apache::Test and be done with 
this problem.



David Wheeler                                     AIM: dwTheory                              ICQ: 15726394
                                                Yahoo!: dew7e
Kineticode. Setting knowledge in motion.[sm]

View raw message