Showing 1 changed files with 91 additions and 75 deletions
+91 -75
lib/DBIx/Custom.pm
... ...
@@ -77,62 +77,68 @@ sub AUTOLOAD {
77 77
 sub auto_filter {
78 78
     my $self = shift;
79 79
     
80
+    $self->{auto_filter} ||= {};
81
+    
80 82
     # Table
81 83
     my $table = shift;
82 84
     
83
-    # Column infomations
84
-    my @cs = @_;
85
-    
86
-    # Initialize filters
87
-    $self->{_auto_bind_filter} ||= {};
88
-    $self->{_auto_fetch_filter} ||= {};
89
-    
90
-    # Create auto filters
91
-    foreach my $c (@cs) {
92
-        croak "Usage \$dbi->auto_filter(" .
93
-              "TABLE, [COLUMN, BIND_FILTER, FETCH_FILTER], [...])"
94
-          unless ref $c eq 'ARRAY' && @$c == 3;
85
+    if (@_) {
86
+        # Column infomations
87
+        my @cs = @_;
95 88
         
96
-        # Column
97
-        my $column = $c->[0];
89
+        # Initialize filters
90
+        $self->{auto_filter}{bind} ||= {};
91
+        $self->{auto_filter}{fetch} ||= {};
98 92
         
99
-        # Bind filter
100
-        my $bind_filter  = $c->[1];
101
-        if (ref $bind_filter eq 'CODE') {
102
-	        $self->{_auto_bind_filter}{$table}{$column}
103
-	          = $bind_filter;
104
-	        $self->{_auto_bind_filter}{$table}{"$table.$column"}
105
-	          = $bind_filter;
93
+        # Create auto filters
94
+        foreach my $c (@cs) {
95
+            croak "Usage \$dbi->auto_filter(" .
96
+                  "TABLE, [COLUMN, BIND_FILTER, FETCH_FILTER], [...])"
97
+              unless ref $c eq 'ARRAY' && @$c == 3;
98
+            
99
+            # Column
100
+            my $column = $c->[0];
101
+            
102
+            # Bind filter
103
+            my $bind_filter  = $c->[1];
104
+            if (ref $bind_filter eq 'CODE') {
105
+    	        $self->{auto_filter}{bind}{$table}{$column}
106
+    	          = $bind_filter;
107
+    	        $self->{auto_filter}{bind}{$table}{"$table.$column"}
108
+    	          = $bind_filter;
109
+            }
110
+            else {
111
+    	        croak qq{"$bind_filter" is not registered}
112
+    	          unless exists $self->filters->{$bind_filter};
113
+    	        
114
+    	        $self->{auto_filter}{bind}{$table}{$column}
115
+    	          = $self->filters->{$bind_filter};
116
+    	        $self->{auto_filter}{bind}{$table}{"$table.$column"}
117
+    	          = $self->filters->{$bind_filter};
118
+    	    }
119
+            
120
+            # Fetch filter
121
+            my $fetch_filter = $c->[2];
122
+            if (ref $fetch_filter eq 'CODE') {
123
+    	        $self->{auto_filter}{fetch}{$table}{$column}
124
+    	          = $fetch_filter;
125
+    	        $self->{auto_filter}{fetch}{$table}{"$table.$column"}
126
+    	          = $fetch_filter;
127
+            }
128
+            else {
129
+                croak qq{"$fetch_filter" is not registered}
130
+                  unless exists $self->filters->{$fetch_filter};
131
+                $self->{auto_filter}{fetch}{$table}{$column}
132
+                  = $self->filters->{$fetch_filter};
133
+                $self->{auto_filter}{fetch}{$table}{"$table.$column"}
134
+                  = $self->filters->{$fetch_filter};
135
+            }
106 136
         }
107
-        else {
108
-	        croak qq{"$bind_filter" is not registered}
109
-	          unless exists $self->filters->{$bind_filter};
110
-	        
111
-	        $self->{_auto_bind_filter}{$table}{$column}
112
-	          = $self->filters->{$bind_filter};
113
-	        $self->{_auto_bind_filter}{$table}{"$table.$column"}
114
-	          = $self->filters->{$bind_filter};
115
-	    }
116 137
         
117
-        # Fetch filter
118
-        my $fetch_filter = $c->[2];
119
-        if (ref $fetch_filter eq 'CODE') {
120
-	        $self->{_auto_fetch_filter}{$table}{$column}
121
-	          = $fetch_filter;
122
-	        $self->{_auto_fetch_filter}{$table}{"$table.$column"}
123
-	          = $fetch_filter;
124
-        }
125
-        else {
126
-            croak qq{"$fetch_filter" is not registered}
127
-              unless exists $self->filters->{$fetch_filter};
128
-            $self->{_auto_fetch_filter}{$table}{$column}
129
-              = $self->filters->{$fetch_filter};
130
-            $self->{_auto_fetch_filter}{$table}{"$table.$column"}
131
-              = $self->filters->{$fetch_filter};
132
-        }
138
+        return $self;
133 139
     }
134 140
     
135
-    return $self;
141
+    return $self->{auto_filter};
136 142
 }
137 143
 
138 144
 sub helper {
... ...
@@ -228,36 +234,44 @@ sub create_query {
228 234
 
229 235
 sub default_bind_filter {
230 236
     my $self = shift;
231
-    my $fname = $_[0];
232 237
     
233
-    if (@_ && !$fname) {
234
-        $self->{_default_bind_filter} = undef;
235
-    }
236
-    else {
237
-        croak qq{"$fname" is not registered}
238
-          unless exists $self->filters->{$fname};
239
-    
240
-        $self->{_default_bind_filter} = $self->filters->{$fname};
238
+    if (@_) {
239
+        my $fname = $_[0];
240
+        
241
+        if (@_ && !$fname) {
242
+            $self->{default_bind_filter} = undef;
243
+        }
244
+        else {
245
+            croak qq{"$fname" is not registered}
246
+              unless exists $self->filters->{$fname};
247
+        
248
+            $self->{default_bind_filter} = $self->filters->{$fname};
249
+        }
250
+        return $self;
241 251
     }
242 252
     
243
-    return $self;
253
+    return $self->{default_bind_filter};
244 254
 }
245 255
 
246 256
 sub default_fetch_filter {
247 257
     my $self = shift;
248 258
     my $fname = $_[0];
249 259
     
250
-    if (@_ && !$fname) {
251
-        $self->{_default_fetch_filter} = undef;
252
-    }
253
-    else {
254
-        croak qq{"$fname" is not registered}
255
-          unless exists $self->filters->{$fname};
256
-    
257
-        $self->{_default_fetch_filter} = $self->filters->{$fname};
260
+    if (@_) {
261
+        if (@_ && !$fname) {
262
+            $self->{default_fetch_filter} = undef;
263
+        }
264
+        else {
265
+            croak qq{"$fname" is not registered}
266
+              unless exists $self->filters->{$fname};
267
+        
268
+            $self->{default_fetch_filter} = $self->filters->{$fname};
269
+        }
270
+        
271
+        return $self;
258 272
     }
259 273
     
260
-    return $self;
274
+    return $self->{default_fetch_filter}
261 275
 }
262 276
 
263 277
 our %VALID_DELETE_ARGS
... ...
@@ -339,7 +353,7 @@ sub execute{
339 353
     foreach my $table (@$auto_filter_tables) {
340 354
         $auto_filter = {
341 355
             %$auto_filter,
342
-            %{$self->{_auto_bind_filter}->{$table} || {}}
356
+            %{$self->{auto_filter}{bind}->{$table} || {}}
343 357
         }
344 358
     }
345 359
     
... ...
@@ -373,17 +387,17 @@ sub execute{
373 387
 	    foreach my $table (@$auto_filter_tables) {
374 388
 	        $auto_fetch_filter = {
375 389
 	            %$auto_filter,
376
-	            %{$self->{_auto_fetch_filter}{$table} || {}}
390
+	            %{$self->{auto_filter}{fetch}{$table} || {}}
377 391
 	        }
378 392
 	    }
379 393
 	    
380 394
 		# Result
381 395
 		my $result = $self->result_class->new(
382
-            sth            => $sth,
383
-            filters        => $self->filters,
384
-            filter_check   => $self->filter_check,
385
-            _auto_filter   => $auto_fetch_filter || {},
386
-            _default_filter => $self->{_default_fetch_filter}
396
+            sth             => $sth,
397
+            filters         => $self->filters,
398
+            filter_check    => $self->filter_check,
399
+            _auto_filter     => $auto_fetch_filter || {},
400
+            _default_filter => $self->default_fetch_filter
387 401
         );
388 402
 
389 403
         return $result;
... ...
@@ -673,7 +687,7 @@ sub _build_bind_values {
673 687
                   : $params->{$column};
674 688
         
675 689
         # Filtering
676
-        my $f = $filter->{$column} || $self->{_default_bind_filter} || '';
690
+        my $f = $filter->{$column} || $self->{default_bind_filter} || '';
677 691
         
678 692
         push @bind_values, $f ? $f->($value) : $value;
679 693
         
... ...
@@ -1009,12 +1023,14 @@ instead of suger methods.
1009 1023
 
1010 1024
 =head2 C<(deprecated) default_bind_filter>
1011 1025
 
1012
-    $dbi = $dbi->default_bind_filter($fname);
1026
+    my $default_bind_filter = $dbi->default_bind_filter;
1027
+    $dbi                    = $dbi->default_bind_filter($fname);
1013 1028
 
1014 1029
 Default filter when parameter binding is executed.
1015 1030
 
1016 1031
 =head2 C<(deprecated) default_fetch_filter>
1017 1032
 
1033
+    my $default_fetch_filter = $dbi->default_fetch_filter;
1018 1034
     $dbi = $dbi->default_fetch_filter($fname);
1019 1035
 
1020 1036
 =head2 C<execute>