Accessor to module
[email protected] (Bianka Martinovic)
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
Hello,
when playing around with Moose I tried to create an accessor like this:
has 'loader' => (
is => 'ro',
isa => 'CM::Module::Loader',
required => 1,
lazy => 1,
default => sub {
CM::Module::Loader->new;
},
);
I realized that the new() method of CM::Module::Loader is called
whenever I use the accessor. (Well, use in 'submodules' which 'extend'
the class the accessor is defined in.) This is some overhead I don't
like in my case. ;)
So, I tried to prevent it by changing the 'default' to:
default => sub {
return $CM::Controller::_loader ||= do {
require CM::Module::Loader;
CM::Module::Loader->new; # return of the do
};
},
This works, but I'm not sure if this is the perfect way to do it. I'd
welcome your suggestions.
Thank you.
Greetings from 'German Perl Hacker' Bianka.