1 package Class::C3::Componentised;
13 my ($class, $target, @to_inject) = @_;
17 unshift( @{"${target}::ISA"},
18 grep { !$seen{ $_ }++ && $target ne $_ && !$target->isa($_) }
23 # Yes, this is hack. But it *does* work. Please don't submit tickets about
24 # it on the basis of the comments in Class::C3, the author was on #dbix-class
25 # while I was implementing this.
27 my $table = { Class::C3::_dump_MRO_table };
28 eval "package $target; import Class::C3;" unless exists $table->{$target};
33 my $base = $class->component_base_class;
34 my @comp = map { /^\+(.*)$/ ? $1 : "${base}::$_" } grep { $_ !~ /^#/ } @_;
35 $class->_load_components(@comp);
36 Class::C3::reinitialize();
39 sub load_own_components {
41 my @comp = map { "${class}::$_" } grep { $_ !~ /^#/ } @_;
42 $class->_load_components(@comp);
45 sub _load_components {
46 my ($class, @comp) = @_;
47 foreach my $comp (@comp) {
51 $class->inject_base($class => @comp);
60 Class::C3::Componentised - extend and mix classes at runtime
66 use base "Class::C3::Componentised";
68 sub component_base_class { "MyApp" };
73 MyApp->load_components(qw/Foo Bar Baz/);
79 =head2 load_components
81 =head2 load_own_components
85 Matt S. Trout <mst@shadowcatsystems.co.uk>
89 You may distribute this code under the same terms as Perl itself.