Take me over?
NAME
Method::Specialize - Generate per-subclass variants for your methods.
SYNOPSIS
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
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
- specializing_method $name, $generator
-
Declare a method
$name
in the current class, whose bodies are created per subclass using $generator.
TODO
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
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
Yuval Kogman <nothingmuch@woobling.org>
COPYRIGHT
Copyright (c) 2008 Yuval Kogman. All rights reserved
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.