Showing 3 changed files with 53 additions and 57 deletions
+2
Changes
... ...
@@ -1,4 +1,6 @@
1 1
 0.1629
2
+  renamed auto_filter to filter
3
+  changed filter method arguments
2 4
   deprecated cache_method
3 5
 0.1628
4 6
   remove DBIx::Custom::Model
+48 -48
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1628';
3
+our $VERSION = '0.1629';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -64,7 +64,7 @@ sub AUTOLOAD {
64 64
 sub apply_filter {
65 65
     my $self = shift;
66 66
     
67
-    $self->{auto_filter} ||= {};
67
+    $self->{filter} ||= {};
68 68
     
69 69
     # Table
70 70
     my $table = shift;
... ...
@@ -74,13 +74,13 @@ sub apply_filter {
74 74
         my @cs = @_;
75 75
         
76 76
         # Initialize filters
77
-        $self->{auto_filter}{out} ||= {};
78
-        $self->{auto_filter}{in} ||= {};
77
+        $self->{filter}{out} ||= {};
78
+        $self->{filter}{in} ||= {};
79 79
         
80 80
         # Create auto filters
81 81
         foreach my $c (@cs) {
82
-            croak "Usage \$dbi->auto_filter(" .
83
-                  "TABLE, [COLUMN, OUT_FILTER, IN_FILTER], [...])"
82
+            croak "Usage \$dbi->apply_filter(" .
83
+                  "TABLE, COLUMN, {in => INFILTER, out => OUTFILTER}, ...)"
84 84
               unless ref $c eq 'ARRAY' && @$c == 3;
85 85
             
86 86
             # Column
... ...
@@ -89,35 +89,35 @@ sub apply_filter {
89 89
             # Bind filter
90 90
             my $out_filter  = $c->[1];
91 91
             if (ref $out_filter eq 'CODE') {
92
-    	        $self->{auto_filter}{out}{$table}{$column}
93
-    	          = $out_filter;
94
-    	        $self->{auto_filter}{out}{$table}{"$table.$column"}
95
-    	          = $out_filter;
92
+                $self->{filter}{out}{$table}{$column}
93
+                  = $out_filter;
94
+                $self->{filter}{out}{$table}{"$table.$column"}
95
+                  = $out_filter;
96 96
             }
97 97
             else {
98
-    	        croak qq{"$out_filter" is not registered}
99
-    	          unless exists $self->filters->{$out_filter};
100
-    	        
101
-    	        $self->{auto_filter}{out}{$table}{$column}
102
-    	          = $self->filters->{$out_filter};
103
-    	        $self->{auto_filter}{out}{$table}{"$table.$column"}
104
-    	          = $self->filters->{$out_filter};
105
-    	    }
98
+                croak qq{"$out_filter" is not registered}
99
+                  unless exists $self->filters->{$out_filter};
100
+                
101
+                $self->{filter}{out}{$table}{$column}
102
+                  = $self->filters->{$out_filter};
103
+                $self->{filter}{out}{$table}{"$table.$column"}
104
+                  = $self->filters->{$out_filter};
105
+              }
106 106
             
107 107
             # Fetch filter
108 108
             my $in_filter = $c->[2];
109 109
             if (ref $in_filter eq 'CODE') {
110
-    	        $self->{auto_filter}{in}{$table}{$column}
111
-    	          = $in_filter;
112
-    	        $self->{auto_filter}{in}{$table}{"$table.$column"}
113
-    	          = $in_filter;
110
+                $self->{filter}{in}{$table}{$column}
111
+                  = $in_filter;
112
+                $self->{filter}{in}{$table}{"$table.$column"}
113
+                  = $in_filter;
114 114
             }
115 115
             else {
116 116
                 croak qq{"$in_filter" is not registered}
117 117
                   unless exists $self->filters->{$in_filter};
118
-                $self->{auto_filter}{in}{$table}{$column}
118
+                $self->{filter}{in}{$table}{$column}
119 119
                   = $self->filters->{$in_filter};
120
-                $self->{auto_filter}{in}{$table}{"$table.$column"}
120
+                $self->{filter}{in}{$table}{"$table.$column"}
121 121
                   = $self->filters->{$in_filter};
122 122
             }
123 123
         }
... ...
@@ -125,7 +125,7 @@ sub apply_filter {
125 125
         return $self;
126 126
     }
127 127
     
128
-    return $self->{auto_filter};
128
+    return $self->{filter};
129 129
 }
130 130
 
131 131
 sub helper {
... ...
@@ -306,32 +306,32 @@ sub execute{
306 306
       unless ref $query;
307 307
     
308 308
     # Auto filter
309
-    my $auto_filter = {};
309
+    my $filter = {};
310 310
     my $tables = $args{table} || [];
311 311
     $tables = [$tables]
312 312
       unless ref $tables eq 'ARRAY';
313 313
     foreach my $table (@$tables) {
314
-        $auto_filter = {
315
-            %$auto_filter,
316
-            %{$self->{auto_filter}{in}->{$table} || {}}
314
+        $filter = {
315
+            %$filter,
316
+            %{$self->{filter}{out}->{$table} || {}}
317 317
         }
318 318
     }
319 319
     
320
-    # Filter
321
-    my $filter = $args{filter} || $query->filter || {};
322
-    foreach my $column (keys %$filter) {
323
-        my $fname = $filter->{$column};
320
+    # Filter argument
321
+    my $f = $args{filter} || $query->filter || {};
322
+    foreach my $column (keys %$f) {
323
+        my $fname = $f->{$column};
324 324
         if (!defined $fname) {
325
-            $filter->{$column} = undef;
325
+            $f->{$column} = undef;
326 326
         }
327 327
         elsif (ref $fname ne 'CODE') {
328 328
           croak qq{"$fname" is not registered"}
329 329
             unless exists $self->filters->{$fname};
330 330
           
331
-          $filter->{$column} = $self->filters->{$fname};
331
+          $f->{$column} = $self->filters->{$fname};
332 332
         }
333 333
     }
334
-    $filter = {%$auto_filter, %$filter};
334
+    $filter = {%$filter, %$f};
335 335
     
336 336
     # Create bind values
337 337
     my $binds = $self->_build_binds($params, $query->columns, $filter);
... ...
@@ -346,21 +346,21 @@ sub execute{
346 346
     if ($sth->{NUM_OF_FIELDS}) {
347 347
         
348 348
         # Auto in filter
349
-        my $auto_in_filter = {};
350
-	      foreach my $table (@$tables) {
351
-	          $auto_in_filter = {
352
-	              %$auto_filter,
353
-	              %{$self->{auto_filter}{in}{$table} || {}}
354
-	          }
355
-	      }
356
-	    
357
-		# Result
358
-		my $result = $self->result_class->new(
349
+        my $in_filter = {};
350
+        foreach my $table (@$tables) {
351
+            $in_filter = {
352
+                %$in_filter,
353
+                %{$self->{filter}{in}{$table} || {}}
354
+            }
355
+        }
356
+        
357
+        # Result
358
+        my $result = $self->result_class->new(
359 359
             sth            => $sth,
360 360
             filters        => $self->filters,
361 361
             filter_check   => $self->filter_check,
362 362
             default_filter => $self->{default_in_filter},
363
-            _auto_filter   => $auto_in_filter || {}
363
+            filter         => $in_filter || {}
364 364
         );
365 365
 
366 366
         return $result;
... ...
@@ -980,7 +980,7 @@ C<apply_filter> is automatically filter for columns of table.
980 980
 This have effect C<insert>, C<update>, C<delete>. C<select>
981 981
 and L<DBIx::Custom::Result> object. but this has'nt C<execute> method.
982 982
 
983
-If you want to have effect <execute< method, use C<table>
983
+If you want to have effect C<execute()> method, use C<table>
984 984
 arguments.
985 985
 
986 986
     $result = $dbi->execute(
+3 -9
lib/DBIx/Custom/Result.pm
... ...
@@ -25,7 +25,7 @@ sub filter {
25 25
             }
26 26
         }
27 27
         
28
-        $self->{filter} = $filter;
28
+        $self->{filter} = {%{$self->filter || {}}, %$filter};
29 29
         
30 30
         return $self;
31 31
     }
... ...
@@ -36,11 +36,8 @@ sub filter {
36 36
 sub fetch {
37 37
     my $self = shift;
38 38
     
39
-    # Filters
40
-    my $filters = $self->filters || {};
39
+    # Filter
41 40
     my $filter  = $self->{filter}  || {};
42
-    my $auto_filter = $self->{_auto_filter} || {};
43
-    $filter = {%$auto_filter, %$filter};
44 41
     
45 42
     # Fetch
46 43
     my @row = $self->{sth}->fetchrow_array;
... ...
@@ -94,11 +91,8 @@ sub fetch_first {
94 91
 sub fetch_hash {
95 92
     my $self = shift;
96 93
     
97
-    # Filters
98
-    my $filters = $self->filters || {};
94
+    # Filter
99 95
     my $filter  = $self->filter  || {};
100
-    my $auto_filter = $self->{_auto_filter} || {};
101
-    $filter = {%$auto_filter, %$filter};
102 96
     
103 97
     # Fetch
104 98
     my $row = $self->{sth}->fetchrow_arrayref;