Merge 'trunk' into 'DBIx-Class-C3'
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / Componentised.pm
CommitLineData
227d4dee 1package DBIx::Class::Componentised;
2
147dd158 3use Class::C3;
4
227d4dee 5sub inject_base {
6 my ($class, $target, @to_inject) = @_;
7 {
8 no strict 'refs';
9 unshift(@{"${target}::ISA"}, grep { $target ne $_ } @to_inject);
10 }
9a15732e 11 my $table = { Class::C3::_dump_MRO_table };
12 eval "package $target; use Class::C3;" unless exists $table->{$target};
13 Class::C3::reinitialize() if defined $table->{$target};
227d4dee 14}
15
16sub load_components {
17 my $class = shift;
18 my @comp = map { "DBIx::Class::$_" } grep { $_ !~ /^#/ } @_;
19 $class->_load_components(@comp);
20}
21
22sub load_own_components {
23 my $class = shift;
24 my @comp = map { "${class}::$_" } grep { $_ !~ /^#/ } @_;
25 $class->_load_components(@comp);
26}
27
28sub _load_components {
29 my ($class, @comp) = @_;
30 foreach my $comp (@comp) {
31 eval "use $comp";
32 die $@ if $@;
33 }
34 $class->inject_base($class => @comp);
35}
36
371;