Class-AutoGenerate
view release on metacpan or search on metacpan
lib/Class/AutoGenerate/Declare.pm view on Meta::CPAN
};
If we included the rule above, intantiated the class loader, and then ran:
use My::Flipper;
A class would be generated named C<My::Flipper> that uses C<My::Base::Flipper> as its only base class, imports the C<looks_like_number> function from L<Scalar::Util>, defines a scalar package variable C<$scalar> set to 14, an array package variable, ...
=cut
sub generates(&) { shift }
=head2 declare { ... };
A declare block may be used to wrap your class loader code, but is not required. The block will be passed a single argument, C<$self>, which is the initialized class loader object. It is helpful if you need a reference to your C<$self>.
For example,
package My::Classloader;
use Class::Autogenerate -base;
lib/Class/AutoGenerate/Declare.pm view on Meta::CPAN
# later...
use My::Classloader;
BEGIN { My::Classloader->new( base => 'Foo' ) };
You may have multiple C<declare> blocks in your class loader.
It is important to note that the C<declare> block modifies the semantics of how the class loader is built. Normally, the C<requiring> rules are all generated and associated with the class loader package immediately. A C<declare> block causes all rule...
=cut
sub declare(&) {
my $code = shift;
# Wrap that code in a little more code that sets things up
my $declaration = sub {
my $self = shift;
# $declare_to signals to requiring to register rules differently
local $declare_to = [];
$code->($self);
return @$declare_to;
( run in 2.145 seconds using v1.01-cache-2.11-cpan-49f99fa48dc )