Fix UTF8Column out of order loading warning
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Componentised.pm
1 package # hide from PAUSE
2     DBIx::Class::Componentised;
3
4 use strict;
5 use warnings;
6
7 use base 'Class::C3::Componentised';
8 use Carp::Clan qw/^DBIx::Class|^Class::C3::Componentised/;
9 use mro 'c3';
10
11 # this warns of subtle bugs introduced by UTF8Columns hacky handling of store_column
12 sub inject_base {
13   my $class = shift;
14   my $target = shift;
15
16   my @present_components = (@{mro::get_linear_isa ($target)||[]});
17   shift @present_components;    # don't need to interrogate myself
18
19   no strict 'refs';
20   for my $comp (reverse @_) {
21
22     # if we are trying add a UTF8Columns component *for the first time*
23     if ($comp->isa ('DBIx::Class::UTF8Columns') && ! $target->isa ('DBIx::Class::UTF8Columns') ) {
24       require B;
25       my @broken;
26
27       for (@present_components) {
28         last if $_ eq 'DBIx::Class::Row'; # don't care about anything further down the chain
29
30         my $cref = $_->can ('store_column')
31          or next;
32
33         push @broken, $_ if B::svref_2object($cref)->STASH->NAME eq $_;
34       }
35
36       carp "Incorrect loading order of $comp by ${target} will affect other components overriding store_column ("
37           . join (', ', @broken)
38           .'). Refer to the documentation of DBIx::Class::UTF8Columns for more info'
39        if @broken;
40     }
41
42     unshift @present_components, $comp;
43   }
44
45   $class->next::method($target, @_);
46 }
47
48 1;