Showing 1 changed files with 126 additions and 123 deletions
+126 -123
t/sqlite.t
... ...
@@ -19,10 +19,136 @@ BEGIN {
19 19
 $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
20 20
 sub test { print "# $_[0]\n" }
21 21
 
22
+use DBIx::Custom;
23
+use MyDBI1;
24
+{
25
+    package MyDBI4;
26
+
27
+    use strict;
28
+    use warnings;
29
+
30
+    use base 'DBIx::Custom';
31
+
32
+    sub connect {
33
+        my $self = shift->SUPER::connect(@_);
34
+        
35
+        $self->include_model(
36
+            MyModel2 => [
37
+                'book',
38
+                {class => 'Company', name => 'company'}
39
+            ]
40
+        );
41
+    }
42
+
43
+    package MyModel2::Base1;
44
+
45
+    use strict;
46
+    use warnings;
47
+
48
+    use base 'DBIx::Custom::Model';
49
+
50
+    package MyModel2::book;
51
+
52
+    use strict;
53
+    use warnings;
54
+
55
+    use base 'MyModel2::Base1';
56
+
57
+    sub insert {
58
+        my ($self, $param) = @_;
59
+        
60
+        return $self->SUPER::insert(param => $param);
61
+    }
62
+
63
+    sub list { shift->select; }
64
+
65
+    package MyModel2::Company;
66
+
67
+    use strict;
68
+    use warnings;
69
+
70
+    use base 'MyModel2::Base1';
71
+
72
+    sub insert {
73
+        my ($self, $param) = @_;
74
+        
75
+        return $self->SUPER::insert(param => $param);
76
+    }
77
+
78
+    sub list { shift->select; }
79
+}
22 80
 {
23 81
     package DBIx::Custom;
24 82
     has dsn => sub { 'dbi:SQLite:dbname=:memory:' }
25 83
 }
84
+{
85
+     package MyDBI5;
86
+
87
+    use strict;
88
+    use warnings;
89
+
90
+    use base 'DBIx::Custom';
91
+
92
+    sub connect {
93
+        my $self = shift->SUPER::connect(@_);
94
+        
95
+        $self->include_model('MyModel4');
96
+    }
97
+}
98
+{
99
+    package MyDBI6;
100
+    
101
+    use base 'DBIx::Custom';
102
+    
103
+    sub connect {
104
+        my $self = shift->SUPER::connect(@_);
105
+        
106
+        $self->include_model('MyModel5');
107
+        
108
+        return $self;
109
+    }
110
+}
111
+{
112
+    package MyDBI7;
113
+    
114
+    use base 'DBIx::Custom';
115
+    
116
+    sub connect {
117
+        my $self = shift->SUPER::connect(@_);
118
+        
119
+        $self->include_model('MyModel6');
120
+        
121
+        
122
+        return $self;
123
+    }
124
+}
125
+{
126
+    package MyDBI8;
127
+    
128
+    use base 'DBIx::Custom';
129
+    
130
+    sub connect {
131
+        my $self = shift->SUPER::connect(@_);
132
+        
133
+        $self->include_model('MyModel7');
134
+        
135
+        return $self;
136
+    }
137
+}
138
+
139
+{
140
+    package MyDBI9;
141
+    
142
+    use base 'DBIx::Custom';
143
+    
144
+    sub connect {
145
+        my $self = shift->SUPER::connect(@_);
146
+        
147
+        $self->include_model('MyModel8')->setup_model;
148
+        
149
+        return $self;
150
+    }
151
+}
26 152
 
27 153
 # Constant
28 154
 my $create_table1 = 'create table table1 (key1 char(255), key2 char(255));';
... ...
@@ -265,19 +391,6 @@ $model = $dbi->model('book');
265 391
 
266 392
 
267 393
 test 'model delete_at';
268
-{
269
-    package MyDBI6;
270
-    
271
-    use base 'DBIx::Custom';
272
-    
273
-    sub connect {
274
-        my $self = shift->SUPER::connect(@_);
275
-        
276
-        $self->include_model('MyModel5');
277
-        
278
-        return $self;
279
-    }
280
-}
281 394
 $dbi = MyDBI6->connect;
282 395
 eval { $dbi->execute('drop table table1') };
283 396
 eval { $dbi->execute('drop table table2') };
... ...
@@ -337,20 +450,6 @@ is($row->{key3}, 3);
337 450
 
338 451
 
339 452
 test 'mycolumn and column';
340
-{
341
-    package MyDBI7;
342
-    
343
-    use base 'DBIx::Custom';
344
-    
345
-    sub connect {
346
-        my $self = shift->SUPER::connect(@_);
347
-        
348
-        $self->include_model('MyModel6');
349
-        
350
-        
351
-        return $self;
352
-    }
353
-}
354 453
 $dbi = MyDBI7->connect;
355 454
 eval { $dbi->execute('drop table table1') };
356 455
 eval { $dbi->execute('drop table table2') };
... ...
@@ -560,19 +659,6 @@ $rows = $dbi->select(
560 659
 is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
561 660
           'quote');
562 661
 
563
-{
564
-    package MyDBI8;
565
-    
566
-    use base 'DBIx::Custom';
567
-    
568
-    sub connect {
569
-        my $self = shift->SUPER::connect(@_);
570
-        
571
-        $self->include_model('MyModel7');
572
-        
573
-        return $self;
574
-    }
575
-}
576 662
 
577 663
 $dbi = DBIx::Custom->connect;
578 664
 eval { $dbi->execute('drop table table1') };
... ...
@@ -702,19 +788,6 @@ is_deeply($result->one,
702 788
           {key1 => 1, 'table2.key1' => 1});
703 789
 
704 790
 test 'dbi method from model';
705
-{
706
-    package MyDBI9;
707
-    
708
-    use base 'DBIx::Custom';
709
-    
710
-    sub connect {
711
-        my $self = shift->SUPER::connect(@_);
712
-        
713
-        $self->include_model('MyModel8')->setup_model;
714
-        
715
-        return $self;
716
-    }
717
-}
718 791
 $dbi = MyDBI9->connect;
719 792
 eval { $dbi->execute('drop table table1') };
720 793
 $dbi->execute($create_table1);
... ...
@@ -2281,62 +2354,6 @@ is_deeply($model->list->all, [{name => 'a'}], 'basic');
2281 2354
 is($dbi->models->{'book'}, $dbi->model('book'));
2282 2355
 is($dbi->models->{'company'}, $dbi->model('company'));
2283 2356
 
2284
-{
2285
-    package MyDBI4;
2286
-
2287
-    use strict;
2288
-    use warnings;
2289
-
2290
-    use base 'DBIx::Custom';
2291
-
2292
-    sub connect {
2293
-        my $self = shift->SUPER::connect(@_);
2294
-        
2295
-        $self->include_model(
2296
-            MyModel2 => [
2297
-                'book',
2298
-                {class => 'Company', name => 'company'}
2299
-            ]
2300
-        );
2301
-    }
2302
-
2303
-    package MyModel2::Base1;
2304
-
2305
-    use strict;
2306
-    use warnings;
2307
-
2308
-    use base 'DBIx::Custom::Model';
2309
-
2310
-    package MyModel2::book;
2311
-
2312
-    use strict;
2313
-    use warnings;
2314
-
2315
-    use base 'MyModel2::Base1';
2316
-
2317
-    sub insert {
2318
-        my ($self, $param) = @_;
2319
-        
2320
-        return $self->SUPER::insert(param => $param);
2321
-    }
2322
-
2323
-    sub list { shift->select; }
2324
-
2325
-    package MyModel2::Company;
2326
-
2327
-    use strict;
2328
-    use warnings;
2329
-
2330
-    use base 'MyModel2::Base1';
2331
-
2332
-    sub insert {
2333
-        my ($self, $param) = @_;
2334
-        
2335
-        return $self->SUPER::insert(param => $param);
2336
-    }
2337
-
2338
-    sub list { shift->select; }
2339
-}
2340 2357
 $dbi = MyDBI4->connect;
2341 2358
 eval { $dbi->execute('drop table book') };
2342 2359
 $dbi->execute("create table book (title, author)");
... ...
@@ -2348,20 +2365,6 @@ $model = $dbi->model('company');
2348 2365
 $model->insert({name => 'a'});
2349 2366
 is_deeply($model->list->all, [{name => 'a'}], 'basic');
2350 2367
 
2351
-{
2352
-     package MyDBI5;
2353
-
2354
-    use strict;
2355
-    use warnings;
2356
-
2357
-    use base 'DBIx::Custom';
2358
-
2359
-    sub connect {
2360
-        my $self = shift->SUPER::connect(@_);
2361
-        
2362
-        $self->include_model('MyModel4');
2363
-    }
2364
-}
2365 2368
 $dbi = MyDBI5->connect;
2366 2369
 eval { $dbi->execute('drop table company') };
2367 2370
 eval { $dbi->execute('drop table table1') };