Class-Autouse

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        print 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
    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().

   Syntactic Sugar Example

lib/Class/Autouse.pm  view on Meta::CPAN

			}
		}
	}

	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


=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.250 second using v1.01-cache-2.11-cpan-00829025b61 )