| ... | ... |
@@ -6,40 +6,47 @@ use DBI::Custom; |
| 6 | 6 |
use Scalar::Util qw/blessed/; |
| 7 | 7 |
use DBI::Custom::SQL::Template; |
| 8 | 8 |
|
| 9 |
+# Function for test name |
|
| 10 |
+my $test; |
|
| 11 |
+sub test {
|
|
| 12 |
+ $test = shift; |
|
| 13 |
+} |
|
| 14 |
+ |
|
| 15 |
+# Varialbes for test |
|
| 16 |
+my $dbi; |
|
| 17 |
+my $sql_tmpl; |
|
| 18 |
+ |
|
| 9 | 19 |
my $sql_tmpl1 = DBI::Custom::SQL::Template->new->tag_start(0); |
| 10 | 20 |
my $sql_tmpl2 = DBI::Custom::SQL::Template->new->tag_start(1); |
| 11 | 21 |
my $sql_tmpl3 = DBI::Custom::SQL::Template->new->tag_start(2); |
| 12 | 22 |
|
| 13 |
-{
|
|
| 14 |
- my $dbi = DBI::Custom->new( |
|
| 15 |
- user => 'a', |
|
| 16 |
- password => 'b', |
|
| 17 |
- data_source => 'c', |
|
| 18 |
- dbi_options => {d => 1, e => 2},
|
|
| 19 |
- filters => {
|
|
| 20 |
- f => 3, |
|
| 21 |
- }, |
|
| 22 |
- bind_filter => 'f', |
|
| 23 |
- fetch_filter => 'g', |
|
| 24 |
- result_class => 'g', |
|
| 25 |
- sql_template => $sql_tmpl1, |
|
| 26 |
- ); |
|
| 27 |
- is_deeply($dbi,{user => 'a', password => 'b', data_source => 'c',
|
|
| 28 |
- dbi_options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f',
|
|
| 29 |
- fetch_filter => 'g', result_class => 'g', |
|
| 30 |
- sql_template => $sql_tmpl1}, 'new'); |
|
| 31 |
- |
|
| 32 |
- isa_ok($dbi, 'DBI::Custom'); |
|
| 33 |
-} |
|
| 23 |
+test 'constructor'; |
|
| 24 |
+$dbi = DBI::Custom->new( |
|
| 25 |
+ user => 'a', |
|
| 26 |
+ password => 'b', |
|
| 27 |
+ data_source => 'c', |
|
| 28 |
+ dbi_options => {d => 1, e => 2},
|
|
| 29 |
+ filters => {
|
|
| 30 |
+ f => 3, |
|
| 31 |
+ }, |
|
| 32 |
+ bind_filter => 'f', |
|
| 33 |
+ fetch_filter => 'g', |
|
| 34 |
+ result_class => 'g', |
|
| 35 |
+ sql_template => $sql_tmpl1, |
|
| 36 |
+); |
|
| 37 |
+is_deeply($dbi,{user => 'a', password => 'b', data_source => 'c',
|
|
| 38 |
+ dbi_options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f',
|
|
| 39 |
+ fetch_filter => 'g', result_class => 'g', |
|
| 40 |
+ sql_template => $sql_tmpl1}, $test); |
|
| 41 |
+isa_ok($dbi, 'DBI::Custom'); |
|
| 34 | 42 |
|
| 35 | 43 |
|
| 44 |
+test 'Sub class constructor'; |
|
| 36 | 45 |
{
|
| 37 | 46 |
package DBI::Custom::T1; |
| 38 | 47 |
use base 'DBI::Custom'; |
| 39 | 48 |
|
| 40 |
- my $class = __PACKAGE__; |
|
| 41 |
- |
|
| 42 |
- $class |
|
| 49 |
+ __PACKAGE__ |
|
| 43 | 50 |
->user('a')
|
| 44 | 51 |
->password('b')
|
| 45 | 52 |
->data_source('c')
|
| ... | ... |
@@ -53,73 +60,68 @@ my $sql_tmpl3 = DBI::Custom::SQL::Template->new->tag_start(2); |
| 53 | 60 |
->sql_template($sql_tmpl1) |
| 54 | 61 |
; |
| 55 | 62 |
} |
| 56 |
-{
|
|
| 57 |
- my $dbi = DBI::Custom::T1->new( |
|
| 58 |
- user => 'ao', |
|
| 59 |
- password => 'bo', |
|
| 60 |
- data_source => 'co', |
|
| 61 |
- dbi_options => {do => 10, eo => 20},
|
|
| 62 |
- filters => {
|
|
| 63 |
- fo => 30, |
|
| 64 |
- }, |
|
| 65 |
- bind_filter => 'fo', |
|
| 66 |
- fetch_filter => 'go', |
|
| 67 |
- result_class => 'ho', |
|
| 68 |
- sql_template => $sql_tmpl1, |
|
| 69 |
- ); |
|
| 70 |
- my $sql_tmpl = delete $dbi->{sql_template};
|
|
| 71 |
- is($sql_tmpl->tag_start, 0); |
|
| 72 |
- is_deeply($dbi,{ user => 'ao', password => 'bo', data_source => 'co', dbi_options => {do => 10, eo => 20},
|
|
| 73 |
- ,filters => {fo => 30}, bind_filter => 'fo', fetch_filter => 'go', result_class => 'ho',
|
|
| 74 |
- }, 'new arguments'); |
|
| 75 |
- |
|
| 76 |
- isa_ok($dbi, 'DBI::Custom::T1'); |
|
| 77 |
-} |
|
| 63 |
+$dbi = DBI::Custom::T1->new( |
|
| 64 |
+ user => 'ao', |
|
| 65 |
+ password => 'bo', |
|
| 66 |
+ data_source => 'co', |
|
| 67 |
+ dbi_options => {do => 10, eo => 20},
|
|
| 68 |
+ filters => {
|
|
| 69 |
+ fo => 30, |
|
| 70 |
+ }, |
|
| 71 |
+ bind_filter => 'fo', |
|
| 72 |
+ fetch_filter => 'go', |
|
| 73 |
+ result_class => 'ho', |
|
| 74 |
+ sql_template => $sql_tmpl1, |
|
| 75 |
+); |
|
| 76 |
+is($dbi->user, 'ao', "$test : user"); |
|
| 77 |
+is($dbi->password, 'bo', "$test : passowr"); |
|
| 78 |
+is($dbi->data_source, 'co', "$test : data_source"); |
|
| 79 |
+is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options");
|
|
| 80 |
+is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
|
|
| 81 |
+is($dbi->bind_filter, 'fo', "$test : bind_filter"); |
|
| 82 |
+is($dbi->fetch_filter, 'go', "$test : fetch_filter"); |
|
| 83 |
+is($dbi->result_class, 'ho', "$test : result_class"); |
|
| 84 |
+is($dbi->sql_template->tag_start, 0, "$test : sql_template"); |
|
| 85 |
+isa_ok($dbi, 'DBI::Custom::T1'); |
|
| 78 | 86 |
|
| 79 |
-{
|
|
| 80 |
- my $dbi = DBI::Custom::T1->new; |
|
| 81 |
- |
|
| 82 |
- is($dbi->user, 'a'); |
|
| 83 |
- is($dbi->password, 'b'); |
|
| 84 |
- is($dbi->data_source, 'c'); |
|
| 85 |
- is_deeply($dbi->dbi_options, {d => 1, e => 2});
|
|
| 86 |
- is_deeply({$dbi->filters}, {f => 3});
|
|
| 87 |
- is($dbi->bind_filter, 'f'); |
|
| 88 |
- is($dbi->fetch_filter, 'g'); |
|
| 89 |
- is($dbi->result_class, 'DBI::Custom::Result'); |
|
| 90 |
- is($dbi->sql_template->tag_start, 0); |
|
| 91 |
- isa_ok($dbi, 'DBI::Custom::T1'); |
|
| 92 |
- |
|
| 93 |
-} |
|
| 87 |
+test 'Sub class constructor default'; |
|
| 88 |
+$dbi = DBI::Custom::T1->new; |
|
| 89 |
+is($dbi->user, 'a', "$test : user"); |
|
| 90 |
+is($dbi->password, 'b', "$test : password"); |
|
| 91 |
+is($dbi->data_source, 'c', "$test : data_source"); |
|
| 92 |
+is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options");
|
|
| 93 |
+is_deeply({$dbi->filters}, {f => 3}, "$test : filters");
|
|
| 94 |
+is($dbi->bind_filter, 'f', "$test : bind_filter"); |
|
| 95 |
+is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
| 96 |
+is($dbi->result_class, 'DBI::Custom::Result', "$test : result_class"); |
|
| 97 |
+is($dbi->sql_template->tag_start, 0, "$test : sql_template"); |
|
| 98 |
+isa_ok($dbi, 'DBI::Custom::T1'); |
|
| 94 | 99 |
|
| 100 |
+test 'Sub sub class constructor default'; |
|
| 95 | 101 |
{
|
| 96 | 102 |
package DBI::Custom::T1_2; |
| 97 | 103 |
use base 'DBI::Custom::T1'; |
| 98 | 104 |
} |
| 99 | 105 |
|
| 100 |
-{
|
|
| 101 |
- my $dbi = DBI::Custom::T1_2->new; |
|
| 102 |
- |
|
| 103 |
- is($dbi->user, 'a'); |
|
| 104 |
- is($dbi->password, 'b'); |
|
| 105 |
- is($dbi->data_source, 'c'); |
|
| 106 |
- is_deeply($dbi->dbi_options, {d => 1, e => 2});
|
|
| 107 |
- is_deeply(scalar $dbi->filters, {f => 3});
|
|
| 108 |
- is($dbi->bind_filter, 'f'); |
|
| 109 |
- is($dbi->fetch_filter, 'g'); |
|
| 110 |
- is($dbi->result_class, 'DBI::Custom::Result'); |
|
| 111 |
- is($dbi->sql_template->tag_start, 0); |
|
| 112 |
- |
|
| 113 |
- isa_ok($dbi, 'DBI::Custom::T1_2'); |
|
| 114 |
-} |
|
| 106 |
+$dbi = DBI::Custom::T1_2->new; |
|
| 107 |
+is($dbi->user, 'a', "$test : user"); |
|
| 108 |
+is($dbi->password, 'b', "$test : passowrd"); |
|
| 109 |
+is($dbi->data_source, 'c', "$test : data_source"); |
|
| 110 |
+is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options");
|
|
| 111 |
+is_deeply(scalar $dbi->filters, {f => 3}, "$test : filters");
|
|
| 112 |
+is($dbi->bind_filter, 'f', "$test : bind_filter"); |
|
| 113 |
+is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
| 114 |
+is($dbi->result_class, 'DBI::Custom::Result', "$test : result_class"); |
|
| 115 |
+is($dbi->sql_template->tag_start, 0, "$test sql_template"); |
|
| 116 |
+isa_ok($dbi, 'DBI::Custom::T1_2'); |
|
| 115 | 117 |
|
| 118 |
+ |
|
| 119 |
+test 'Customized sub class constructor default'; |
|
| 116 | 120 |
{
|
| 117 | 121 |
package DBI::Custom::T1_3; |
| 118 | 122 |
use base 'DBI::Custom::T1'; |
| 119 | 123 |
|
| 120 |
- my $class = __PACKAGE__; |
|
| 121 |
- |
|
| 122 |
- $class |
|
| 124 |
+ __PACKAGE__ |
|
| 123 | 125 |
->user('ao')
|
| 124 | 126 |
->password('bo')
|
| 125 | 127 |
->data_source('co')
|
| ... | ... |
@@ -133,48 +135,41 @@ my $sql_tmpl3 = DBI::Custom::SQL::Template->new->tag_start(2); |
| 133 | 135 |
->sql_template($sql_tmpl2) |
| 134 | 136 |
; |
| 135 | 137 |
} |
| 138 |
+$dbi = DBI::Custom::T1_3->new; |
|
| 139 |
+is($dbi->user, 'ao', "$test : user"); |
|
| 140 |
+is($dbi->password, 'bo', "$test : password"); |
|
| 141 |
+is($dbi->data_source, 'co', "$test : data_source"); |
|
| 142 |
+is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options");
|
|
| 143 |
+is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters");
|
|
| 144 |
+is($dbi->bind_filter, 'fo', "$test : bind_filter"); |
|
| 145 |
+is($dbi->fetch_filter, 'go', "$test : fetch_filter"); |
|
| 146 |
+is($dbi->result_class, 'ho', "$test : result_class"); |
|
| 147 |
+is($dbi->sql_template->tag_start, 1, "$test : sql_template"); |
|
| 148 |
+isa_ok($dbi, 'DBI::Custom::T1_3'); |
|
| 136 | 149 |
|
| 137 |
-{
|
|
| 138 |
- my $dbi = DBI::Custom::T1_3->new; |
|
| 139 |
- |
|
| 140 |
- is($dbi->user, 'ao'); |
|
| 141 |
- is($dbi->password, 'bo'); |
|
| 142 |
- is($dbi->data_source, 'co'); |
|
| 143 |
- is_deeply($dbi->dbi_options, {do => 10, eo => 20});
|
|
| 144 |
- is_deeply(scalar $dbi->filters, {fo => 30});
|
|
| 145 |
- is($dbi->bind_filter, 'fo'); |
|
| 146 |
- is($dbi->fetch_filter, 'go'); |
|
| 147 |
- is($dbi->result_class, 'ho'); |
|
| 148 |
- is($dbi->sql_template->tag_start, 1); |
|
| 149 |
- |
|
| 150 |
- isa_ok($dbi, 'DBI::Custom::T1_3'); |
|
| 151 |
-} |
|
| 152 | 150 |
|
| 153 |
-{
|
|
| 154 |
- my $dbi = DBI::Custom::T1_3->new( |
|
| 155 |
- user => 'a', |
|
| 156 |
- password => 'b', |
|
| 157 |
- data_source => 'c', |
|
| 158 |
- dbi_options => {d => 1, e => 2},
|
|
| 159 |
- filters => {
|
|
| 160 |
- f => 3, |
|
| 161 |
- }, |
|
| 162 |
- bind_filter => 'f', |
|
| 163 |
- fetch_filter => 'g', |
|
| 164 |
- result_class => 'h', |
|
| 165 |
- sql_template => $sql_tmpl3, |
|
| 166 |
- ); |
|
| 167 |
- |
|
| 168 |
- is($dbi->user, 'a'); |
|
| 169 |
- is($dbi->password, 'b'); |
|
| 170 |
- is($dbi->data_source, 'c'); |
|
| 171 |
- is_deeply($dbi->dbi_options, {d => 1, e => 2});
|
|
| 172 |
- is_deeply({$dbi->filters}, {f => 3});
|
|
| 173 |
- is($dbi->bind_filter, 'f'); |
|
| 174 |
- is($dbi->fetch_filter, 'g'); |
|
| 175 |
- is($dbi->result_class, 'h'); |
|
| 176 |
- is($dbi->sql_template->tag_start, 2); |
|
| 177 |
- |
|
| 178 |
- isa_ok($dbi, 'DBI::Custom'); |
|
| 179 |
-} |
|
| 151 |
+test 'Customized sub class constructor'; |
|
| 152 |
+$dbi = DBI::Custom::T1_3->new( |
|
| 153 |
+ user => 'a', |
|
| 154 |
+ password => 'b', |
|
| 155 |
+ data_source => 'c', |
|
| 156 |
+ dbi_options => {d => 1, e => 2},
|
|
| 157 |
+ filters => {
|
|
| 158 |
+ f => 3, |
|
| 159 |
+ }, |
|
| 160 |
+ bind_filter => 'f', |
|
| 161 |
+ fetch_filter => 'g', |
|
| 162 |
+ result_class => 'h', |
|
| 163 |
+ sql_template => $sql_tmpl3, |
|
| 164 |
+); |
|
| 165 |
+is($dbi->user, 'a', "$test : user"); |
|
| 166 |
+is($dbi->password, 'b', "$test : password"); |
|
| 167 |
+is($dbi->data_source, 'c', "$test : data_source"); |
|
| 168 |
+is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options");
|
|
| 169 |
+is_deeply({$dbi->filters}, {f => 3}, "$test : filters");
|
|
| 170 |
+is($dbi->bind_filter, 'f', "$test : bind_filter"); |
|
| 171 |
+is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
|
| 172 |
+is($dbi->result_class, 'h', "$test : result_class"); |
|
| 173 |
+is($dbi->sql_template->tag_start, 2, "$test : sql_template"); |
|
| 174 |
+isa_ok($dbi, 'DBI::Custom'); |
|
| 180 | 175 |
|