Showing 4 changed files with 73 additions and 45 deletions
+3
Changes
... ...
@@ -1,4 +1,7 @@
1 1
 0.1730
2
+    - method method of DBIx::Custom::Model is renamed to helper,
3
+      method is DEPRECATED!
4
+    - method method is renamed to helper, method is DEPRECATED!
2 5
     - insert method's id option is DEPRECATED!
3 6
     - fixed id option bug when column name is anbiguous
4 7
 0.1729
+46 -39
lib/DBIx/Custom.pm
... ...
@@ -595,6 +595,16 @@ sub get_column_info {
595 595
         @$column_info];
596 596
 }
597 597
 
598
+sub helper {
599
+    my $self = shift;
600
+    
601
+    # Register method
602
+    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
603
+    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
604
+    
605
+    return $self;
606
+}
607
+
598 608
 sub insert {
599 609
     my $self = shift;
600 610
     
... ...
@@ -646,32 +656,6 @@ sub insert {
646 656
     return $self->execute($sql, $param, table => $table, %args);
647 657
 }
648 658
 
649
-sub values_clause {
650
-    my ($self, $param, $opts) = @_;
651
-    
652
-    my $wrap = $opts->{wrap} || {};
653
-    
654
-    # Create insert parameter tag
655
-    my $safety = $self->safety_character;
656
-    my @columns;
657
-    my @placeholders;
658
-    foreach my $column (sort keys %$param) {
659
-        croak qq{"$column" is not safety column name } . _subname
660
-          unless $column =~ /^[$safety\.]+$/;
661
-        my $column_quote = $self->_q($column);
662
-        $column_quote =~ s/\./$self->_q(".")/e;
663
-        push @columns, $column_quote;
664
-        
665
-        my $func = $wrap->{$column} || sub { $_[0] };
666
-        push @placeholders,
667
-          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
668
-        : $func->(":$column");
669
-    }
670
-    
671
-    return '(' . join(', ', @columns) . ') ' . 'values ' .
672
-           '(' . join(', ', @placeholders) . ')'
673
-}
674
-
675 659
 sub insert_timestamp {
676 660
     my $self = shift;
677 661
     
... ...
@@ -779,16 +763,6 @@ sub merge_param {
779 763
     return $merge;
780 764
 }
781 765
 
782
-sub method {
783
-    my $self = shift;
784
-    
785
-    # Register method
786
-    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
787
-    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
788
-    
789
-    return $self;
790
-}
791
-
792 766
 sub model {
793 767
     my ($self, $name, $model) = @_;
794 768
     
... ...
@@ -1192,6 +1166,32 @@ sub update_timestamp {
1192 1166
     return $self->{update_timestamp};
1193 1167
 }
1194 1168
 
1169
+sub values_clause {
1170
+    my ($self, $param, $opts) = @_;
1171
+    
1172
+    my $wrap = $opts->{wrap} || {};
1173
+    
1174
+    # Create insert parameter tag
1175
+    my $safety = $self->safety_character;
1176
+    my @columns;
1177
+    my @placeholders;
1178
+    foreach my $column (sort keys %$param) {
1179
+        croak qq{"$column" is not safety column name } . _subname
1180
+          unless $column =~ /^[$safety\.]+$/;
1181
+        my $column_quote = $self->_q($column);
1182
+        $column_quote =~ s/\./$self->_q(".")/e;
1183
+        push @columns, $column_quote;
1184
+        
1185
+        my $func = $wrap->{$column} || sub { $_[0] };
1186
+        push @placeholders,
1187
+          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1188
+        : $func->(":$column");
1189
+    }
1190
+    
1191
+    return '(' . join(', ', @columns) . ') ' . 'values ' .
1192
+           '(' . join(', ', @placeholders) . ')'
1193
+}
1194
+
1195 1195
 sub where { DBIx::Custom::Where->new(dbi => shift, @_) }
1196 1196
 
1197 1197
 sub _create_query {
... ...
@@ -1678,6 +1678,11 @@ has default_dbi_option => sub {
1678 1678
     return shift->default_option;
1679 1679
 };
1680 1680
 
1681
+# DEPRECATED!
1682
+sub method {
1683
+    warn "method is DEPRECATED! use helper instead";
1684
+    return shift->helper(@_);
1685
+}
1681 1686
 
1682 1687
 # DEPRECATED!
1683 1688
 sub assign_param {
... ...
@@ -2930,9 +2935,9 @@ Merge parameters.
2930 2935
 
2931 2936
     {key1 => [1, 1], key2 => 2}
2932 2937
 
2933
-=head2 C<method>
2938
+=head2 C<helper>
2934 2939
 
2935
-    $dbi->method(
2940
+    $dbi->helper(
2936 2941
         update_or_insert => sub {
2937 2942
             my $self = shift;
2938 2943
             
... ...
@@ -2945,7 +2950,7 @@ Merge parameters.
2945 2950
         }
2946 2951
     );
2947 2952
 
2948
-Register method. These method is called directly from L<DBIx::Custom> object.
2953
+Register helper. These helper is called directly from L<DBIx::Custom> object.
2949 2954
 
2950 2955
     $dbi->update_or_insert;
2951 2956
     $dbi->find_or_create;
... ...
@@ -3512,6 +3517,7 @@ L<DBIx::Custom>
3512 3517
     cache_method # will be removed at 2017/1/1
3513 3518
     
3514 3519
     # Methods
3520
+    method # will be removed at 2017/1/1
3515 3521
     assign_param # will be removed at 2017/1/1
3516 3522
     update_param # will be removed at 2017/1/1
3517 3523
     insert_param # will be removed at 2017/1/1
... ...
@@ -3546,6 +3552,7 @@ L<DBIx::Custom>
3546 3552
 L<DBIx::Custom::Model>
3547 3553
 
3548 3554
     # Attribute methods
3555
+    method # will be removed at 2017/1/1
3549 3556
     filter # will be removed at 2017/1/1
3550 3557
     name # will be removed at 2017/1/1
3551 3558
     type # will be removed at 2017/1/1
+11 -4
lib/DBIx/Custom/Model.pm
... ...
@@ -75,7 +75,7 @@ sub execute {
75 75
 
76 76
 sub DESTROY { }
77 77
 
78
-sub method {
78
+sub helper {
79 79
     my $self = shift;
80 80
     
81 81
     # Merge
... ...
@@ -114,6 +114,13 @@ has 'filter';
114 114
 has 'name';
115 115
 has type => sub { [] };
116 116
 
117
+
118
+# DEPRECATED!
119
+sub method {
120
+    warn "method method is DEPRECATED! use helper instead";
121
+    return shift->helper(@_);
122
+}
123
+
117 124
 1;
118 125
 
119 126
 =head1 NAME
... ...
@@ -210,9 +217,9 @@ you don't have to specify C<table> and C<primary_key> option.
210 217
 Same as C<insert> of L<DBIx::Custom> except that
211 218
 you don't have to specify C<table> and C<primary_key> option.
212 219
 
213
-=head2 C<method>
220
+=head2 C<helper>
214 221
 
215
-    $model->method(
222
+    $model->helper(
216 223
         update_or_insert => sub {
217 224
             my $self = shift;
218 225
             
... ...
@@ -224,7 +231,7 @@ you don't have to specify C<table> and C<primary_key> option.
224 231
             # ...
225 232
     );
226 233
 
227
-Register method. These method is called directly from L<DBIx::Custom::Model> object.
234
+Register helper. These helper is called directly from L<DBIx::Custom::Model> object.
228 235
 
229 236
     $model->update_or_insert;
230 237
     $model->find_or_create;
+13 -2
t/common.t
... ...
@@ -1054,10 +1054,10 @@ ok($@, "execute fail");
1054 1054
 }
1055 1055
 
1056 1056
 test 'method';
1057
-$dbi->method(
1057
+$dbi->helper(
1058 1058
     one => sub { 1 }
1059 1059
 );
1060
-$dbi->method(
1060
+$dbi->helper(
1061 1061
     two => sub { 2 }
1062 1062
 );
1063 1063
 $dbi->method({
... ...
@@ -3267,6 +3267,17 @@ $model = $dbi->create_model(
3267 3267
 $model->method(foo => sub { shift->select(@_) });
3268 3268
 is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
3269 3269
 
3270
+test 'model helper';
3271
+$dbi = DBIx::Custom->connect;
3272
+eval { $dbi->execute("drop table $table2") };
3273
+$dbi->execute($create_table2);
3274
+$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
3275
+$model = $dbi->create_model(
3276
+    table => $table2
3277
+);
3278
+$model->helper(foo => sub { shift->select(@_) });
3279
+is_deeply($model->foo->one, {$key1 => 1, $key3 => 3});
3280
+
3270 3281
 test 'assign_clause';
3271 3282
 $dbi = DBIx::Custom->connect;
3272 3283
 eval { $dbi->execute("drop table $table1") };