Showing 3 changed files with 19 additions and 110 deletions
+14 -28
lib/DBIx/Custom.pm
... ...
@@ -100,15 +100,19 @@ sub auto_filter {
100 100
         my $bind_filter  = $c->[1];
101 101
         croak qq{"$bind_filter" is not registered}
102 102
           unless $self->filters->{$bind_filter};
103
-        $self->{_auto_bind_filter}{$table}{$column} = $bind_filter;
104
-        $self->{_auto_bind_filter}{$table}{"$table.$column"} = $bind_filter;
103
+        $self->{_auto_bind_filter}{$table}{$column}
104
+          = $self->filters->{$bind_filter};
105
+        $self->{_auto_bind_filter}{$table}{"$table.$column"}
106
+          = $self->filters->{$bind_filter};
105 107
         
106 108
         # Fetch filter
107 109
         my $fetch_filter = $c->[2];
108 110
         croak qq{"$fetch_filter" is not registered}
109 111
           unless $self->filters->{$fetch_filter};
110
-        $self->{_auto_fetch_filter}{$table}{$column} = $fetch_filter;
111
-        $self->{_auto_fetch_filter}{$table}{"$table.$column"} = $fetch_filter;
112
+        $self->{_auto_fetch_filter}{$table}{$column}
113
+          = $self->filters->{$fetch_filter};
114
+        $self->{_auto_fetch_filter}{$table}{"$table.$column"}
115
+          = $self->filters->{$fetch_filter};
112 116
     }
113 117
     
114 118
     return $self;
