You can get the tarball here
There are some similar modules on CPAN (Class::Delegation, NEXT, both by TheDamian), but mine works still does something different... What I'm especially interested in is:
The standard Perl behaviour is to call only the lefternmost instance it can fing doing a depth first traversial.
Imagine the following class structure:
C
/
A B C::C
\ / \ /
A::A D
\ /
My::Class
Perl will try to find a method in this mess in this order:
My::Class -> A::A -> A -> B -> D -> B -> C::C -> C
(Note that it will look twice in B because B is a parent of both A::A and D))
As soon as Perl finds the method somewhere, it will short-circuit out of it's search and invoke the method.
And that is exactly the behaviour Class::DispatchToAll changes.
If you use dispatch_to_all (provided by Class::DispatchToAll) to call your method, Perl will look in all of the aforementioned packages and run all the methods it can find. It will even collect all the return values and return them to you as an array, if you want it too.
Merging a hash (using the Class Hierarchy shown above)
A::hash={foo=>'foo'};
C::hash={bar=>'bar'};
A::A::hash={foo=>'FOO'};
My::Class::hash={even=>'more'};
# assuming a method get_hash not implemented in this example
my @v=$self->dispatch_to_all('get_hash');
my %hash=();
foreach (reverse @v) {
%hash=(%hash,%$_);
}
# %hash now looks like:
# {
# foo=>'FOO', # from A::A, overriding A
# bar=>'bar', # from C
# even=>'more', # from My::Class
# }
Please note the reverse. This enables the overriding of values "further away" from the calling class by values that are "nearer"
Please see the docs in the tarball (and the examples in test.pl) for further info or /msg me
-- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
In reply to RFC: Class::DispatchToAll by domm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |