Class-MakeMethods
view release on metacpan or search on metacpan
MakeMethods.pm view on Meta::CPAN
=item Template (See L<Class::MakeMethods::Template>.)
The Template subclasses provide an open-ended structure for objects
that assemble Perl code on the fly into cachable closure-generating
subroutines; if the method you need isn't included, you can extend
existing methods by re-defining just the snippet of code that's
different.
Class::MakeMethods::Template extends MakeMethods with a text
templating system that can assemble Perl code fragments into a
desired subroutine. The code for generated methods is eval'd once
for each type, and then repeatedly bound as closures to method-specific
data for better performance.
Templates for dozens of types of constructor, accessor, and mutator
methods are included, ranging from from the mundane (constructors
and value accessors for hash and array slots) to the esoteric
(inheritable class data and "inside-out" accessors with external
indexes).
MakeMethods/Basic/Array.pm view on Meta::CPAN
Each accessor method claims the next available spot in the array
to store its value in.
The mapping between method names and array positions is stored in
a hash named %FIELDS in the target package. When the first positional
accessor is defined for a package, its %FIELDS are initialized by
searching its inheritance tree.
B<Caution>: Subclassing packages that use positional accessors is
somewhat fragile, since you may end up with two distinct methods
assigned to the same position. Specific cases to avoid are:
=over 4
=item *
If you inherit from more than one class with positional accessors,
the positions used by the two sets of methods will overlap.
=item *
MakeMethods/Composite.pm view on Meta::CPAN
$VERSION = 1.000;
use strict;
use Class::MakeMethods::Standard '-isasubclass';
use Carp;
########################################################################
=head2 About Composite Methods
The methods generated by Class::MakeMethods::Composite are assembled
from groups of "fragment" subroutines, each of which provides some
aspect of the method's behavior.
You can add pre- and post- operations to any composite method.
package MyObject;
use Class::MakeMethods::Composite::Hash (
new => 'new',
scalar => [
'foo' => {
'pre_rules' => [
MakeMethods/Composite.pm view on Meta::CPAN
$value
} else {
my @value = @_;
$Method->{result} = \@value;
@value;
}
}
sub _build_composite {
my $class = shift;
my $fragments = shift;
map {
my $method = $_;
my @fragments = @{ $fragments->{''} };
foreach my $flagname ( grep $method->{$_}, qw/ permit modifier / ) {
my $value = $method->{$flagname};
my $fragment = $fragments->{$value}
or croak "Unsupported $flagname flag '$value'";
push @fragments, @$fragment;
}
_bind_composite( $method, @fragments );
} $class->get_declarations(@_)
}
sub _assemble_fragments {
my $method = shift;
my @fragments = @_;
while ( scalar @fragments ) {
my ($rule, $sub) = splice( @fragments, 0, 2 );
if ( $rule =~ s/\A\+// ) {
unshift @{$method->{"${rule}_rules"}}, $sub
} elsif ( $rule =~ s/\+\Z// ) {
push @{$method->{"${rule}_rules"}}, $sub
} elsif ( $rule =~ /\A\w+\Z/ ) {
@{$method->{"${rule}_rules"}} = $sub;
} else {
croak "Unsupported rule type '$rule'"
}
}
}
sub _bind_composite {
my $method = shift;
_assemble_fragments( $method, @_ );
if ( my $subs = $method->{"init_rules"} ) {
foreach my $sub ( @$subs ) {
&$sub( $method );
}
}
$method->{name} => sub {
local $Method = $method;
local $Method->{args} = [ @_ ];
local $Method->{result};
local $Method->{scratch};
MakeMethods/Composite/Array.pm view on Meta::CPAN
Each accessor method is assigned the next available array index at
which to store its value.
The mapping between method names and array positions is stored in
a hash named %FIELDS in the declaring package. When a package
declares its first positional accessor, its %FIELDS are initialized
by searching its inheritance tree.
B<Warning>: Subclassing packages that use positional accessors is
somewhat fragile, since you may end up with two distinct methods assigned to the same position. Specific cases to avoid are:
=over 4
=item *
If you inherit from more than one class with positional accessors,
the positions used by the two sets of methods will overlap.
=item *
MakeMethods/Standard/Array.pm view on Meta::CPAN
Each accessor method is assigned the next available array index at
which to store its value.
The mapping between method names and array positions is stored in
a hash named %FIELDS in the declaring package. When a package
declares its first positional accessor, its %FIELDS are initialized
by searching its inheritance tree.
B<Warning>: Subclassing packages that use positional accessors is
somewhat fragile, since you may end up with two distinct methods assigned to the same position. Specific cases to avoid are:
=over 4
=item *
If you inherit from more than one class with positional accessors,
the positions used by the two sets of methods will overlap.
=item *
MakeMethods/Template/Generic.pm view on Meta::CPAN
This package provides a variety of abstract interfaces for constructors
and accessor methods, which form a common foundation for meta-methods
provided by the Hash, Scalar, Flyweight, Static, PackageVar, and
ClassVar implementations.
Generally speaking, the Generic meta-methods define calling interfaces
and behaviors which are bound to differently scoped data by each
of those implementations.
(Note that those implementation classes are not subclasses of
Generic; instead they import various interfaces and code fragments
from the meta-method types defined here, by specifying '-import'
values which are processed by Class::MakeMethods's _metamethod_definition
mechanism.)
=cut
########################################################################
package Class::MakeMethods::Template::Generic;
( run in 0.748 second using v1.01-cache-2.11-cpan-364913b4093 )