Commit | Line | Data |
c0e7b4e5 |
1 | package # hide from PAUSE |
2 | DBIx::Class::Componentised; |
227d4dee |
3 | |
147dd158 |
4 | use Class::C3; |
5 | |
227d4dee |
6 | sub inject_base { |
7 | my ($class, $target, @to_inject) = @_; |
8 | { |
9 | no strict 'refs'; |
e4c24739 |
10 | unshift(@{"${target}::ISA"}, grep { $target ne $_ && !$target->isa($_)} @to_inject); |
227d4dee |
11 | } |
20518cb4 |
12 | |
13 | # Yes, this is hack. But it *does* work. Please don't submit tickets about |
14 | # it on the basis of the comments in Class::C3, the author was on #dbix-class |
15 | # while I was implementing this. |
16 | |
9a15732e |
17 | my $table = { Class::C3::_dump_MRO_table }; |
75a23b3e |
18 | eval "package $target; import Class::C3;" unless exists $table->{$target}; |
227d4dee |
19 | } |
20 | |
21 | sub load_components { |
22 | my $class = shift; |
7411204b |
23 | my $base = $class->component_base_class; |
6db94aca |
24 | my @comp = map { /^\+(.*)$/ ? $1 : "${base}::$_" } grep { $_ !~ /^#/ } @_; |
227d4dee |
25 | $class->_load_components(@comp); |
971c0085 |
26 | Class::C3::reinitialize(); |
227d4dee |
27 | } |
28 | |
29 | sub load_own_components { |
30 | my $class = shift; |
31 | my @comp = map { "${class}::$_" } grep { $_ !~ /^#/ } @_; |
32 | $class->_load_components(@comp); |
33 | } |
34 | |
35 | sub _load_components { |
36 | my ($class, @comp) = @_; |
37 | foreach my $comp (@comp) { |
38 | eval "use $comp"; |
39 | die $@ if $@; |
40 | } |
41 | $class->inject_base($class => @comp); |
42 | } |
43 | |
44 | 1; |