After talking with a coworker, I came up with a scheme that would allow me to do this:
#!/usr/bin/perl -w use strict; use Class::WhenNeeded 'Foo'; my $customer = Foo::Customer->new; my $company = Foo::Company->new; my $salesrep = Foo::Company::SalesRep->new;
In other words, you to skip long declarations of "using" all of the packages (in my scheme, this happens at runtime on an "as needed" basis).
So here I am, thinking this is such an interesting idea and frankly, I haven't seen anyone do anything this general purpose before with this type of syntax. So I post this to Perlmonks.
The same day, BrowserUK poses a virtually identical problem. What a weird frickin' coincidence. I feel like a bit stupid as it almost looks like I stole someone elsess idea (and hence this long post).
->
notation to do the same sort of thing:I just hand-code thepackage Foo;
sub Foo::Bar { require Foo::Bar; 'Foo::Bar' }
package Whatever;
use Foo;
my $bar = Foo->Bar->new;
Bar
method, but then I don't need multi-level stuff like my $qux = Foo->Bar->Baz->Qux->new
, which would be relatively easy with AUTOLOAD
.