| Class-Dynamic documentation | Contained in the Class-Dynamic distribution. |
Class::Dynamic - Rudimentary support for coderefs in @ISA
package Blargh;
use Class::Dynamic;
our @ISA = ("Foo", sub { rand < 0.5 ? "Bar" : "Baz" } );
This module allows you to insert coderefs into a class's @ISA.
The coderef is called with the object and method name as parameters, so that it can determine which class is appropriate. The coderef should return a string representing the class to delegate the method to.
Suggested uses: mixins, random dispatch, creating classes at runtime...
Almost certainly. This is almost throw-away code, although it does do something vaguely useful, so I'm not really inclined to answer bug reports without patches.
GPL & AL.
Simon Cozens, simon@cpan.org
| Class-Dynamic documentation | Contained in the Class-Dynamic distribution. |
package Class::Dynamic; use 5.006; our $VERSION = '1.01'; sub UNIVERSAL::AUTOLOAD { no strict; my $obj = $_[0]; my $class = ref $obj || $obj; my @foo = @{$class."::ISA"}; $UNIVERSAL::AUTOLOAD =~ /(.*)::(.*)/; my $package = $1; my $method = $2; my $sr; while (@foo) { last if ($sr = shift @foo) eq "CODE"; } return unless ref $sr; my $rv = $sr->($obj, $method); $UNIVERSAL::AUTOLOAD =~ s/.*::/${rv}::/; if (! defined &$UNIVERSAL::AUTOLOAD) { require Carp; import Carp; return if $method eq "DESTROY"; croak( qq{Can't locate object method "$method" via package "$rv" (perhaps you forgot to load "$rv"?)}); } else { goto &$UNIVERSAL::AUTOLOAD; } } # Preloaded methods go here. 1; __END__ # Below is stub documentation for your module. You better edit it!