... | ... |
@@ -20,18 +20,15 @@ __PACKAGE__->class_attr(_query_cache_keys => sub { [] }); |
20 | 20 |
__PACKAGE__->class_attr('query_cache_max', default => 50, |
21 | 21 |
inherit => 'scalar_copy'); |
22 | 22 |
|
23 |
-__PACKAGE__->dual_attr([qw/user password data_source/], inherit => 'scalar_copy'); |
|
24 |
-__PACKAGE__->dual_attr([qw/database host port/], inherit => 'scalar_copy'); |
|
25 |
-__PACKAGE__->dual_attr([qw/bind_filter fetch_filter/], inherit => 'scalar_copy'); |
|
23 |
+__PACKAGE__->attr([qw/user password data_source/]); |
|
24 |
+__PACKAGE__->attr([qw/database host port/]); |
|
25 |
+__PACKAGE__->attr([qw/bind_filter fetch_filter options/]); |
|
26 | 26 |
|
27 |
-__PACKAGE__->dual_attr([qw/options filters formats/], |
|
27 |
+__PACKAGE__->dual_attr([qw/ filters formats/], |
|
28 | 28 |
default => sub { {} }, inherit => 'hash_copy'); |
29 | 29 |
|
30 |
-__PACKAGE__->dual_attr('result_class', default => 'DBIx::Custom::Result', |
|
31 |
- inherit => 'scalar_copy'); |
|
32 |
- |
|
33 |
-__PACKAGE__->dual_attr('sql_tmpl', default => sub {DBIx::Custom::SQL::Template->new}, |
|
34 |
- inherit => sub {$_[0] ? $_[0]->clone : undef}); |
|
30 |
+__PACKAGE__->attr(result_class => 'DBIx::Custom::Result'); |
|
31 |
+__PACKAGE__->attr(sql_tmpl => sub { DBIx::Custom::SQL::Template->new }); |
|
35 | 32 |
|
36 | 33 |
sub add_filter { |
37 | 34 |
my $invocant = shift; |
... | ... |
@@ -48,62 +48,25 @@ test 'Sub class constructor'; |
48 | 48 |
use base 'DBIx::Custom'; |
49 | 49 |
|
50 | 50 |
__PACKAGE__ |
51 |
- ->user('a') |
|
52 |
- ->database('a') |
|
53 |
- ->password('b') |
|
54 |
- ->data_source('c') |
|
55 |
- ->options({d => 1, e => 2}) |
|
56 | 51 |
->filters({f => 3}) |
57 | 52 |
->formats({f => 3}) |
58 |
- ->bind_filter('f') |
|
59 |
- ->fetch_filter('g') |
|
60 |
- ->result_class('DBIx::Custom::Result') |
|
61 |
- ->sql_tmpl($SQL_TMPL->{0}) |
|
62 | 53 |
; |
63 | 54 |
} |
64 | 55 |
$dbi = DBIx::Custom::T1->new( |
65 |
- user => 'ao', |
|
66 |
- database => 'ao', |
|
67 |
- password => 'bo', |
|
68 |
- data_source => 'co', |
|
69 |
- options => {do => 10, eo => 20}, |
|
70 | 56 |
filters => { |
71 | 57 |
fo => 30, |
72 | 58 |
}, |
73 | 59 |
formats => { |
74 | 60 |
fo => 30, |
75 | 61 |
}, |
76 |
- bind_filter => 'fo', |
|
77 |
- fetch_filter => 'go', |
|
78 |
- result_class => 'ho', |
|
79 |
- sql_tmpl => $SQL_TMPL->{0}, |
|
80 | 62 |
); |
81 |
-is($dbi->user, 'ao', "$test : user"); |
|
82 |
-is($dbi->database, 'ao', "$test : database"); |
|
83 |
-is($dbi->password, 'bo', "$test : passowr"); |
|
84 |
-is($dbi->data_source, 'co', "$test : data_source"); |
|
85 |
-is_deeply($dbi->options, {do => 10, eo => 20}, "$test : options"); |
|
86 | 63 |
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); |
87 | 64 |
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats"); |
88 |
-is($dbi->bind_filter, 'fo', "$test : bind_filter"); |
|
89 |
-is($dbi->fetch_filter, 'go', "$test : fetch_filter"); |
|
90 |
-is($dbi->result_class, 'ho', "$test : result_class"); |
|
91 |
-is($dbi->sql_tmpl->tag_start, 0, "$test : sql_tmpl"); |
|
92 |
-isa_ok($dbi, 'DBIx::Custom::T1'); |
|
93 | 65 |
|
94 | 66 |
test 'Sub class constructor default'; |
95 | 67 |
$dbi = DBIx::Custom::T1->new; |
96 |
-is($dbi->user, 'a', "$test : user"); |
|
97 |
-is($dbi->database, 'a', "$test : database"); |
|
98 |
-is($dbi->password, 'b', "$test : password"); |
|
99 |
-is($dbi->data_source, 'c', "$test : data_source"); |
|
100 |
-is_deeply($dbi->options, {d => 1, e => 2}, "$test : options"); |
|
101 | 68 |
is_deeply($dbi->filters, {f => 3}, "$test : filters"); |
102 | 69 |
is_deeply($dbi->formats, {f => 3}, "$test : formats"); |
103 |
-is($dbi->bind_filter, 'f', "$test : bind_filter"); |
|
104 |
-is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
105 |
-is($dbi->result_class, 'DBIx::Custom::Result', "$test : result_class"); |
|
106 |
-is($dbi->sql_tmpl->tag_start, 0, "$test : sql_tmpl"); |
|
107 | 70 |
isa_ok($dbi, 'DBIx::Custom::T1'); |
108 | 71 |
|
109 | 72 |
|
... | ... |
@@ -113,17 +76,8 @@ test 'Sub sub class constructor default'; |
113 | 76 |
use base 'DBIx::Custom::T1'; |
114 | 77 |
} |
115 | 78 |
$dbi = DBIx::Custom::T1_2->new; |
116 |
-is($dbi->user, 'a', "$test : user"); |
|
117 |
-is($dbi->database, 'a', "$test : database"); |
|
118 |
-is($dbi->password, 'b', "$test : passowrd"); |
|
119 |
-is($dbi->data_source, 'c', "$test : data_source"); |
|
120 |
-is_deeply($dbi->options, {d => 1, e => 2}, "$test : options"); |
|
121 | 79 |
is_deeply(scalar $dbi->filters, {f => 3}, "$test : filters"); |
122 | 80 |
is_deeply(scalar $dbi->formats, {f => 3}, "$test : formats"); |
123 |
-is($dbi->bind_filter, 'f', "$test : bind_filter"); |
|
124 |
-is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
125 |
-is($dbi->result_class, 'DBIx::Custom::Result', "$test : result_class"); |
|
126 |
-is($dbi->sql_tmpl->tag_start, 0, "$test sql_tmpl"); |
|
127 | 81 |
isa_ok($dbi, 'DBIx::Custom::T1_2'); |
128 | 82 |
|
129 | 83 |
|
... | ... |
@@ -133,63 +87,27 @@ test 'Customized sub class constructor default'; |
133 | 87 |
use base 'DBIx::Custom::T1'; |
134 | 88 |
|
135 | 89 |
__PACKAGE__ |
136 |
- ->user('ao') |
|
137 |
- ->database('ao') |
|
138 |
- ->password('bo') |
|
139 |
- ->data_source('co') |
|
140 |
- ->options({do => 10, eo => 20}) |
|
141 | 90 |
->filters({fo => 30}) |
142 | 91 |
->formats({fo => 30}) |
143 |
- ->bind_filter('fo') |
|
144 |
- ->fetch_filter('go') |
|
145 |
- ->result_class('ho') |
|
146 |
- ->sql_tmpl($SQL_TMPL->{1}) |
|
147 | 92 |
; |
148 | 93 |
} |
149 | 94 |
$dbi = DBIx::Custom::T1_3->new; |
150 |
-is($dbi->user, 'ao', "$test : user"); |
|
151 |
-is($dbi->database, 'ao', "$test : database"); |
|
152 |
-is($dbi->password, 'bo', "$test : password"); |
|
153 |
-is($dbi->data_source, 'co', "$test : data_source"); |
|
154 |
-is_deeply($dbi->options, {do => 10, eo => 20}, "$test : options"); |
|
155 | 95 |
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); |
156 | 96 |
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats"); |
157 |
-is($dbi->bind_filter, 'fo', "$test : bind_filter"); |
|
158 |
-is($dbi->fetch_filter, 'go', "$test : fetch_filter"); |
|
159 |
-is($dbi->result_class, 'ho', "$test : result_class"); |
|
160 |
-is($dbi->sql_tmpl->tag_start, 1, "$test : sql_tmpl"); |
|
161 | 97 |
isa_ok($dbi, 'DBIx::Custom::T1_3'); |
162 | 98 |
|
163 | 99 |
|
164 | 100 |
test 'Customized sub class constructor'; |
165 | 101 |
$dbi = DBIx::Custom::T1_3->new( |
166 |
- user => 'a', |
|
167 |
- database => 'a', |
|
168 |
- password => 'b', |
|
169 |
- data_source => 'c', |
|
170 |
- options => {d => 1, e => 2}, |
|
171 | 102 |
filters => { |
172 | 103 |
f => 3, |
173 | 104 |
}, |
174 | 105 |
formats => { |
175 | 106 |
f => 3, |
176 | 107 |
}, |
177 |
- bind_filter => 'f', |
|
178 |
- fetch_filter => 'g', |
|
179 |
- result_class => 'h', |
|
180 |
- sql_tmpl => $SQL_TMPL->{2}, |
|
181 | 108 |
); |
182 |
-is($dbi->user, 'a', "$test : user"); |
|
183 |
-is($dbi->database, 'a', "$test : database"); |
|
184 |
-is($dbi->password, 'b', "$test : password"); |
|
185 |
-is($dbi->data_source, 'c', "$test : data_source"); |
|
186 |
-is_deeply($dbi->options, {d => 1, e => 2}, "$test : options"); |
|
187 | 109 |
is_deeply($dbi->filters, {f => 3}, "$test : filters"); |
188 | 110 |
is_deeply($dbi->formats, {f => 3}, "$test : formats"); |
189 |
-is($dbi->bind_filter, 'f', "$test : bind_filter"); |
|
190 |
-is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
191 |
-is($dbi->result_class, 'h', "$test : result_class"); |
|
192 |
-is($dbi->sql_tmpl->tag_start, 2, "$test : sql_tmpl"); |
|
193 | 111 |
isa_ok($dbi, 'DBIx::Custom'); |
194 | 112 |
|
195 | 113 |
|