Class-LazyLoad
view release on metacpan or search on metacpan
lib/Class/LazyLoad.pm view on Meta::CPAN
$VERSION
);
$VERSION = 0.04;
{
my @todo;
sub import
{
shift;
return if (caller)[0] eq 'Class::LazyLoad::Functions';
unless ( @_ ) {
push @todo, [ (caller)[0], 'new' ];
return;
}
foreach ( @_ ) {
if (ref($_) eq 'ARRAY') {
push @todo, $_;
} else {
push @todo, [ $_, 'new' ];
}
}
lib/Class/LazyLoad.pm view on Meta::CPAN
sub init_lazyloads { lazyload( @$_ ) for @todo }
INIT { init_lazyloads() }
}
use overload
'${}' => sub { _build($_[0]); $_[0] },
'%{}' => sub { _build($_[0]); $_[0] },
'&{}' => sub { _build($_[0]); $_[0] },
'@{}' => sub {
# C::LL does array access, so make sure it's not us before building.
return $_[0] if (caller)[0] eq __PACKAGE__;
_build($_[0]); $_[0]
},
nomethod => sub {
my $realclass = $_[0][1];
if ($_[3] eq '""') {
if (my $func = overload::Method($realclass, $_[3])) {
_build($_[0]);
return $_[0]->$func();
}
else {
lib/Class/LazyLoad/Functions.pm view on Meta::CPAN
my %is_exportable = map { $_ => undef } qw(
lazyload
unlazyload
lazyload_one
init_lazyloads
);
sub import
{
shift;
my $pkg = (caller)[0];
foreach (grep exists $is_exportable{$_}, @_)
{
local $^W = 0;
*{ $pkg . "::" . $_ } = \&{ 'Class::LazyLoad::' . $_ };
}
}
}
1;
( run in 1.088 second using v1.01-cache-2.11-cpan-1e74a51a04c )