Showing 1 changed files with 93 additions and 93 deletions
+93 -93
lib/DBIx/Custom.pm
... ...
@@ -230,22 +230,22 @@ sub dbh {
230 230
 }
231 231
 
232 232
 sub delete {
233
-    my ($self, %args) = @_;
233
+    my ($self, %opt) = @_;
234 234
 
235 235
     # Arguments
236
-    my $table = $args{table} || '';
236
+    my $table = $opt{table} || '';
237 237
     croak qq{"table" option must be specified. } . _subname
238 238
       unless $table;
239
-    my $where            = $args{where} || {};
240
-    my $allow_delete_all = $args{allow_delete_all};
241
-    my $where_param      = $args{where_param} || {};
242
-    my $id = $args{id};
243
-    my $primary_key = $args{primary_key};
239
+    my $where            = $opt{where} || {};
240
+    my $allow_delete_all = $opt{allow_delete_all};
241
+    my $where_param      = $opt{where_param} || {};
242
+    my $id = $opt{id};
243
+    my $primary_key = $opt{primary_key};
244 244
     croak "update method primary_key option " .
245 245
           "must be specified when id is specified " . _subname
246 246
       if defined $id && !defined $primary_key;
247 247
     $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
248
-    my $prefix = $args{prefix};
248
+    my $prefix = $opt{prefix};
249 249
     
250 250
     # Where
251 251
     $where = $self->_id_to_param($id, $primary_key, $table)
... ...
@@ -275,7 +275,7 @@ sub delete {
275 275
     $sql .= "from " . $self->_q($table) . " $where_clause ";
276 276
     
277 277
     # Execute query
278
-    return $self->execute($sql, $where_param, %args);
278
+    return $self->execute($sql, $where_param, %opt);
279 279
 }
280 280
 
281 281
 sub delete_all { shift->delete(allow_delete_all => 1, @_) }
... ...
@@ -286,15 +286,15 @@ sub create_model {
286 286
     my $self = shift;
287 287
     
288 288
     # Arguments
289
-    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
290
-    $args->{dbi} = $self;
291
-    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
292
-    my $model_name  = delete $args->{name};
293
-    my $model_table = delete $args->{table};
289
+    my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_};
290
+    $opt->{dbi} = $self;
291
+    my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model';
292
+    my $model_name  = delete $opt->{name};
293
+    my $model_table = delete $opt->{table};
294 294
     $model_name ||= $model_table;
295 295
     
296 296
     # Create model
297
-    my $model = $model_class->new($args);
297
+    my $model = $model_class->new($opt);
298 298
     weaken $model->{dbi};
299 299
     $model->name($model_name) unless $model->name;
300 300
     $model->table($model_table) unless $model->table;
... ...
@@ -375,33 +375,33 @@ sub execute {
375 375
     my $sql = shift;
376 376
     my $param;
377 377
     $param = shift if @_ % 2;
378
-    my %args = @_;
378
+    my %opt = @_;
379 379
     
380 380
     # Arguments
381
-    my $p = $args{param} || {};
381
+    my $p = $opt{param} || {};
382 382
     $param ||= $p;
383
-    my $tables = $args{table} || [];
383
+    my $tables = $opt{table} || [];
384 384
     $tables = [$tables] unless ref $tables eq 'ARRAY';
385
-    my $filter = $args{filter};
385
+    my $filter = $opt{filter};
386 386
     $filter = _array_to_hash($filter);
387
-    my $bind_type = $args{bind_type} || $args{type};
387
+    my $bind_type = $opt{bind_type} || $opt{type};
388 388
     $bind_type = _array_to_hash($bind_type);
389
-    my $type_rule_off = $args{type_rule_off};
389
+    my $type_rule_off = $opt{type_rule_off};
390 390
     my $type_rule_off_parts = {
391
-        1 => $args{type_rule1_off},
392
-        2 => $args{type_rule2_off}
391
+        1 => $opt{type_rule1_off},
392
+        2 => $opt{type_rule2_off}
393 393
     };
394
-    my $query_return = $args{query};
395
-    my $table_alias = $args{table_alias} || {};
396
-    my $after_build_sql = $args{after_build_sql} || $args{sqlfilter};
397
-    warn "sqlfilter option is DEPRECATED" if $args{sqlfilter};
398
-    my $id = $args{id};
399
-    my $primary_key = $args{primary_key};
394
+    my $query_return = $opt{query};
395
+    my $table_alias = $opt{table_alias} || {};
396
+    my $after_build_sql = $opt{after_build_sql} || $opt{sqlfilter};
397
+    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
398
+    my $id = $opt{id};
399
+    my $primary_key = $opt{primary_key};
400 400
     croak "execute method primary_key option " .
401 401
           "must be specified when id is specified " . _subname
402 402
       if defined $id && !defined $primary_key;
403 403
     $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
404
-    my $append = $args{append};
404
+    my $append = $opt{append};
405 405
     $sql .= $append if defined $append && !ref $sql;
406 406
     
407 407
     my $query
... ...
@@ -553,10 +553,10 @@ sub execute {
553 553
 }
554 554
 
555 555
 sub get_table_info {
556
-    my ($self, %args) = @_;
556
+    my ($self, %opt) = @_;
557 557
     
558
-    my $exclude = delete $args{exclude};
559
-    croak qq/"$_" is wrong option/ for keys %args;
558
+    my $exclude = delete $opt{exclude};
559
+    croak qq/"$_" is wrong option/ for keys %opt;
560 560
     
561 561
     my $table_info = [];
562 562
     $self->each_table(
... ...
@@ -568,10 +568,10 @@ sub get_table_info {
568 568
 }
569 569
 
570 570
 sub get_column_info {
571
-    my ($self, %args) = @_;
571
+    my ($self, %opt) = @_;
572 572
     
573
-    my $exclude_table = delete $args{exclude_table};
574
-    croak qq/"$_" is wrong option/ for keys %args;
573
+    my $exclude_table = delete $opt{exclude_table};
574
+    croak qq/"$_" is wrong option/ for keys %opt;
575 575
     
576 576
     my $column_info = [];
577 577
     $self->each_column(
... ...
@@ -632,17 +632,17 @@ sub update_or_insert {
632 632
 
633 633
     # Arguments
634 634
     my $param  = shift;
635
-    my %args = @_;
636
-    my $id = $args{id};
637
-    my $primary_key = $args{primary_key};
635
+    my %opt = @_;
636
+    my $id = $opt{id};
637
+    my $primary_key = $opt{primary_key};
638 638
     $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
639 639
     croak "update_or_insert method need primary_key option " .
640 640
           "when id is specified" . _subname
641 641
       if defined $id && !defined $primary_key;
642
-    my $table  = $args{table};
642
+    my $table  = $opt{table};
643 643
     croak qq{"table" option must be specified } . _subname
644 644
       unless defined $table;
645
-    my $select_option = $args{select_option};
645
+    my $select_option = $opt{select_option};
646 646
     
647 647
     my $rows = $self->select(table => $table, id => $id,
648 648
         primary_key => $primary_key, %$select_option)->all;
... ...
@@ -653,7 +653,7 @@ sub update_or_insert {
653 653
     my $row = $rows->[0];
654 654
     my @options = (table => $table);
655 655
     push @options, id => $id, primary_key => $primary_key if defined $id;
656
-    push @options, %args;
656
+    push @options, %opt;
657 657
     
658 658
     if ($row) {
659 659
         return $self->update($param, @options);
... ...
@@ -729,11 +729,11 @@ sub include_model {
729 729
         }
730 730
         
731 731
         # Create model
732
-        my $args = {};
733
-        $args->{model_class} = $mclass if $mclass;
734
-        $args->{name}        = $model_name if $model_name;
735
-        $args->{table}       = $model_table if $model_table;
736
-        $self->create_model($args);
732
+        my $opt = {};
733
+        $opt->{model_class} = $mclass if $mclass;
734
+        $opt->{name}        = $model_name if $model_name;
735
+        $opt->{table}       = $model_table if $model_table;
736
+        $self->create_model($opt);
737 737
     }
738 738
     
739 739
     return $self;
... ...
@@ -846,33 +846,33 @@ sub register_filter {
846 846
 }
847 847
 
848 848
 sub select {
849
-    my ($self, %args) = @_;
849
+    my ($self, %opt) = @_;
850 850
 
851 851
     # Arguments
852
-    my $table = $args{table};
852
+    my $table = $opt{table};
853 853
     my $tables = ref $table eq 'ARRAY' ? $table
854 854
                : defined $table ? [$table]
855 855
                : [];
856
-    $args{table} = $tables;
857
-    my $columns   = $args{column};
858
-    my $where     = $args{where} || {};
859
-    my $join      = $args{join} || [];
856
+    $opt{table} = $tables;
857
+    my $columns   = $opt{column};
858
+    my $where     = $opt{where} || {};
859
+    my $join      = $opt{join} || [];
860 860
     croak qq{"join" must be array reference } . _subname
861 861
       unless ref $join eq 'ARRAY';
862
-    my $relation = $args{relation};
862
+    my $relation = $opt{relation};
863 863
     warn "select() relation option is DEPRECATED!"
864 864
       if $relation;
865
-    my $param = $args{param} || {}; # DEPRECATED!
865
+    my $param = $opt{param} || {}; # DEPRECATED!
866 866
     warn "select() param option is DEPRECATED!"
867 867
       if keys %$param;
868
-    my $where_param = $args{where_param} || $param || {};
869
-    my $id = $args{id};
870
-    my $primary_key = $args{primary_key};
868
+    my $where_param = $opt{where_param} || $param || {};
869
+    my $id = $opt{id};
870
+    my $primary_key = $opt{primary_key};
871 871
     croak "update method primary_key option " .
872 872
           "must be specified when id is specified " . _subname
873 873
       if defined $id && !defined $primary_key;
874 874
     $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
875
-    my $prefix = $args{prefix};
875
+    my $prefix = $opt{prefix};
876 876
     
877 877
     # Add relation tables(DEPRECATED!);
878 878
     $self->_add_relation_table($tables, $relation);
... ...
@@ -959,7 +959,7 @@ sub select {
959 959
       if $relation;
960 960
     
961 961
     # Execute query
962
-    my $result = $self->execute($sql, $where_param, %args);
962
+    my $result = $self->execute($sql, $where_param, %opt);
963 963
     
964 964
     return $result;
965 965
 }
... ...
@@ -1090,25 +1090,25 @@ sub update {
1090 1090
     # Arguments
1091 1091
     my $param;
1092 1092
     $param = shift if @_ % 2;
1093
-    my %args = @_;
1094
-    my $table = $args{table} || '';
1093
+    my %opt = @_;
1094
+    my $table = $opt{table} || '';
1095 1095
     croak qq{"table" option must be specified } . _subname
1096 1096
       unless $table;
1097
-    my $p = $args{param} || {};
1097
+    my $p = $opt{param} || {};
1098 1098
     $param  ||= $p;
1099
-    my $where = $args{where} || {};
1100
-    my $where_param = $args{where_param} || {};
1101
-    my $allow_update_all = $args{allow_update_all};
1102
-    my $id = $args{id};
1103
-    my $primary_key = $args{primary_key};
1099
+    my $where = $opt{where} || {};
1100
+    my $where_param = $opt{where_param} || {};
1101
+    my $allow_update_all = $opt{allow_update_all};
1102
+    my $id = $opt{id};
1103
+    my $primary_key = $opt{primary_key};
1104 1104
     croak "update method primary_key option " .
1105 1105
           "must be specified when id is specified " . _subname
1106 1106
       if defined $id && !defined $primary_key;
1107 1107
     $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1108
-    my $prefix = $args{prefix};
1108
+    my $prefix = $opt{prefix};
1109 1109
     
1110 1110
     # Timestamp
1111
-    if ($args{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
1111
+    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
1112 1112
         my $columns = $update_timestamp->[0];
1113 1113
         $columns = [$columns] unless ref $columns eq 'ARRAY';
1114 1114
         my $value = $update_timestamp->[1];
... ...
@@ -1117,7 +1117,7 @@ sub update {
1117 1117
     }
1118 1118
 
1119 1119
     # Update clause
1120
-    my $assign_clause = $self->assign_clause($param, {wrap => $args{wrap}});
1120
+    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1121 1121
 
1122 1122
     # Where
1123 1123
     $where = $self->_id_to_param($id, $primary_key, $table)
... ...
@@ -1150,7 +1150,7 @@ sub update {
1150 1150
     $sql .= $self->_q($table) . " set $assign_clause $where_clause ";
1151 1151
     
1152 1152
     # Execute query
1153
-    return $self->execute($sql, $param, %args);
1153
+    return $self->execute($sql, $param, %opt);
1154 1154
 }
1155 1155
 
1156 1156
 sub update_all { shift->update(allow_update_all => 1, @_) };
... ...
@@ -1726,42 +1726,42 @@ sub apply_filter {
1726 1726
 
1727 1727
 # DEPRECATED!
1728 1728
 sub select_at {
1729
-    my ($self, %args) = @_;
1729
+    my ($self, %opt) = @_;
1730 1730
 
1731 1731
     warn "select_at is DEPRECATED! use update and id option instead";
1732 1732
 
1733 1733
     # Arguments
1734
-    my $primary_keys = delete $args{primary_key};
1734
+    my $primary_keys = delete $opt{primary_key};
1735 1735
     $primary_keys = [$primary_keys] unless ref $primary_keys;
1736
-    my $where = delete $args{where};
1737
-    my $param = delete $args{param};
1736
+    my $where = delete $opt{where};
1737
+    my $param = delete $opt{param};
1738 1738
     
1739 1739
     # Table
1740 1740
     croak qq{"table" option must be specified } . _subname
1741
-      unless $args{table};
1742
-    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1741
+      unless $opt{table};
1742
+    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1743 1743
     
1744 1744
     # Create where parameter
1745 1745
     my $where_param = $self->_id_to_param($where, $primary_keys);
1746 1746
     
1747
-    return $self->select(where => $where_param, %args);
1747
+    return $self->select(where => $where_param, %opt);
1748 1748
 }
1749 1749
 
1750 1750
 # DEPRECATED!
1751 1751
 sub delete_at {
1752
-    my ($self, %args) = @_;
1752
+    my ($self, %opt) = @_;
1753 1753
 
1754 1754
     warn "delete_at is DEPRECATED! use update and id option instead";
1755 1755
     
1756 1756
     # Arguments
1757
-    my $primary_keys = delete $args{primary_key};
1757
+    my $primary_keys = delete $opt{primary_key};
1758 1758
     $primary_keys = [$primary_keys] unless ref $primary_keys;
1759
-    my $where = delete $args{where};
1759
+    my $where = delete $opt{where};
1760 1760
     
1761 1761
     # Create where parameter
1762 1762
     my $where_param = $self->_id_to_param($where, $primary_keys);
1763 1763
     
1764
-    return $self->delete(where => $where_param, %args);
1764
+    return $self->delete(where => $where_param, %opt);
1765 1765
 }
1766 1766
 
1767 1767
 # DEPRECATED!
... ...
@@ -1773,17 +1773,17 @@ sub update_at {
1773 1773
     # Arguments
1774 1774
     my $param;
1775 1775
     $param = shift if @_ % 2;
1776
-    my %args = @_;
1777
-    my $primary_keys = delete $args{primary_key};
1776
+    my %opt = @_;
1777
+    my $primary_keys = delete $opt{primary_key};
1778 1778
     $primary_keys = [$primary_keys] unless ref $primary_keys;
1779
-    my $where = delete $args{where};
1780
-    my $p = delete $args{param} || {};
1779
+    my $where = delete $opt{where};
1780
+    my $p = delete $opt{param} || {};
1781 1781
     $param  ||= $p;
1782 1782
     
1783 1783
     # Create where parameter
1784 1784
     my $where_param = $self->_id_to_param($where, $primary_keys);
1785 1785
     
1786
-    return $self->update(where => $where_param, param => $param, %args);
1786
+    return $self->update(where => $where_param, param => $param, %opt);
1787 1787
 }
1788 1788
 
1789 1789
 # DEPRECATED!
... ...
@@ -1795,18 +1795,18 @@ sub insert_at {
1795 1795
     # Arguments
1796 1796
     my $param;
1797 1797
     $param = shift if @_ % 2;
1798
-    my %args = @_;
1799
-    my $primary_key = delete $args{primary_key};
1798
+    my %opt = @_;
1799
+    my $primary_key = delete $opt{primary_key};
1800 1800
     $primary_key = [$primary_key] unless ref $primary_key;
1801
-    my $where = delete $args{where};
1802
-    my $p = delete $args{param} || {};
1801
+    my $where = delete $opt{where};
1802
+    my $p = delete $opt{param} || {};
1803 1803
     $param  ||= $p;
1804 1804
     
1805 1805
     # Create where parameter
1806 1806
     my $where_param = $self->_id_to_param($where, $primary_key);
1807 1807
     $param = $self->merge_param($where_param, $param);
1808 1808
     
1809
-    return $self->insert(param => $param, %args);
1809
+    return $self->insert(param => $param, %opt);
1810 1810
 }
1811 1811
 
1812 1812
 # DEPRECATED!