Showing 2 changed files with 26 additions and 51 deletions
+22 -39
lib/DBIx/Custom.pm
... ...
@@ -22,7 +22,7 @@ __PACKAGE__->class_attr('query_cache_max', default => 50,
22 22
 
23 23
 __PACKAGE__->attr([qw/user password data_source/]);
24 24
 __PACKAGE__->attr([qw/database host port/]);
25
-__PACKAGE__->attr([qw/bind_filter fetch_filter options/]);
25
+__PACKAGE__->attr([qw/default_bind_filter default_fetch_filter options/]);
26 26
 
27 27
 __PACKAGE__->dual_attr([qw/ filters formats/],
28 28
                        default => sub { {} }, inherit => 'hash_copy');
... ...
@@ -210,10 +210,10 @@ sub create_query {
210 210
     $query->sth($sth);
211 211
     
212 212
     # Set bind filter
213
-    $query->bind_filter($self->bind_filter);
213
+    $query->bind_filter($self->default_bind_filter);
214 214
     
215 215
     # Set fetch filter
216
-    $query->fetch_filter($self->fetch_filter);
216
+    $query->fetch_filter($self->default_fetch_filter);
217 217
     
218 218
     return $query;
219 219
 }
... ...
@@ -679,16 +679,6 @@ sub _add_query_cache {
679 679
     return $class;
680 680
 }
681 681
 
682
-sub filter_off {
683
-    my $self = shift;
684
-    
685
-    # Filter off
686
-    $self->bind_filter(undef);
687
-    $self->fetch_filter(undef);
688
-    
689
-    return $self;
690
-}
691
-
692 682
 =head1 NAME
693 683
 
694 684
 DBIx::Custom - Customizable DBI
... ...
@@ -824,22 +814,24 @@ This method is generally used to get a format.
824 814
 
825 815
 If you add format, use add_format method.
826 816
 
827
-=head2 bind_filter
817
+=head2 default_bind_filter
828 818
 
829 819
 Binding filter
830 820
 
831
-    $dbi         = $dbi->bind_filter($bind_filter);
832
-    $bind_filter = $dbi->bind_filter
821
+    $dbi                 = $dbi->default_bind_filter($default_bind_filter);
822
+    $default_bind_filter = $dbi->default_bind_filter
833 823
 
834 824
 The following is bind filter sample
835
-
836
-    $dbi->bind_filter(sub {
837
-        my ($value, $key, $dbi, $infos) = @_;
825
+    
826
+    $dbi->add_filter(encode_utf8 => sub {
827
+        my $value = shift;
838 828
         
839
-        # edit $value
829
+        require Encode 'encode_utf8';
840 830
         
841
-        return $value;
831
+        return encode_utf8($value);
842 832
     });
833
+    
834
+    $dbi->default_bind_filter('encode_utf8')
843 835
 
844 836
 Bind filter arguemts is
845 837
 
... ...
@@ -848,23 +840,25 @@ Bind filter arguemts is
848 840
     3. $dbi   : DBIx::Custom object
849 841
     4. $infos : {table => $table, column => $column}
850 842
 
851
-=head2 fetch_filter
843
+=head2 default_fetch_filter
852 844
 
853 845
 Fetching filter
854 846
 
855
-    $dbi          = $dbi->fetch_filter($fetch_filter);
856
-    $fetch_filter = $dbi->fetch_filter;
847
+    $dbi                  = $dbi->default_fetch_filter($default_fetch_filter);
848
+    $default_fetch_filter = $dbi->default_fetch_filter;
857 849
 
858 850
 The following is fetch filter sample
859 851
 
860
-    $dbi->fetch_filter(sub {
861
-        my ($value, $key, $dbi, $infos) = @_;
852
+    $dbi->add_filter(decode_utf8 => sub {
853
+        my $value = shift;
862 854
         
863
-        # edit $value
855
+        require Encode 'decode_utf8';
864 856
         
865
-        return $value;
857
+        return decode_utf8($value);
866 858
     });
867 859
 
860
+    $dbi->default_fetch_filter('decode_utf8');
861
+
868 862
 Bind filter arguemts is
869 863
 
870 864
     1. $value : Value
... ...
@@ -928,17 +922,6 @@ Check if database is connected.
928 922
     
929 923
     $is_connected = $dbi->connected;
930 924
     
931
-=head2 filter_off
932
-
933
-bind_filter and fitch_filter off
934
-    
935
-    $dbi->filter_off
936
-    
937
-This method is equeal to
938
-    
939
-    $dbi->bind_filter(undef);
940
-    $dbi->fetch_filter(undef);
941
-
942 925
 =head2 add_filter
943 926
 
944 927
 Resist filter
+4 -12
t/dbix-custom-core.t
... ...
@@ -30,14 +30,14 @@ $dbi = DBIx::Custom->new(
30 30
     filters => {
31 31
         f => 3,
32 32
     },
33
-    bind_filter => 'f',
34
-    fetch_filter => 'g',
33
+    default_bind_filter => 'f',
34
+    default_fetch_filter => 'g',
35 35
     result_class => 'g',
36 36
     sql_tmpl => $SQL_TMPL->{0},
37 37
 );
38 38
 is_deeply($dbi,{user => 'a', database => 'a', password => 'b', data_source => 'c', 
39
-                options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f',
40
-                fetch_filter => 'g', result_class => 'g',
39
+                options => {d => 1, e => 2}, filters => {f => 3}, default_bind_filter => 'f',
40
+                default_fetch_filter => 'g', result_class => 'g',
41 41
                 sql_tmpl => $SQL_TMPL->{0}}, $test);
42 42
 isa_ok($dbi, 'DBIx::Custom');
43 43
 
... ...
@@ -121,14 +121,6 @@ $dbi = DBIx::Custom->new;
121 121
 $dbi->add_format(a => sub {1});
122 122
 is($dbi->formats->{a}->(), 1, $test);
123 123
 
124
-test 'filter_off';
125
-$dbi = DBIx::Custom->new;
126
-$dbi->bind_filter('a');
127
-$dbi->fetch_filter('b');
128
-$dbi->filter_off;
129
-ok(!$dbi->bind_filter,  "$test : bind_filter  off");
130
-ok(!$dbi->fetch_filter, "$test : fetch_filter off");
131
-
132 124
 test 'Accessor';
133 125
 $dbi = DBIx::Custom->new;
134 126
 $dbi->options({opt1 => 1, opt2 => 2});