Showing 10 changed files with 55 additions and 54 deletions
+36 -35
lib/DBIx/Custom.pm
... ...
@@ -71,7 +71,7 @@ sub available_datatype {
71 71
     my $self = shift;
72 72
     
73 73
     my $data_types = '';
74
-    foreach my $i (-1000 .. 1000) {
74
+    for my $i (-1000 .. 1000) {
75 75
          my $type_info = $self->dbh->type_info($i);
76 76
          my $data_type = $type_info->{DATA_TYPE};
77 77
          my $type_name = $type_info->{TYPE_NAME};
... ...
@@ -127,7 +127,7 @@ sub assign_clause {
127 127
     # Create set tag
128 128
     my @params;
129 129
     my $safety = $self->safety_character;
130
-    foreach my $column (sort keys %$param) {
130
+    for my $column (sort keys %$param) {
131 131
         croak qq{"$column" is not safety column name } . _subname
132 132
           unless $column =~ /^[$safety\.]+$/;
133 133
         my $column_quote = $self->_q($column);
... ...
@@ -406,13 +406,13 @@ sub execute {
406 406
     # Type rule
407 407
     my $type_filters = {};
408 408
     unless ($type_rule_off) {
409
-        foreach my $i (1, 2) {
409
+        for my $i (1, 2) {
410 410
             unless ($type_rule_off_parts->{$i}) {
411 411
                 $type_filters->{$i} = {};
412
-                foreach my $alias (keys %$table_alias) {
412
+                for my $alias (keys %$table_alias) {
413 413
                     my $table = $table_alias->{$alias};
414 414
                     
415
-                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
415
+                    for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
416 416
                         $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
417 417
                     }
418 418
                 }
... ...
@@ -425,7 +425,7 @@ sub execute {
425 425
     # DEPRECATED! Applied filter
426 426
     if ($self->{filter}{on}) {
427 427
         my $applied_filter = {};
428
-        foreach my $table (@$tables) {
428
+        for my $table (@$tables) {
429 429
             $applied_filter = {
430 430
                 %$applied_filter,
431 431
                 %{$self->{filter}{out}->{$table} || {}}
... ...
@@ -435,7 +435,7 @@ sub execute {
435 435
     }
436 436
     
437 437
     # Replace filter name to code
438
-    foreach my $column (keys %$filter) {
438
+    for my $column (keys %$filter) {
439 439
         my $name = $filter->{$column};
440 440
         if (!defined $name) {
441 441
             $filter->{$column} = undef;
... ...
@@ -478,7 +478,7 @@ sub execute {
478 478
     if (DEBUG) {
479 479
         print STDERR "SQL:\n" . $query->sql . "\n";
480 480
         my @output;
481
-        foreach my $b (@$bind) {
481
+        for my $b (@$bind) {
482 482
             my $value = $b->{value};
483 483
             $value = 'undef' unless defined $value;
484 484
             $value = encode(DEBUG_ENCODING(), $value)
... ...
@@ -497,8 +497,8 @@ sub execute {
497 497
             $filter->{in}  = {};
498 498
             $filter->{end} = {};
499 499
             push @$tables, $main_table if $main_table;
500
-            foreach my $table (@$tables) {
501
-                foreach my $way (qw/in end/) {
500
+            for my $table (@$tables) {
501
+                for my $way (qw/in end/) {
502 502
                     $filter->{$way} = {
503 503
                         %{$filter->{$way}},
504 504
                         %{$self->{filter}{$way}{$table} || {}}
... ...
@@ -644,7 +644,7 @@ sub include_model {
644 644
     }
645 645
     
646 646
     # Include models
647
-    foreach my $model_info (@$model_infos) {
647
+    for my $model_info (@$model_infos) {
648 648
         
649 649
         # Load model
650 650
         my $model_class;
... ...
@@ -690,8 +690,8 @@ sub merge_param {
690 690
     
691 691
     # Merge parameters
692 692
     my $merge = {};
693
-    foreach my $param (@params) {
694
-        foreach my $column (keys %$param) {
693
+    for my $param (@params) {
694
+        for my $column (keys %$param) {
695 695
             my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
696 696
             
697 697
             if (exists $merge->{$column}) {
... ...
@@ -744,7 +744,7 @@ sub new {
744 744
     
745 745
     # Check attributes
746 746
     my @attrs = keys %$self;
747
-    foreach my $attr (@attrs) {
747
+    for my $attr (@attrs) {
748 748
         croak qq{Invalid attribute: "$attr" } . _subname
749 749
           unless $self->can($attr);
750 750
     }
... ...
@@ -815,7 +815,7 @@ sub select {
815 815
     if (defined $opt{column}) {
816 816
         my $columns
817 817
           = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
818
-        foreach my $column (@$columns) {
818
+        for my $column (@$columns) {
819 819
             if (ref $column eq 'HASH') {
820 820
                 $column = $self->column(%$column) if ref $column eq 'HASH';
821 821
             }
... ...
@@ -838,7 +838,7 @@ sub select {
838 838
     $sql .= 'from ';
839 839
     if ($opt{relation}) {
840 840
         my $found = {};
841
-        foreach my $table (@$tables) {
841
+        for my $table (@$tables) {
842 842
             $sql .= $self->_q($table) . ', ' unless $found->{$table};
843 843
             $found->{$table} = 1;
844 844
         }
... ...
@@ -957,13 +957,13 @@ sub type_rule {
957 957
         my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
958 958
         
959 959
         # Into
960
-        foreach my $i (1 .. 2) {
960
+        for my $i (1 .. 2) {
961 961
             my $into = "into$i";
962 962
             my $exists_into = exists $type_rule->{$into};
963 963
             $type_rule->{$into} = _array_to_hash($type_rule->{$into});
964 964
             $self->{type_rule} = $type_rule;
965 965
             $self->{"_$into"} = {};
966
-            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
966
+            for my $type_name (keys %{$type_rule->{$into} || {}}) {
967 967
                 croak qq{type name of $into section must be lower case}
968 968
                   if $type_name =~ /[A-Z]/;
969 969
             }
... ...
@@ -992,9 +992,9 @@ sub type_rule {
992 992
         }
993 993
 
994 994
         # From
995
-        foreach my $i (1 .. 2) {
995
+        for my $i (1 .. 2) {
996 996
             $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
997
-            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
997
+            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
998 998
                 croak qq{data type of from$i section must be lower case or number}
999 999
                   if $data_type =~ /[A-Z]/;
1000 1000
                 my $fname = $type_rule->{"from$i"}{$data_type};
... ...
@@ -1118,7 +1118,7 @@ sub values_clause {
1118 1118
     my $safety = $self->safety_character;
1119 1119
     my @columns;
1120 1120
     my @placeholders;
1121
-    foreach my $column (sort keys %$param) {
1121
+    for my $column (sort keys %$param) {
1122 1122
         croak qq{"$column" is not safety column name } . _subname
1123 1123
           unless $column =~ /^[$safety\.]+$/;
1124 1124
         my $column_quote = $self->_q($column);
... ...
@@ -1219,7 +1219,7 @@ sub _create_bind_values {
1219 1219
     my $bind = [];
1220 1220
     my $count = {};
1221 1221
     my $not_exists = {};
1222
-    foreach my $column (@$columns) {
1222
+    for my $column (@$columns) {
1223 1223
         
1224 1224
         # Value
1225 1225
         my $value;
... ...
@@ -1246,7 +1246,7 @@ sub _create_bind_values {
1246 1246
         $value = $f->($value) if $f;
1247 1247
         
1248 1248
         # Type rule
1249
-        foreach my $i (1 .. 2) {
1249
+        for my $i (1 .. 2) {
1250 1250
             my $type_filter = $type_filters->{$i};
1251 1251
             my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
1252 1252
             $value = $tf->($value) if $tf;
... ...
@@ -1349,7 +1349,7 @@ sub _need_tables {
1349 1349
     my ($self, $tree, $need_tables, $tables) = @_;
1350 1350
     
1351 1351
     # Get needed tables
1352
-    foreach my $table (@$tables) {
1352
+    for my $table (@$tables) {
1353 1353
         if ($tree->{$table}) {
1354 1354
             $need_tables->{$table} = 1;
1355 1355
             $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
... ...
@@ -1431,10 +1431,11 @@ sub _push_join {
1431 1431
     # Search need tables
1432 1432
     my $need_tables = {};
1433 1433
     $self->_need_tables($tree, $need_tables, $join_tables);
1434
-    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
1434
+    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1435
+      keys %$need_tables;
1435 1436
     
1436 1437
     # Add join clause
1437
-    foreach my $need_table (@need_tables) {
1438
+    for my $need_table (@need_tables) {
1438 1439
         $$sql .= $tree->{$need_table}{join} . ' ';
1439 1440
     }
1440 1441
 }
... ...
@@ -1508,7 +1509,7 @@ sub _where_to_obj {
1508 1509
     if (ref $where eq 'HASH') {
1509 1510
         my $clause = ['and'];
1510 1511
         my $q = $self->_quote;
1511
-        foreach my $column (keys %$where) {
1512
+        for my $column (keys %$where) {
1512 1513
             my $table;
1513 1514
             my $c;
1514 1515
             if ($column =~ /(?:(.*?)\.)?(.*)/) {
... ...
@@ -1595,7 +1596,7 @@ sub _apply_filter {
1595 1596
         # Column
1596 1597
         my $column = $cinfos[$i];
1597 1598
         if (ref $column eq 'ARRAY') {
1598
-            foreach my $c (@$column) {
1599
+            for my $c (@$column) {
1599 1600
                 push @cinfos, $c, $cinfos[$i + 1];
1600 1601
             }
1601 1602
             next;
... ...
@@ -1605,13 +1606,13 @@ sub _apply_filter {
1605 1606
         my $finfo = $cinfos[$i + 1] || {};
1606 1607
         croak "$usage (table: $table) " . _subname
1607 1608
           unless  ref $finfo eq 'HASH';
1608
-        foreach my $ftype (keys %$finfo) {
1609
+        for my $ftype (keys %$finfo) {
1609 1610
             croak "$usage (table: $table) " . _subname
1610 1611
               unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1611 1612
         }
1612 1613
         
1613 1614
         # Set filters
1614
-        foreach my $way (qw/in out end/) {
1615
+        for my $way (qw/in out end/) {
1615 1616
         
1616 1617
             # Filter
1617 1618
             my $filter = $finfo->{$way};
... ...
@@ -1878,7 +1879,7 @@ sub _push_relation {
1878 1879
     
1879 1880
     if (keys %{$relation || {}}) {
1880 1881
         $$sql .= $need_where ? 'where ' : 'and ';
1881
-        foreach my $rcolumn (keys %$relation) {
1882
+        for my $rcolumn (keys %$relation) {
1882 1883
             my $table1 = (split (/\./, $rcolumn))[0];
1883 1884
             my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1884 1885
             push @$tables, ($table1, $table2);
... ...
@@ -1893,12 +1894,12 @@ sub _add_relation_table {
1893 1894
     my ($self, $tables, $relation) = @_;
1894 1895
     
1895 1896
     if (keys %{$relation || {}}) {
1896
-        foreach my $rcolumn (keys %$relation) {
1897
+        for my $rcolumn (keys %$relation) {
1897 1898
             my $table1 = (split (/\./, $rcolumn))[0];
1898 1899
             my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1899 1900
             my $table1_exists;
1900 1901
             my $table2_exists;
1901
-            foreach my $table (@$tables) {
1902
+            for my $table (@$tables) {
1902 1903
                 $table1_exists = 1 if $table eq $table1;
1903 1904
                 $table2_exists = 1 if $table eq $table2;
1904 1905
             }
... ...
@@ -2551,7 +2552,7 @@ You can check SQL or get statment handle.
2551 2552
 If you want to execute SQL fast, you can do the following way.
2552 2553
 
2553 2554
     my $query;
2554
-    foreach my $row (@$rows) {
2555
+    for my $row (@$rows) {
2555 2556
       $query ||= $dbi->insert($row, table => 'table1', query => 1);
2556 2557
       $dbi->execute($query, $row);
2557 2558
     }
... ...
@@ -2564,7 +2565,7 @@ You can do the following way.
2564 2565
     
2565 2566
     my $query;
2566 2567
     my $sth;
2567
-    foreach my $row (@$rows) {
2568
+    for my $row (@$rows) {
2568 2569
       $query ||= $dbi->insert($row, table => 'book', query => 1);
2569 2570
       $sth ||= $query->sth;
2570 2571
       $sth->execute(map { $row->{$_} } sort keys %$row);
+2 -2
lib/DBIx/Custom/Mapper.pm
... ...
@@ -22,7 +22,7 @@ sub map {
22 22
     
23 23
     # Mapping
24 24
     my $new_param = {};
25
-    foreach my $key (keys %rule) {
25
+    for my $key (keys %rule) {
26 26
         
27 27
         my $mapping = $rule{$key};
28 28
         
... ...
@@ -102,7 +102,7 @@ sub new {
102 102
     
103 103
     # Check attribute names
104 104
     my @attrs = keys %$self;
105
-    foreach my $attr (@attrs) {
105
+    for my $attr (@attrs) {
106 106
         croak qq{"$attr" is invalid attribute name (} . _subname . ")"
107 107
           unless $self->can($attr);
108 108
     }
+2 -2
lib/DBIx/Custom/Model.pm
... ...
@@ -40,7 +40,7 @@ sub AUTOLOAD {
40 40
 
41 41
 my @methods = qw/insert insert_at update update_at update_all
42 42
                  delete delete_at delete_all select select_at count/;
43
-foreach my $method (@methods) {
43
+for my $method (@methods) {
44 44
 
45 45
     my $code = sub {
46 46
         my $self = shift;
... ...
@@ -101,7 +101,7 @@ sub new {
101 101
     
102 102
     # Check attribute names
103 103
     my @attrs = keys %$self;
104
-    foreach my $attr (@attrs) {
104
+    for my $attr (@attrs) {
105 105
         croak qq{"$attr" is invalid attribute name } . _subname
106 106
           unless $self->can($attr);
107 107
     }
+2 -2
lib/DBIx/Custom/Order.pm
... ...
@@ -11,7 +11,7 @@ has 'dbi',
11 11
 sub prepend {
12 12
     my $self = shift;
13 13
     
14
-    foreach my $order (reverse @_) {
14
+    for my $order (reverse @_) {
15 15
         if (ref $order eq 'ARRAY') {
16 16
             my $column = shift @$order;
17 17
             $column = $self->dbi->_q($column) if defined $column;
... ...
@@ -30,7 +30,7 @@ sub to_string {
30 30
     
31 31
     my $exists = {};
32 32
     my @orders;
33
-    foreach my $order (@{$self->orders}) {
33
+    for my $order (@{$self->orders}) {
34 34
         next unless defined $order;
35 35
         $order =~ s/^\s+//;
36 36
         $order =~ s/\s+$//;
+2 -2
lib/DBIx/Custom/Query.pm
... ...
@@ -46,7 +46,7 @@ sub filter {
46 46
                 my $column = $ef->[$i];
47 47
                 my $f = $ef->[$i + 1];
48 48
                 if (ref $column eq 'ARRAY') {
49
-                    foreach my $c (@$column) {
49
+                    for my $c (@$column) {
50 50
                         $filter->{$c} = $f;
51 51
                     }
52 52
                 }
... ...
@@ -55,7 +55,7 @@ sub filter {
55 55
                 }
56 56
             }
57 57
         }
58
-        foreach my $column (keys %$filter) {
58
+        for my $column (keys %$filter) {
59 59
             my $fname = $filter->{$column};
60 60
             if  (exists $filter->{$column}
61 61
               && defined $fname
+1 -1
lib/DBIx/Custom/QueryBuilder.pm
... ...
@@ -208,7 +208,7 @@ sub _parse_tag {
208 208
     # Tables
209 209
     my $tables = [];
210 210
     # Build SQL 
211
-    foreach my $node (@tree) {
211
+    for my $node (@tree) {
212 212
         # Text
213 213
         if ($node->{type} eq 'text') { $sql .= $node->{value} }
214 214
         # Parameter
+4 -4
lib/DBIx/Custom/Result.pm
... ...
@@ -18,7 +18,7 @@ sub filter {
18 18
         # Convert filter name to subroutine
19 19
         my $filter = @_ == 1 ? $_[0] : [@_];
20 20
         $filter = _array_to_hash($filter);
21
-        foreach my $column (keys %$filter) {
21
+        for my $column (keys %$filter) {
22 22
             my $fname = $filter->{$column};
23 23
             if  (exists $filter->{$column}
24 24
               && defined $fname
... ...
@@ -230,9 +230,9 @@ sub type_rule {
230 230
         my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
231 231
 
232 232
         # From
233
-        foreach my $i (1 .. 2) {
233
+        for my $i (1 .. 2) {
234 234
             $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
235
-            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
235
+            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
236 236
                 croak qq{data type of from$i section must be lower case or number}
237 237
                   if $data_type =~ /[A-Z]/;
238 238
                 my $fname = $type_rule->{"from$i"}{$data_type};
... ...
@@ -300,7 +300,7 @@ sub end_filter {
300 300
                 @_ > 1 ? [@_] : $_[0]
301 301
             );
302 302
         }
303
-        foreach my $column (keys %$end_filter) {
303
+        for my $column (keys %$end_filter) {
304 304
             my $fname = $end_filter->{$column};
305 305
             if  (exists $end_filter->{$column}
306 306
               && defined $fname
+1 -1
lib/DBIx/Custom/Util.pm
... ...
@@ -20,7 +20,7 @@ sub _array_to_hash {
20 20
         my $f = $array->[$i + 1];
21 21
         
22 22
         if (ref $key eq 'ARRAY') {
23
-            foreach my $k (@$key) {
23
+            for my $k (@$key) {
24 24
                 $hash->{$k} = $f;
25 25
             }
26 26
         }
+2 -2
lib/DBIx/Custom/Where.pm
... ...
@@ -17,7 +17,7 @@ sub new {
17 17
     
18 18
     # Check attribute names
19 19
     my @attrs = keys %$self;
20
-    foreach my $attr (@attrs) {
20
+    for my $attr (@attrs) {
21 21
         croak qq{"$attr" is invalid attribute name (} . _subname . ")"
22 22
           unless $self->can($attr);
23 23
     }
... ...
@@ -31,7 +31,7 @@ sub to_string {
31 31
     # Check if column name is safety character;
32 32
     my $safety = $self->dbi->safety_character;
33 33
     if (ref $self->param eq 'HASH') {
34
-        foreach my $column (keys %{$self->param}) {
34
+        for my $column (keys %{$self->param}) {
35 35
             croak qq{"$column" is not safety column name (} . _subname . ")"
36 36
               unless $column =~ /^[$safety\.]+$/;
37 37
         }
+3 -3
t/common.t
... ...
@@ -2878,7 +2878,7 @@ $rows = [
2878 2878
 ];
2879 2879
 {
2880 2880
     my $query;
2881
-    foreach my $row (@$rows) {
2881
+    for my $row (@$rows) {
2882 2882
       $query ||= $dbi->insert($row, table => $table1, query => 1);
2883 2883
       $dbi->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
2884 2884
     }
... ...
@@ -2899,7 +2899,7 @@ $rows = [
2899 2899
 {
2900 2900
     my $query;
2901 2901
     my $sth;
2902
-    foreach my $row (@$rows) {
2902
+    for my $row (@$rows) {
2903 2903
       $query ||= $dbi->insert($row, table => $table1, query => 1);
2904 2904
       $sth ||= $query->sth;
2905 2905
       $sth->execute(map { $row->{$_} } sort keys %$row);
... ...
@@ -2921,7 +2921,7 @@ $rows = [
2921 2921
 {
2922 2922
     $model = $dbi->create_model(table => $table1, primary_key => $key1);
2923 2923
     my $query;
2924
-    foreach my $row (@$rows) {
2924
+    for my $row (@$rows) {
2925 2925
       $query ||= $model->insert($row, query => 1);
2926 2926
       $model->execute($query, $row, filter => {$key7 => sub { $_[0] * 2 }});
2927 2927
     }