Showing 3 changed files with 134 additions and 39 deletions
+1 -1
t/common-mysql.t
... ...
@@ -23,7 +23,7 @@ use DBIx::Custom;
23 23
     sub create_table2_2 { "create table table2 (key1 varchar(255), key2 varchar(255), key3 varchar(255)) engine=InnoDB" }
24 24
     sub create_table3 { "create table table3 (key1 varchar(255), key2 varchar(255), key3 varchar(255)) engine=InnoDB" }
25 25
     sub create_table_reserved {
26
-      'create table `table` (`select` varchar(255), `update` varchar(255)) engine=InnoDB;' }
26
+      'create table `table` (`select` varchar(255), `update` varchar(255)) engine=InnoDB' }
27 27
 }
28 28
 
29 29
 require "$FindBin::Bin/common.t";
+129 -34
t/common.t
... ...
@@ -1,12 +1,10 @@
1 1
 use Test::More;
2 2
 use strict;
3 3
 use warnings;
4
-use DBIx::Custom;
5 4
 use Encode qw/encode_utf8/;
6 5
 use FindBin;
7 6
 use lib "$FindBin::Bin/common";
8 7
 
9
-
10 8
 my $dbi;
11 9
 
12 10
 plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
... ...
@@ -15,6 +13,132 @@ plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped'
15 13
 
16 14
 plan 'no_plan';
17 15
 
16
+use MyDBI1;
17
+{
18
+    package MyDBI4;
19
+
20
+    use strict;
21
+    use warnings;
22
+
23
+    use base 'DBIx::Custom';
24
+
25
+    sub connect {
26
+        my $self = shift->SUPER::connect(@_);
27
+        
28
+        $self->include_model(
29
+            MyModel2 => [
30
+                'book',
31
+                {class => 'Company', name => 'company'}
32
+            ]
33
+        );
34
+    }
35
+
36
+    package MyModel2::Base1;
37
+
38
+    use strict;
39
+    use warnings;
40
+
41
+    use base 'DBIx::Custom::Model';
42
+
43
+    package MyModel2::book;
44
+
45
+    use strict;
46
+    use warnings;
47
+
48
+    use base 'MyModel2::Base1';
49
+
50
+    sub insert {
51
+        my ($self, $param) = @_;
52
+        
53
+        return $self->SUPER::insert(param => $param);
54
+    }
55
+
56
+    sub list { shift->select; }
57
+
58
+    package MyModel2::Company;
59
+
60
+    use strict;
61
+    use warnings;
62
+
63
+    use base 'MyModel2::Base1';
64
+
65
+    sub insert {
66
+        my ($self, $param) = @_;
67
+        
68
+        return $self->SUPER::insert(param => $param);
69
+    }
70
+
71
+    sub list { shift->select; }
72
+}
73
+{
74
+     package MyDBI5;
75
+
76
+    use strict;
77
+    use warnings;
78
+
79
+    use base 'DBIx::Custom';
80
+
81
+    sub connect {
82
+        my $self = shift->SUPER::connect(@_);
83
+        
84
+        $self->include_model('MyModel4');
85
+    }
86
+}
87
+{
88
+    package MyDBI6;
89
+    
90
+    use base 'DBIx::Custom';
91
+    
92
+    sub connect {
93
+        my $self = shift->SUPER::connect(@_);
94
+        
95
+        $self->include_model('MyModel5');
96
+        
97
+        return $self;
98
+    }
99
+}
100
+{
101
+    package MyDBI7;
102
+    
103
+    use base 'DBIx::Custom';
104
+    
105
+    sub connect {
106
+        my $self = shift->SUPER::connect(@_);
107
+        
108
+        $self->include_model('MyModel6');
109
+        
110
+        
111
+        return $self;
112
+    }
113
+}
114
+{
115
+    package MyDBI8;
116
+    
117
+    use base 'DBIx::Custom';
118
+    
119
+    sub connect {
120
+        my $self = shift->SUPER::connect(@_);
121
+        
122
+        $self->include_model('MyModel7');
123
+        
124
+        return $self;
125
+    }
126
+}
127
+
128
+{
129
+    package MyDBI9;
130
+    
131
+    use base 'DBIx::Custom';
132
+    
133
+    sub connect {
134
+        my $self = shift->SUPER::connect(@_);
135
+        
136
+        $self->include_model('MyModel8')->setup_model;
137
+        
138
+        return $self;
139
+    }
140
+}
141
+
18 142
 $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
19 143
 sub test { print "# $_[0]\n" }
20 144
 
... ...
@@ -1078,49 +1202,20 @@ $rows = $dbi->select(
1078 1202
 is_deeply($rows, [{key1 => 1, key2 => 2}]);
1079 1203
 
1080 1204
 test 'connect super';
1081
-{
1082
-    package MyDBI;
1083
-    
1084
-    use base 'DBIx::Custom';
1085
-    sub connect {
1086
-        my $self = shift->SUPER::connect(@_);
1087
-        
1088
-        return $self;
1089
-    }
1090
-    
1091
-    sub new {
1092
-        my $self = shift->SUPER::new(@_);
1093
-        
1094
-        return $self;
1095
-    }
1096
-}
1097
-
1098
-$dbi = MyDBI->connect;
1205
+$dbi = DBIx::Custom->connect;
1099 1206
 eval { $dbi->execute('drop table table1') };
1100 1207
 $dbi->execute($create_table1);
1101 1208
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1102 1209
 is($dbi->select(table => 'table1')->one->{key1}, 1);
1103 1210
 
1104
-$dbi = MyDBI->new;
1211
+$dbi = DBIx::Custom->new;
1105 1212
 $dbi->connect;
1106 1213
 eval { $dbi->execute('drop table table1') };
1107 1214
 $dbi->execute($create_table1);
1108 1215
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1109 1216
 is($dbi->select(table => 'table1')->one->{key1}, 1);
1110 1217
 
1111
-{
1112
-    package MyDBI2;
1113
-    
1114
-    use base 'DBIx::Custom';
1115
-    sub connect {
1116
-        my $self = shift->SUPER::new(@_);
1117
-        $self->connect;
1118
-        
1119
-        return $self;
1120
-    }
1121
-}
1122
-
1123
-$dbi = MyDBI->connect;
1218
+$dbi = DBIx::Custom->connect;
1124 1219
 eval { $dbi->execute('drop table table1') };
1125 1220
 $dbi->execute($create_table1);
1126 1221
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
+4 -4
t/sqlite.t
... ...
@@ -20,6 +20,10 @@ $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
20 20
 sub test { print "# $_[0]\n" }
21 21
 
22 22
 use DBIx::Custom;
23
+{
24
+    package DBIx::Custom;
25
+    has dsn => sub { 'dbi:SQLite:dbname=:memory:' }
26
+}
23 27
 use MyDBI1;
24 28
 {
25 29
     package MyDBI4;
... ...
@@ -77,10 +81,6 @@ use MyDBI1;
77 81
 
78 82
     sub list { shift->select; }
79 83
 }
80
-{
81
-    package DBIx::Custom;
82
-    has dsn => sub { 'dbi:SQLite:dbname=:memory:' }
83
-}
84 84
 {
85 85
      package MyDBI5;
86 86