Method::Specialize - Generate per-subclass variants for your methods.
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
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).
@ISA
Declare a method $name in the current class, whose bodies are created per subclass using $generator.
$name
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.
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.
darcs send
Yuval Kogman <nothingmuch@woobling.org>
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.
To install Method::Specialize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Method::Specialize
CPAN shell
perl -MCPAN -e shell install Method::Specialize
For more information on module installation, please visit the detailed CPAN module installation guide.