| ... | ... | @@ -32,6 +32,15 @@ sub filters : ClassObjectAttr { | 
| 32 | 32 | } | 
| 33 | 33 | } | 
| 34 | 34 |  | 
| 35 | +sub formats : ClassObjectAttr { | |
| 36 | + type => 'hash', | |
| 37 | + deref => 1, | |
| 38 | +    initialize => { | |
| 39 | + clone => 'hash', | |
| 40 | +        default => sub { {} } | |
| 41 | + } | |
| 42 | +} | |
| 43 | + | |
| 35 | 44 |  sub result_class : ClassObjectAttr { | 
| 36 | 45 |      initialize => { | 
| 37 | 46 | clone => 'scalar', | 
| ... | ... | @@ -62,6 +71,16 @@ sub add_filter { | 
| 62 | 71 | return $invocant; | 
| 63 | 72 | } | 
| 64 | 73 |  | 
| 74 | +# Add format | |
| 75 | +sub add_format{ | |
| 76 | + my $invocant = shift; | |
| 77 | + | |
| 78 | + my %old_formats = $invocant->formats; | |
| 79 | +    my %new_formats = ref $_[0] eq 'HASH' ? %{$_[0]} : @_; | |
| 80 | + $invocant->formats(%old_formats, %new_formats); | |
| 81 | + return $invocant; | |
| 82 | +} | |
| 83 | + | |
| 65 | 84 | # Auto commit | 
| 66 | 85 |  sub _auto_commit { | 
| 67 | 86 | my $self = shift; | 
| ... | ... | @@ -802,6 +821,12 @@ This method is same as DBI::do | 
| 802 | 821 | $self = $dbi->filters($filters); | 
| 803 | 822 | $filters = $dbi->filters; | 
| 804 | 823 |  | 
| 824 | +=head2 formats | |
| 825 | + | |
| 826 | + # Set and get formats | |
| 827 | + $self = $dbi->formats($formats); | |
| 828 | + $formats = $dbi->formats; | |
| 829 | + | |
| 805 | 830 | =head2 bind_filter | 
| 806 | 831 |  | 
| 807 | 832 | # Set and get binding filter | 
| ... | ... | @@ -925,6 +950,10 @@ If database is already disconnected, this method do noting. | 
| 925 | 950 |  | 
| 926 | 951 | add_filter add filter to filters | 
| 927 | 952 |  | 
| 953 | +=head2 add_format | |
| 954 | + | |
| 955 | + $dbi->add_format(date => '%Y:%m:%d'); | |
| 956 | + | |
| 928 | 957 | =head2 create_query | 
| 929 | 958 |  | 
| 930 | 959 | # Create Query object from SQL template | 
| ... | ... | @@ -54,6 +54,9 @@ test 'Sub class constructor'; | 
| 54 | 54 | ->filters( | 
| 55 | 55 | f => 3 | 
| 56 | 56 | ) | 
| 57 | + ->formats( | |
| 58 | + f => 3 | |
| 59 | + ) | |
| 57 | 60 |        ->bind_filter('f') | 
| 58 | 61 |        ->fetch_filter('g') | 
| 59 | 62 |        ->result_class('DBI::Custom::Result') | 
| ... | ... | @@ -68,6 +71,9 @@ $dbi = DBI::Custom::T1->new( | 
| 68 | 71 |      filters => { | 
| 69 | 72 | fo => 30, | 
| 70 | 73 | }, | 
| 74 | +    formats => { | |
| 75 | + fo => 30, | |
| 76 | + }, | |
| 71 | 77 | bind_filter => 'fo', | 
| 72 | 78 | fetch_filter => 'go', | 
| 73 | 79 | result_class => 'ho', | 
| ... | ... | @@ -78,6 +84,7 @@ is($dbi->password, 'bo', "$test : passowr"); | 
| 78 | 84 | is($dbi->data_source, 'co', "$test : data_source"); | 
| 79 | 85 |  is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options"); | 
| 80 | 86 |  is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); | 
| 87 | +is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats"); | |
| 81 | 88 | is($dbi->bind_filter, 'fo', "$test : bind_filter"); | 
| 82 | 89 | is($dbi->fetch_filter, 'go', "$test : fetch_filter"); | 
| 83 | 90 | is($dbi->result_class, 'ho', "$test : result_class"); | 
| ... | ... | @@ -91,6 +98,7 @@ is($dbi->password, 'b', "$test : password"); | 
| 91 | 98 | is($dbi->data_source, 'c', "$test : data_source"); | 
| 92 | 99 |  is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); | 
| 93 | 100 |  is_deeply({$dbi->filters}, {f => 3}, "$test : filters"); | 
| 101 | +is_deeply({$dbi->formats}, {f => 3}, "$test : formats"); | |
| 94 | 102 | is($dbi->bind_filter, 'f', "$test : bind_filter"); | 
| 95 | 103 | is($dbi->fetch_filter, 'g', "$test : fetch_filter"); | 
| 96 | 104 | is($dbi->result_class, 'DBI::Custom::Result', "$test : result_class"); | 
| ... | ... | @@ -109,6 +117,7 @@ is($dbi->password, 'b', "$test : passowrd"); | 
| 109 | 117 | is($dbi->data_source, 'c', "$test : data_source"); | 
| 110 | 118 |  is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); | 
| 111 | 119 |  is_deeply(scalar $dbi->filters, {f => 3}, "$test : filters"); | 
| 120 | +is_deeply(scalar $dbi->formats, {f => 3}, "$test : formats"); | |
| 112 | 121 | is($dbi->bind_filter, 'f', "$test : bind_filter"); | 
| 113 | 122 | is($dbi->fetch_filter, 'g', "$test : fetch_filter"); | 
| 114 | 123 | is($dbi->result_class, 'DBI::Custom::Result', "$test : result_class"); | 
| ... | ... | @@ -129,6 +138,9 @@ test 'Customized sub class constructor default'; | 
| 129 | 138 | ->filters( | 
| 130 | 139 | fo => 30 | 
| 131 | 140 | ) | 
| 141 | + ->formats( | |
| 142 | + fo => 30 | |
| 143 | + ) | |
| 132 | 144 |        ->bind_filter('fo') | 
| 133 | 145 |        ->fetch_filter('go') | 
| 134 | 146 |        ->result_class('ho') | 
| ... | ... | @@ -141,6 +153,7 @@ is($dbi->password, 'bo', "$test : password"); | 
| 141 | 153 | is($dbi->data_source, 'co', "$test : data_source"); | 
| 142 | 154 |  is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options"); | 
| 143 | 155 |  is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); | 
| 156 | +is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats"); | |
| 144 | 157 | is($dbi->bind_filter, 'fo', "$test : bind_filter"); | 
| 145 | 158 | is($dbi->fetch_filter, 'go', "$test : fetch_filter"); | 
| 146 | 159 | is($dbi->result_class, 'ho', "$test : result_class"); | 
| ... | ... | @@ -157,6 +170,9 @@ $dbi = DBI::Custom::T1_3->new( | 
| 157 | 170 |      filters => { | 
| 158 | 171 | f => 3, | 
| 159 | 172 | }, | 
| 173 | +    formats => { | |
| 174 | + f => 3, | |
| 175 | + }, | |
| 160 | 176 | bind_filter => 'f', | 
| 161 | 177 | fetch_filter => 'g', | 
| 162 | 178 | result_class => 'h', | 
| ... | ... | @@ -167,6 +183,7 @@ is($dbi->password, 'b', "$test : password"); | 
| 167 | 183 | is($dbi->data_source, 'c', "$test : data_source"); | 
| 168 | 184 |  is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); | 
| 169 | 185 |  is_deeply({$dbi->filters}, {f => 3}, "$test : filters"); | 
| 186 | +is_deeply({$dbi->formats}, {f => 3}, "$test : formats"); | |
| 170 | 187 | is($dbi->bind_filter, 'f', "$test : bind_filter"); | 
| 171 | 188 | is($dbi->fetch_filter, 'g', "$test : fetch_filter"); | 
| 172 | 189 | is($dbi->result_class, 'h', "$test : result_class"); | 
| ... | ... | @@ -179,3 +196,8 @@ $dbi = DBI::Custom->new; | 
| 179 | 196 |  $dbi->add_filter(a => sub {1}); | 
| 180 | 197 |  is($dbi->filters->{a}->(), 1, $test); | 
| 181 | 198 |  | 
| 199 | +test 'add_formats'; | |
| 200 | +$dbi = DBI::Custom->new; | |
| 201 | +$dbi->add_format(a => sub {1}); | |
| 202 | +is($dbi->formats->{a}->(), 1, $test); | |
| 203 | + |