File Coverage

blib/lib/DBIx/Class/Componentised.pm
Criterion Covered Total %
statement 51 51 100.0
branch 15 16 93.7
condition 5 6 83.3
subroutine 9 9 100.0
pod 1 1 100.0
total 81 83 97.5


line stmt bran cond sub pod time code
1             package # hide from PAUSE
2             DBIx::Class::Componentised;
3              
4 313     313   2366 use strict;
  313         730  
  313         9124  
5 313     313   1690 use warnings;
  313         655  
  313         8317  
6              
7 313     313   1817 use base 'Class::C3::Componentised';
  313         682  
  313         104309  
8 313     313   967572 use mro 'c3';
  313         825  
  313         1505  
9              
10 313     313   9370 use DBIx::Class::_Util 'get_subname';
  313         736  
  313         16380  
11 313     313   2009 use DBIx::Class::Carp '^DBIx::Class|^Class::C3::Componentised';
  313         710  
  313         3064  
12 313     313   111151 use namespace::clean;
  313         4068248  
  313         2123  
13              
14             # this warns of subtle bugs introduced by UTF8Columns hacky handling of store_column
15             # if and only if it is placed before something overriding store_column
16             sub inject_base {
17 20969     20969 1 91321 my $class = shift;
18 20969         57192 my ($target, @complist) = @_;
19              
20             # we already did load the component
21 20969   66     280771 my $keep_checking = ! (
22             $target->isa ('DBIx::Class::UTF8Columns')
23             ||
24             $target->isa ('DBIx::Class::ForceUTF8')
25             );
26              
27 20969         38790 my @target_isa;
28              
29 20969   100     77911 while ($keep_checking && @complist) {
30              
31 313 100   313   102021 @target_isa = do { no strict 'refs'; @{"$target\::ISA"} }
  313         851  
  313         94806  
  25283         61929  
  20967         30737  
  20967         137397  
32             unless @target_isa;
33              
34 25283         51449 my $comp = pop @complist;
35              
36             # warn here on use of either component, as we have no access to ForceUTF8,
37             # the author does not respond, and the Catalyst wiki used to recommend it
38 25283         55134 for (qw/DBIx::Class::UTF8Columns DBIx::Class::ForceUTF8/) {
39 50561 100       393148 if ($comp->isa ($_) ) {
40 5         13 $keep_checking = 0; # no use to check from this point on
41             carp_once "Use of $_ is strongly discouraged. See documentation of DBIx::Class::UTF8Columns for more info\n"
42 5 100       36 unless $ENV{DBIC_UTF8COLUMNS_OK};
43 5         70 last;
44             }
45             }
46              
47             # something unset $keep_checking - we got a unicode mangler
48 25283 100       56816 if (! $keep_checking) {
49              
50 5         9 my $base_store_column = do { require DBIx::Class::Row; DBIx::Class::Row->can ('store_column') };
  5         28  
  5         32  
51              
52 5         10 my @broken;
53 5         10 for my $existing_comp (@target_isa) {
54 7 50       75 my $sc = $existing_comp->can ('store_column')
55             or next;
56              
57 7 100       27 if ($sc ne $base_store_column) {
58 2         8 my ($definer) = get_subname($sc);
59 2 100       9 push @broken, ($definer eq $existing_comp)
60             ? $existing_comp
61             : "$existing_comp (via $definer)"
62             ;
63             }
64             }
65              
66 5 100       21 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 25283         112280 unshift @target_isa, $comp;
73             }
74              
75 20969         94821 $class->next::method(@_);
76             }
77              
78             1;