Hi everyone,
I already sent this message as a posting to clpm.modules but thought
here might also be the right place to ask:
I am currently writing on a little module implementing a cached
autoloading of methods as described by Mark Jason Dominus in
http://plover.perl.com/yak/tricks/slide073.html
Short example:
A little class:
package Test;
use base qw(Autoloader::Cache);
use Autoloader::Cache
method1 => q{
sub {
my ($self, $arg) = @_;
$self->{arg} = $arg;
}},
method2 => q{
sub {
return shift->{arg};
}};
sub new { bless { }, shift }
Program instantiating this class:
package main;
use Test;
my $obj = new Test;
# dynamically created via Autoloader::Cache::AUTOLOAD
# method is compiled and diddled into the caller's namespace
$obj->method1("argument");
print $obj->method2;
# second call to a method already previously called:
# quicker since no longer the need for the autoloader
print $obj->method2;
The above also works with an arbitrary number of classes inheriting from
this module, methods and classes aren't mixed up due to a mapping
between methods and classes inside Autoloader::Cache.
Now the question for the namespace: As it can be seen, I have named it
Autoloader::Cache as for yet. Is this appropriate? My main concern is
whether I can just put a module under the top-level namespace of
Autoloader since there is actually only one module of that name so I am
not even sure whether that's a valid top-level namespace.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;