View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
יובל קוג'מן (Yuval Kogman) > Method-Specialize > Method::Specialize



Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  


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).


specializing_method $name, $generator

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


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, and use darcs send to commit changes.


Yuval Kogman <>


        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.
syntax highlighting: