Class-Autouse
view release on metacpan or search on metacpan
238239240241242243244245246247248249250251252253254255256257258259260261262263
Foo::Wrapper->class_method,
"\n"
;
sugar
This method is provided to support
"syntactic sugar"
: allowing the
developer to put things into Perl which
do
not look like regular Perl.
There are several ways to
do
this in Perl. Strategies which
require
that method
with
the superloader, and
with
class gnerators.
When Perl is unable to find a subroutine/method, and all of the class
loaders are exhausted, callbacks registered via sugar() are called. The
callbacks recieve the class name, method name, and parameters of the
call.
If the callback returns nothing, Class::Autouse will
continue
to iterate
through other callbacks. The first callback which returns a true value
will end iteration. That value is expected to be a CODE reference which
will respond to the AUTOLOAD call.
Note: The sugar callback(s) will only be fired by UNIVERSAL::AUTOLOAD
after
all other attempts at loading the class are done, and
after
fired by isa() or can(). It will fire repatedly
for
the same class. To
Syntactic Sugar Example
lib/Class/Autouse.pm view on Meta::CPAN
502503504505506507508509510511512513514515516517518519520521522
}
}
}
return
1;
}
sub
_try_loaders {
_debug(\
@_
, 0)
if
DEBUG;
my
(
$class
,
$function
,
@optional_args
) =
@_
;
# The function and args are only present to help callbacks whose main goal is to
# do "syntactic sugar" instead of really writing a class
# This allows us to shortcut out of re-checking a class
$TRIED_CLASS
{
$class
}++;
if
( _namespace_occupied(
$class
) ) {
$LOADED
{
$class
} = 1;
_load_ancestors(
$class
);
return
1;
}
lib/Class/Autouse.pm view on Meta::CPAN
1134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158=head2 sugar
This method is provided to support "syntactic sugar": allowing the developer
to put things into Perl which do not look like regular Perl. There are
several ways to do this in Perl. Strategies which require overriding
UNIVERSAL::AUTOLOAD can use this interface instead to share that method
with the superloader, and with class gnerators.
When Perl is unable to find a subroutine/method, and all of the class loaders
are exhausted, callbacks registered via sugar() are called. The callbacks
recieve the class name, method name, and parameters of the call.
If the callback returns nothing, Class::Autouse will continue to iterate through
other callbacks. The first callback which returns a true value will
end iteration. That value is expected to be a CODE reference which will respond
to the AUTOLOAD call.
Note: The sugar callback(s) will only be fired by UNIVERSAL::AUTOLOAD after all
other attempts at loading the class are done, and after attempts to use regular
AUTOLOAD to handle the method call. It is never fired by isa() or can(). It
will fire repatedly for the same class. To generate classes, use the
regular CODE ref support in autouse().
=head3 Syntactic Sugar Example
( run in 0.478 second using v1.01-cache-2.11-cpan-5f2e87ce722 )