Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday September 16, 2003
07:53 PM

Weird coincidence

[ #14745 ]

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • In my current project I'm using -> notation to do the same sort of thing:

    package Foo;
    sub Foo::Bar { require Foo::Bar; 'Foo::Bar' }
    package Whatever;
    use Foo;
    my $bar = Foo->Bar->new;

    I just hand-code the 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.

    What's not a coincidence is the (not very obvious) similarity here to Self [] and its "paths to objects" idiom/dogma.

  • However, I don't think it contains the actual method call magic.