... ...
@@ -580,11 +584,6 @@ sub _build_bind_values {
580 584
     # Parameter
581 585
     $params ||= {};
582 586
     
583
-    # Check filter
584
-    $self->_check_filter($self->filters, $filter,
585
-                         $self->default_bind_filter, $params)
586
-      if $self->filter_check;
587
-    
588 587
     # Build bind values
589 588
     my $count = {};
590 589
     foreach my $column (@{$query->columns}) {
... ...
@@ -596,7 +595,10 @@ sub _build_bind_values {
596 595
         
597 596
         # Filtering
598 597
         my $fname = $filter->{$column} || $self->default_bind_filter || '';
599
-        my $filter_func = $fname ? $self->filters->{$fname} : undef;
598
+        my $filter_func = ref $fname ? $fname
599
+                        : $fname ? $self->filters->{$fname}
600
+                        : undef;
601
+        
600 602
         push @bind_values, $filter_func
601 603
                          ? $filter_func->($value)
602 604
                          : $value;
... ...
@@ -608,20 +610,6 @@ sub _build_bind_values {
608 610
     return \@bind_values;
609 611
 }
610 612
 
611
-sub _check_filter {
612
-    my ($self, $filters, $filter, $default_filter, $params) = @_;
613
-    
614
-    # Filter name not exists
615
-    foreach my $fname (values %$filter) {
616
-        croak qq{Bind filter "$fname" is not registered}
617
-          unless exists $filters->{$fname};
618
-    }
619
-    
620
-    # Default filter name not exists
621
-    croak qq{Default bind filter "$default_filter" is not registered}
622
-      if $default_filter && ! exists $filters->{$default_filter};
623
-}
624
-
625 613
 sub _croak {
626 614
     my ($self, $error, $append) = @_;
627 615
     $append ||= "";
... ...
@@ -854,10 +842,8 @@ Filter functions.
854 842
     my $filter_check = $dbi->filter_check;
855 843
     $dbi             = $dbi->filter_check(0);
856 844
 
857
-Enable filter check. 
858
-Default to 1.
859
-This check maybe damege performance.
860
-If you require performance, set C<filter_check> attribute to 0.
845
+B<this attribute is now deprecated and has no mean
846
+because check is always done>. 
861 847
 
862 848
 =head2 C<password>
863 849
 
+5 -27
lib/DBIx/Custom/Result.pm
... ...
@@ -25,11 +25,6 @@ sub fetch {
25 25
     # No row
26 26
     return unless @row;
27 27
     
28
-    # Check filter
29
-    $self->_check_filter($filters, $filter, 
30
-                         $self->default_filter, $self->sth)
31
-      if $self->{filter_check};
32
-    
33 28
     # Filtering
34 29
     my $columns = $self->{sth}->{NAME_lc};
35 30
     for (my $i = 0; $i < @$columns; $i++) {
... ...
@@ -41,7 +36,8 @@ sub fetch {
41 36
                    : $self->{default_filter};
42 37
         
43 38
         # Filtering
44
-        $row[$i] = $filters->{$fname}->($row[$i])
39
+        $row[$i] = ref $fname ? $fname->($row[$i]) 
40
+                 : $filters->{$fname}->($row[$i])
45 41
           if $fname;
46 42
     }
47 43
 
... ...
@@ -89,11 +85,6 @@ sub fetch_hash {
89 85
     # Cannot fetch
90 86
     return unless $row;
91 87
 
92
-    # Check filter
93
-    $self->_check_filter($filters, $filter, 
94
-                         $self->default_filter, $self->sth)
95
-      if $self->{filter_check};
96
-
97 88
     # Filter
98 89
     my $row_hash = {};
99 90
     my $columns = $self->{sth}->{NAME_lc};
... ...
@@ -107,8 +98,9 @@ sub fetch_hash {
107 98
         
108 99
         # Filtering
109 100
         $row_hash->{$column}
110
-          = $fname ? $filters->{$fname}->($row->[$i]) 
111
-                   : $row->[$i];
101
+          = ref $fname ? $fname->($row->[$i])
102
+          : $fname     ? $filters->{$fname}->($row->[$i]) 
103
+          : $row->[$i];
112 104
     }
113 105
     
114 106
     return $row_hash;
... ...
@@ -179,20 +171,6 @@ sub fetch_multi {
179 171
     return $rows;
180 172
 }
181 173
 
182
-sub _check_filter {
183
-    my ($self, $filters, $filter, $default_filter, $sth) = @_;
184
-    
185
-    # Filter name not exists
186
-    foreach my $fname (values %$filter) {
187
-        croak qq{Fetch filter "$fname" is not registered}
188
-          unless exists $filters->{$fname};
189
-    }
190
-    
191
-    # Default filter name not exists
192
-    croak qq{Default fetch filter "$default_filter" is not registered}
193
-      if $default_filter && ! exists $filters->{$default_filter};
194
-}
195
-
196 174
 1;
197 175
 
198 176
 =head1 NAME
-55
t/dbix-custom-core-sqlite.t
... ...
@@ -453,61 +453,6 @@ $dbi->cache(0);
453 453
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
454 454
 is(scalar keys %{$dbi->{_cached}}, 0, 'not cache');
455 455
 
456
-
457
-test 'filter_check in fetching';
458
-$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
459
-$dbi->execute($CREATE_TABLE->{0});
460
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
461
-$dbi->default_fetch_filter('not_exists');
462
-$result = $dbi->select(table => 'table1');
463
-eval{$result->fetch_first};
464
-like($@, qr/\QDefault fetch filter "not_exists" is not registered/, "$test : array :default_fetch_filter");
465
-
466
-$dbi->default_fetch_filter(undef);
467
-$result = $dbi->select(table => 'table1');
468
-$result->filter({key1 => 'not_exists'});
469
-eval{$result->fetch_first};
470
-like($@, qr/\QFetch filter "not_exists" is not registered/, "$test :  array :fetch_filter");
471
-
472
-$dbi->filter_check(0);
473
-$result = $dbi->select(table => 'table1');
474
-$result->filter({Key1 => 'encode_utf8'});
475
-eval{$result->fetch_first};
476
-ok(!$@, "$test : array : filter_check off");
477
-
478
-$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
479
-$dbi->execute($CREATE_TABLE->{0});
480
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
481
-$dbi->default_fetch_filter('not_exists');
482
-$result = $dbi->select(table => 'table1');
483
-eval{$result->fetch_hash_first};
484
-like($@, qr/\QDefault fetch filter "not_exists" is not registered/, "$test : hash :default_fetch_filter");
485
-
486
-$dbi->default_fetch_filter(undef);
487
-$result = $dbi->select(table => 'table1');
488
-$result->filter({key1 => 'not_exists'});
489
-eval{$result->fetch_hash_first};
490
-like($@, qr/\QFetch filter "not_exists" is not registered/, "$test : hash :fetch_filter");
491
-
492
-$dbi->filter_check(0);
493
-$result = $dbi->select(table => 'table1');
494
-$result->filter({Key1 => 'encode_utf8'});
495
-eval{$result->fetch_hash_first};
496
-ok(!$@, "$test : hash : filter_check off");
497
-
498
-test 'filter_check in parameter binding';
499
-$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
500
-$dbi->execute($CREATE_TABLE->{0});
501
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
502
-
503
-$dbi->default_bind_filter('not_exists');
504
-eval{$dbi->select(table => 'table1')};
505
-like($@, qr/\QDefault bind filter "not_exists" is not registered/, "$test : default_bind_filter");
506
-
507
-$dbi->default_bind_filter(undef);
508
-eval{$dbi->select(table => 'table1', filter => {key1 => 'not_exists'})};
509
-like($@, qr/\QBind filter "not_exists" is not registered/, "$test : bind_filter");
510
-
511 456
 test 'execute';
512 457
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
513 458
 $dbi->execute($CREATE_TABLE->{0});