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   3304 use strict;
  380         1150  
  380         11477  
5 380     380   2102 use warnings;
  380         1128  
  380         10786  
6              
7 380     380   2071 use base 'Class::C3::Componentised';
  380         1044  
  380         187663  
8 380     380   1319326 use mro 'c3';
  380         1293  
  380         1800  
9              
10 380     380   13345 use DBIx::Class::Carp '^DBIx::Class|^Class::C3::Componentised';
  380         1226  
  380         5378  
11 380     380   187732 use namespace::clean;
  380         5949754  
  380         2639  
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 22384     22384 1 122303 my $class = shift;
17 22384         60275 my ($target, @complist) = @_;
18              
19             # we already did load the component
20 22384   66     325075 my $keep_checking = ! (
21             $target->isa ('DBIx::Class::UTF8Columns')
22             ||
23             $target->isa ('DBIx::Class::ForceUTF8')
24             );
25              
26 22384         41626 my @target_isa;
27              
28 22384   100     83119 while ($keep_checking && @complist) {
29              
30 380 100   380   116396 @target_isa = do { no strict 'refs'; @{"$target\::ISA"} }
  380         1245  
  380         131343  
  27636         66058  
  22382         31930  
  22382         156586  
31             unless @target_isa;
32              
33 27636         56291 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 27636         58014 for (qw/DBIx::Class::UTF8Columns DBIx::Class::ForceUTF8/) {
38 55267 100       472813 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       38 unless $ENV{DBIC_UTF8COLUMNS_OK};
42 5         71 last;
43             }
44             }
45              
46             # something unset $keep_checking - we got a unicode mangler
47 27636 100       57644 if (! $keep_checking) {
48              
49 5         12 my $base_store_column = do { require DBIx::Class::Row; DBIx::Class::Row->can ('store_column') };
  5         33  
  5         31  
50              
51 5         10 my @broken;
52 5         13 for my $existing_comp (@target_isa) {
53 7 50       79 my $sc = $existing_comp->can ('store_column')
54             or next;
55              
56 7 100       31 if ($sc ne $base_store_column) {
57 2         8 require B;
58 2         18 my $definer = B::svref_2object($sc)->STASH->NAME;
59 2 100       13 push @broken, ($definer eq $existing_comp)
60             ? $existing_comp
61             : "$existing_comp (via $definer)"
62             ;
63             }
64             }
65              
66 5 100       25 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 27636         120041 unshift @target_isa, $comp;
73             }
74              
75 22384         98041 $class->next::method(@_);
76             }
77              
78             1;