Method::Specialize - Generate per-subclass variants for your methods.


Method-Specialize documentation  | view source Contained in the Method-Specialize distribution.

Index


NAME

Top

Method::Specialize - Generate per-subclass variants for your methods.

SYNOPSIS

Top

    package Foo;
	use Method::Specialize;

    use namespace::clean;

    specializing_method foo => sub {
        my $class = shift;

        return sub {
            warn "Hi, i'm a version of Foo::bar specialized for $class";
        };
    };

    package Bar;
    use base qw(Foo);

    Bar->foo; # calls the generator when needed, generally goes to cache

DESCRIPTION

Top

This package uses Class::MethodCache to create per-subclass versions of a method.

This is useful for for removing dynamism from generated code.

The generated versions will be invalidated using the same mechanism that invalidates Perl's method resolution caching, so any changes to @ISA or a symbol table will clear the stale methods (under 5.10 this only clears the cached methods of affected classes, under 5.8 this clears all caches globaly).

EXPORTS

Top

specializing_method $name, $generator

Declare a method $name in the current class, whose bodies are created per subclass using $generator.

TODO

Top

Currently specializing the method on the superclass is suboptimal, since we must do some condition checking first. This can be done much more efficiently in XS.

VERSION CONTROL

Top

This module is maintained using Darcs. You can get the latest version from http://nothingmuch.woobling.org/code, and use darcs send to commit changes.

AUTHOR

Top

Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT

Top


Method-Specialize documentation  | view source Contained in the Method-Specialize distribution.