Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

appropriate name/place for module which does JIT loading of modules

by sakoht (Initiate)
on Dec 15, 2007 at 19:54 UTC ( [id://657225]=perlquestion: print w/replies, xml ) Need Help??

sakoht has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I have some code I'm packaging for CPAN release, which includes some logic to do JIT loading of modules by implementing UNIVERSAL::AUTOLOAD.

Given that there is only one UNIVERSAL::AUTOLOAD, I broke that part out into a module, and added an API so that the feature can be shared, tentatively calling it Class::AutoLoader.

ex.:

use Class::AutoLoader "My::Thing"; use Class::AutoLoader qr/SomeNamespace::.*/; use Class::AutoLoader \&my_class_generator;

I talked with Stevan Little and Rob Kinyon, who wrote Class::LazyLoad, about merging features. Stevan sent me to Rob, and Rob suggested I post here for suggestions.

Rob (Dragonchild) suggested I indicate he had "vague reservations I can't explain".
He mentioned that perl6 has had something like this for a while, and that following that name/API might be good. (I think its a pragma, "use autoloader ....");

Any comments or suggestions on naming, API, other modules which do this I haven't found, etc?

The source is 206 lines, including POD, so I'd be glad to post it or mail it to the curious if the SYNOPSIS above isn't sufficient.

Thanks in advance...

Replies are listed 'Best First'.
Re: appropriate name/place for module which does JIT loading of modules
by Joost (Canon) on Dec 15, 2007 at 20:45 UTC
      Good point. It will really work for any package/module pair where the names are 1:1.
Re: appropriate name/place for module which does JIT loading of modules
by shmem (Chancellor) on Dec 16, 2007 at 17:57 UTC
    Are you aware of autouse, which is in the core?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Thanks for the feedback.

      I was not aware of the autouse pragma. Sadly, it requires that the module name be explicit (no regex, no callback), and that the subroutine names which should trigger loading also be explicit. It seems at first glance to do what Class::LazyLoad does, though there may be subtle details I've missed.

      I did discover Class::Autouse and also the "later" pragma in the process of finding "autouse", though. These both much closer to my module.

      Both of these require explicit package names, but use AUTOLOAD so they can be method agnostic. The "later" pragma seems to have more features, but none I need, and with the additional restriction that it only applies in the namespace it is used-from, which will break things for me.

      Thanks for pointing me in the right direction!
      I'll contact the authors now...

        I've sent a patch to Adam Kennedy, author of Class::Autouse, after some discussion. It seems that this is the one of the group which is actually used in production, while the others are proof-of-concept, experiments, etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://657225]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-28 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found