File Coverage

blib/lib/DBIx/Class/Componentised.pm
Criterion Covered Total %
statement 49 49 100.0
branch 15 16 93.7
condition 5 6 83.3
subroutine 8 8 100.0
pod 1 1 100.0
total 78 80 97.5


line stmt bran cond sub pod time code
1             package # hide from PAUSE
2             DBIx::Class::Componentised;
3              
4 380     380   2186 use strict;
  380         706  
  380         11274  
5 380     380   1613 use warnings;
  380         669  
  380         10825  
6              
7 380     380   1608 use base 'Class::C3::Componentised';
  380         662  
  380         214040  
8 380     380   1260671 use mro 'c3';
  380         788  
  380         1684  
9              
10 380     380   14446 use DBIx::Class::Carp '^DBIx::Class|^Class::C3::Componentised';
  380         758  
  380         3935  
11 380     380   201736 use namespace::clean;
  380         5879855  
  380         2437  
12              
13             # this warns of subtle bugs introduced by UTF8Columns hacky handling of store_column
14             # if and only if it is placed before something overriding store_column
15             sub inject_base {
16 22016     22016 1 91596 my $class = shift;
17 22016         39440 my ($target, @complist) = @_;
18              
19             # we already did load the component
20 22016   66     304882 my $keep_checking = ! (
21             $target->isa ('DBIx::Class::UTF8Columns')
22             ||
23             $target->isa ('DBIx::Class::ForceUTF8')
24             );
25              
26 22016         20695 my @target_isa;
27              
28 22016   100     79447 while ($keep_checking && @complist) {
29              
30 380 100   380   124074 @target_isa = do { no strict 'refs'; @{"$target\::ISA"} }
  380         862  
  380         127893  
  27268         49113  
  22014         17260  
  22014         124930  
31             unless @target_isa;
32              
33 27268         32577 my $comp = pop @complist;
34              
35             # warn here on use of either component, as we have no access to ForceUTF8,
36             # the author does not respond, and the Catalyst wiki used to recommend it
37 27268         37005 for (qw/DBIx::Class::UTF8Columns DBIx::Class::ForceUTF8/) {
38 54531 100       406951 if ($comp->isa ($_) ) {
39 5         9 $keep_checking = 0; # no use to check from this point on
40             carp_once "Use of $_ is strongly discouraged. See documentation of DBIx::Class::UTF8Columns for more info\n"
41 5 100       34 unless $ENV{DBIC_UTF8COLUMNS_OK};
42 5         44 last;
43             }
44             }
45              
46             # something unset $keep_checking - we got a unicode mangler
47 27268 100       42757 if (! $keep_checking) {
48              
49 5         8 my $base_store_column = do { require DBIx::Class::Row; DBIx::Class::Row->can ('store_column') };
  5         27  
  5         29  
50              
51 5         8 my @broken;
52 5         10 for my $existing_comp (@target_isa) {
53 7 50       81 my $sc = $existing_comp->can ('store_column')
54             or next;
55              
56 7 100       23 if ($sc ne $base_store_column) {
57 2         6 require B;
58 2         21 my $definer = B::svref_2object($sc)->STASH->NAME;
59 2 100       10 push @broken, ($definer eq $existing_comp)
60             ? $existing_comp
61             : "$existing_comp (via $definer)"
62             ;
63             }
64             }
65              
66 5 100       23 carp "Incorrect loading order of $comp by $target will affect other components overriding 'store_column' ("
67             . join (', ', @broken)
68             .'). Refer to the documentation of DBIx::Class::UTF8Columns for more info'
69             if @broken;
70             }
71              
72 27268         116076 unshift @target_isa, $comp;
73             }
74              
75 22016         75561 $class->next::method(@_);
76             }
77              
78             1;