Showing 1 changed files with 59 additions and 59 deletions
+59 -59
lib/DBIx/Custom.pm
... ...
@@ -240,7 +240,7 @@ sub dbh {
240 240
     }
241 241
 }
242 242
 
243
-our %VALID_DELETE_ARGS
243
+our %DELETE_ARGS
244 244
   = map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all/;
245 245
 
246 246
 sub delete {
... ...
@@ -249,16 +249,15 @@ sub delete {
249 249
     # Check argument names
250 250
     foreach my $name (keys %args) {
251 251
         croak qq{Argument "$name" is invalid name}
252
-          unless $VALID_DELETE_ARGS{$name};
252
+          unless $DELETE_ARGS{$name};
253 253
     }
254 254
     
255 255
     # Arguments
256
-    my $table            = $args{table} || '';
256
+    my $table = $args{table} || '';
257 257
     croak qq{"table" option must be specified} unless $table;
258
-    my $where            = $args{where} || {};
259
-    my $append           = $args{append};
260
-    my $filter           = $args{filter};
261
-    my $allow_delete_all = $args{allow_delete_all};
258
+    my $where            = delete $args{where} || {};
259
+    my $append           = delete $args{append};
260
+    my $allow_delete_all = delete $args{allow_delete_all};
262 261
 
263 262
     # Where
264 263
     my $w;
... ...
@@ -297,16 +296,18 @@ sub delete {
297 296
     
298 297
     # Execute query
299 298
     my $ret_val = $self->execute(
300
-        $query, param  => $where, filter => $filter,
301
-        table => $table);
299
+        $query,
300
+        param  => $where,
301
+        table => $table,
302
+        %args
303
+    );
302 304
     
303 305
     return $ret_val;
304 306
 }
305 307
 
306 308
 sub delete_all { shift->delete(allow_delete_all => 1, @_) }
307 309
 
308
-our %VALID_DELETE_AT_ARGS
309
-  = (%VALID_DELETE_ARGS, where => 1, primary_key => 1);
310
+our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
310 311
 
311 312
 sub delete_at {
312 313
     my ($self, %args) = @_;
... ...
@@ -314,7 +315,7 @@ sub delete_at {
314 315
     # Check argument names
315 316
     foreach my $name (keys %args) {
316 317
         croak qq{Argument "$name" is invalid name}
317
-          unless $VALID_DELETE_AT_ARGS{$name};
318
+          unless $DELETE_AT_ARGS{$name};
318 319
     }
319 320
     
320 321
     # Primary key
... ...
@@ -348,7 +349,7 @@ sub delete_at {
348 349
 
349 350
 sub DESTROY { }
350 351
 
351
-our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter table/;
352
+our %EXECUTE_ARGS = map { $_ => 1 } @COMMON_ARGS, 'param';
352 353
 
353 354
 sub execute{
354 355
     my ($self, $query, %args)  = @_;
... ...
@@ -356,7 +357,7 @@ sub execute{
356 357
     # Check argument names
357 358
     foreach my $name (keys %args) {
358 359
         croak qq{Argument "$name" is invalid name}
359
-          unless $VALID_EXECUTE_ARGS{$name};
360
+          unless $EXECUTE_ARGS{$name};
360 361
     }
361 362
     
362 363
     my $params = $args{param} || {};
... ...
@@ -474,8 +475,7 @@ sub execute{
474 475
     return $affected;
475 476
 }
476 477
 
477
-our %VALID_INSERT_ARGS
478
-  = map { $_ => 1 } @COMMON_ARGS, qw/param append/;
478
+our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param append/;
479 479
 
480 480
 sub insert {
481 481
     my ($self, %args) = @_;
... ...
@@ -483,15 +483,14 @@ sub insert {
483 483
     # Check argument names
484 484
     foreach my $name (keys %args) {
485 485
         croak qq{Argument "$name" is invalid name}
486
-          unless $VALID_INSERT_ARGS{$name};
486
+          unless $INSERT_ARGS{$name};
487 487
     }
488 488
     
489 489
     # Arguments
490
-    my $table  = $args{table};
490
+    my $table  = delete $args{table};
491 491
     croak qq{"table" option must be specified} unless $table;
492
-    my $param  = $args{param} || {};
493
-    my $append = $args{append} || '';
494
-    my $filter = $args{filter};
492
+    my $param  = delete $args{param} || {};
493
+    my $append = delete $args{append} || '';
495 494
     
496 495
     # Columns
497 496
     my @columns;
... ...
@@ -520,15 +519,14 @@ sub insert {
520 519
     my $ret_val = $self->execute(
521 520
         $query,
522 521
         param  => $param,
523
-        filter => $filter,
524
-        table => $table
522
+        table => $table,
523
+        %args
525 524
     );
526 525
     
527 526
     return $ret_val;
528 527
 }
529 528
 
530
-our %VALID_INSERT_AT_ARGS
531
-  = (%VALID_INSERT_ARGS, where => 1, primary_key => 1);
529
+our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
532 530
 
533 531
 sub insert_at {
534 532
     my ($self, %args) = @_;
... ...
@@ -536,7 +534,7 @@ sub insert_at {
536 534
     # Check argument names
537 535
     foreach my $name (keys %args) {
538 536
         croak qq{Argument "$name" is invalid name}
539
-          unless $VALID_INSERT_AT_ARGS{$name};
537
+          unless $INSERT_AT_ARGS{$name};
540 538
     }
541 539
     
542 540
     # Primary key
... ...
@@ -761,7 +759,7 @@ sub register_filter {
761 759
 
762 760
 sub register_tag { shift->query_builder->register_tag(@_) }
763 761
 
764
-our %VALID_SELECT_ARGS
762
+our %SELECT_ARGS
765 763
   = map { $_ => 1 } @COMMON_ARGS, qw/column where append relation
766 764
                                      selection join/;
767 765
 
... ...
@@ -771,25 +769,25 @@ sub select {
771 769
     # Check argument names
772 770
     foreach my $name (keys %args) {
773 771
         croak qq{Argument "$name" is invalid name}
774
-          unless $VALID_SELECT_ARGS{$name};
772
+          unless $SELECT_ARGS{$name};
775 773
     }
776 774
     
777 775
     # Arguments
778
-    my $table = $args{table};
776
+    my $table = delete $args{table};
779 777
     my $tables = ref $table eq 'ARRAY' ? $table
780 778
                : defined $table ? [$table]
781 779
                : [];
782
-    my $columns   = $args{column};
783
-    my $selection = $args{selection} || '';
784
-    my $where     = $args{where} || {};
785
-    my $append    = $args{append};
786
-    my $filter    = $args{filter};
787
-    my $join =     $args{join} || [];
780
+    my $columns   = delete $args{column};
781
+    my $selection = delete $args{selection} || '';
782
+    my $where     = delete $args{where} || {};
783
+    my $append    = delete $args{append};
784
+    my $join      = delete $args{join} || [];
788 785
     croak qq{"join" must be array reference}
789 786
       unless ref $join eq 'ARRAY';
787
+    my $relation = delete $args{relation};
790 788
     
791 789
     # Add relation tables(DEPRECATED!);
792
-    $self->_add_relation_table($tables, $args{relation});
790
+    $self->_add_relation_table($tables, $relation);
793 791
     
794 792
     # SQL stack
795 793
     my @sql;
... ...
@@ -865,7 +863,7 @@ sub select {
865 863
     # Table
866 864
     unless ($selection) {
867 865
         push @sql, 'from';
868
-        if ($args{relation}) {
866
+        if ($relation) {
869 867
             my $found = {};
870 868
             foreach my $table (@$tables) {
871 869
                 push @sql, ($table, ',') unless $found->{$table};
... ...
@@ -910,7 +908,7 @@ sub select {
910 908
     push @sql, $swhere;
911 909
     
912 910
     # Relation(DEPRECATED!);
913
-    $self->_push_relation(\@sql, $tables, $args{relation}, $swhere eq '' ? 1 : 0);
911
+    $self->_push_relation(\@sql, $tables, $relation, $swhere eq '' ? 1 : 0);
914 912
     
915 913
     # Append statement
916 914
     push @sql, $append if $append;
... ...
@@ -924,14 +922,16 @@ sub select {
924 922
     
925 923
     # Execute query
926 924
     my $result = $self->execute(
927
-        $query, param  => $where, filter => $filter,
928
-        table => $tables);
925
+        $query,
926
+        param  => $where, 
927
+        table => $tables,
928
+        %args
929
+    );
929 930
     
930 931
     return $result;
931 932
 }
932 933
 
933
-our %VALID_SELECT_AT_ARGS
934
-  = (%VALID_SELECT_ARGS, where => 1, primary_key => 1);
934
+our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
935 935
 
936 936
 sub select_at {
937 937
     my ($self, %args) = @_;
... ...
@@ -939,7 +939,7 @@ sub select_at {
939 939
     # Check argument names
940 940
     foreach my $name (keys %args) {
941 941
         croak qq{Argument "$name" is invalid name}
942
-          unless $VALID_SELECT_AT_ARGS{$name};
942
+          unless $SELECT_AT_ARGS{$name};
943 943
     }
944 944
     
945 945
     # Primary key
... ...
@@ -990,9 +990,8 @@ sub setup_model {
990 990
     return $self;
991 991
 }
992 992
 
993
-our %VALID_UPDATE_ARGS
994
-  = map { $_ => 1 } @COMMON_ARGS, qw/param where append
995
-                                     allow_update_all/;
993
+our %UPDATE_ARGS
994
+  = map { $_ => 1 } @COMMON_ARGS, qw/param where append allow_update_all/;
996 995
 
997 996
 sub update {
998 997
     my ($self, %args) = @_;
... ...
@@ -1000,17 +999,16 @@ sub update {
1000 999
     # Check argument names
1001 1000
     foreach my $name (keys %args) {
1002 1001
         croak qq{Argument "$name" is invalid name}
1003
-          unless $VALID_UPDATE_ARGS{$name};
1002
+          unless $UPDATE_ARGS{$name};
1004 1003
     }
1005 1004
     
1006 1005
     # Arguments
1007
-    my $table            = $args{table} || '';
1006
+    my $table = delete $args{table} || '';
1008 1007
     croak qq{"table" option must be specified} unless $table;
1009
-    my $param            = $args{param} || {};
1010
-    my $where            = $args{where} || {};
1011
-    my $append           = $args{append} || '';
1012
-    my $filter           = $args{filter};
1013
-    my $allow_update_all = $args{allow_update_all};
1008
+    my $param            = delete $args{param} || {};
1009
+    my $where            = delete $args{where} || {};
1010
+    my $append           = delete $args{append} || '';
1011
+    my $allow_update_all = delete $args{allow_update_all};
1014 1012
     
1015 1013
     # Update keys
1016 1014
     my @clumns = keys %$param;
... ...
@@ -1079,17 +1077,19 @@ sub update {
1079 1077
     return $query if $args{query};
1080 1078
     
1081 1079
     # Execute query
1082
-    my $ret_val = $self->execute($query, param  => $param, 
1083
-                                 filter => $filter,
1084
-                                 table => $table);
1080
+    my $ret_val = $self->execute(
1081
+        $query,
1082
+        param  => $param, 
1083
+        table => $table,
1084
+        %args
1085
+    );
1085 1086
     
1086 1087
     return $ret_val;
1087 1088
 }
1088 1089
 
1089 1090
 sub update_all { shift->update(allow_update_all => 1, @_) };
1090 1091
 
1091
-our %VALID_UPDATE_AT_ARGS
1092
-  = (%VALID_UPDATE_ARGS, where => 1, primary_key => 1);
1092
+our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1093 1093
 
1094 1094
 sub update_at {
1095 1095
     my ($self, %args) = @_;
... ...
@@ -1097,7 +1097,7 @@ sub update_at {
1097 1097
     # Check argument names
1098 1098
     foreach my $name (keys %args) {
1099 1099
         croak qq{Argument "$name" is invalid name}
1100
-          unless $VALID_UPDATE_AT_ARGS{$name};
1100
+          unless $UPDATE_AT_ARGS{$name};
1101 1101
     }
1102 1102
     
1103 1103
     # Primary key