Revert C3-fication d009cb7d and fixups 7f068248 and 983f766d
[dbsrgits/DBIx-Class.git] / xt / extra / c3_mro.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
e8b77df6 3use warnings;
e4c24739 4use strict;
e8b77df6 5
6use Test::More;
d009cb7d 7use DBICTest;
5e0eea35 8use DBIx::Class::Optional::Dependencies;
7648acb5 9use DBIx::Class::_Util 'uniq';
d009cb7d 10
11my @global_ISA_tail = qw(
12 DBIx::Class
13 DBIx::Class::Componentised
14 Class::C3::Componentised
15 DBIx::Class::AccessorGroup
5f48fa56 16 DBIx::Class::MethodAttributes
d009cb7d 17 Class::Accessor::Grouped
18);
e4c24739 19
20{
e8b77df6 21 package AAA;
e4c24739 22
e8b77df6 23 use base "DBIx::Class::Core";
7648acb5 24 use mro 'c3';
e8b77df6 25}
e4c24739 26
e8b77df6 27{
28 package BBB;
e4c24739 29
e8b77df6 30 use base 'AAA';
e4c24739 31
e8b77df6 32 #Injecting a direct parent.
33 __PACKAGE__->inject_base( __PACKAGE__, 'AAA' );
34}
e4c24739 35
e8b77df6 36{
37 package CCC;
e4c24739 38
e8b77df6 39 use base 'AAA';
e4c24739 40
e8b77df6 41 #Injecting an indirect parent.
42 __PACKAGE__->inject_base( __PACKAGE__, 'DBIx::Class::Core' );
e4c24739 43}
44
4f507947 45eval { mro::get_linear_isa('BBB'); };
e4c24739 46ok (! $@, "Correctly skipped injecting a direct parent of class BBB");
47
4f507947 48eval { mro::get_linear_isa('CCC'); };
e4c24739 49ok (! $@, "Correctly skipped injecting an indirect parent of class BBB");
e8b77df6 50
d009cb7d 51
52my $art = DBICTest->init_schema->resultset("Artist")->next;
53
7648acb5 54check_ancestry($_) for uniq map
55 { length ref $_ ? ref $_ : $_ }
56 (
57 $art,
58 $art->result_source,
59 $art->result_source->resultset,
60 ( map
61 { $_, $_->result_class, $_->resultset_class }
62 map
63 { $art->result_source->schema->source($_) }
64 $art->result_source->schema->sources
65 ),
66 qw( AAA BBB CCC ),
67 ((! DBIx::Class::Optional::Dependencies->req_ok_for('cdbicompat') ) ? () : do {
68 unshift @INC, 't/cdbi/testlib';
69 map { eval "require $_" or die $@; $_ } qw(
70 Film Lazy Actor ActorAlias ImplicitInflate
71 );
72 }),
73 )
74;
d009cb7d 75
e8b77df6 76use DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server;
e8b77df6 77
78is_deeply (
79 mro::get_linear_isa('DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server'),
80 [qw/
81 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server
82 DBIx::Class::Storage::DBI::Sybase
83 DBIx::Class::Storage::DBI::MSSQL
84 DBIx::Class::Storage::DBI::UniqueIdentifier
fabbd5cc 85 DBIx::Class::Storage::DBI::IdentityInsert
e8b77df6 86 DBIx::Class::Storage::DBI
87 DBIx::Class::Storage::DBIHacks
88 DBIx::Class::Storage
d009cb7d 89 /, @global_ISA_tail],
e8b77df6 90 'Correctly ordered ISA of DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server'
91);
92
87bf71d5 93my $storage = DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server->new;
c1e5a9ac 94$storage->connect_info(['dbi:SQLite::memory:']); # determine_driver's init() connects for this subclass
87bf71d5 95$storage->_determine_driver;
e8b77df6 96is (
87bf71d5 97 $storage->can('sql_limit_dialect'),
98 'DBIx::Class::Storage::DBI::MSSQL'->can('sql_limit_dialect'),
e8b77df6 99 'Correct method picked'
100);
101
750a4ad2 102if ( "$]" >= 5.010 ) {
87bf71d5 103 ok (! $INC{'Class/C3.pm'}, 'No Class::C3 loaded on perl 5.10+');
104
105 # Class::C3::Componentised loads MRO::Compat unconditionally to satisfy
106 # the assumption that once Class::C3::X is loaded, so is Class::C3
107 #ok (! $INC{'MRO/Compat.pm'}, 'No MRO::Compat loaded on perl 5.10+');
108}
109
d009cb7d 110sub check_ancestry {
111 my $class = shift;
112
113 die "Expecting classname" if length ref $class;
114
115 my @linear_ISA = @{ mro::get_linear_isa($class) };
116
117 # something is *VERY* wrong, the splice below won't make it
118 unless (@linear_ISA > @global_ISA_tail) {
119 fail(
120 "Unexpectedly shallow \@ISA for class '$class': "
121 . join ', ', map { "'$_'" } @linear_ISA
122 );
123 return;
124 }
125
126 is_deeply (
127 [ splice @linear_ISA, ($#linear_ISA - $#global_ISA_tail) ],
128 \@global_ISA_tail,
129 "Correct end of \@ISA for '$class'"
130 );
131
7648acb5 132 is(
133 mro::get_mro($class),
134 'c3',
135 "Expected mro on class '$class' automatically set",
136 );
d009cb7d 137}
138
e8b77df6 139done_testing;