Showing 7 changed files with 217 additions and 20 deletions
+14
Changes
... ...
@@ -1,3 +1,17 @@
1
+0.1699
2
+    - added EXPERIMENTAL order method
3
+    - added EXPERIMENTAL DBIx::Custom::Order module
4
+    - changed backword compatible policy
5
+      ------------------------------------------------------------------------
6
+      If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
7
+      except for attribute method.
8
+      You can check all DEPRECATED functionalities by document.
9
+      DEPRECATED functionality is removed after five years,
10
+      but if at least one person use the functionality and tell me that thing
11
+      I extend one year each time you tell me it.
12
+
13
+      EXPERIMENTAL functionality will be changed without warnings.
14
+      ------------------------------------------------------------------------
1 15
 0.1698
2 16
     - fixed DBIx::Custom::Where to_string method small bug
3 17
     - added EXPERIMENTAL execute method table_alias option
+101 -12
lib/DBIx/Custom.pm
... ...
@@ -12,6 +12,7 @@ use DBIx::Custom::QueryBuilder;
12 12
 use DBIx::Custom::Where;
13 13
 use DBIx::Custom::Model;
14 14
 use DBIx::Custom::Tag;
15
+use DBIx::Custom::Order;
15 16
 use DBIx::Custom::Util qw/_array_to_hash _subname/;
16 17
 use Encode qw/encode encode_utf8 decode_utf8/;
17 18
 
... ...
@@ -732,6 +733,11 @@ sub new {
732 733
 
733 734
 sub not_exists { bless {}, 'DBIx::Custom::NotExists' }
734 735
 
736
+sub order {
737
+    my $self = shift;
738
+    return DBIx::Custom::Order->new(@_);
739
+}
740
+
735 741
 sub register_filter {
736 742
     my $self = shift;
737 743
     
... ...
@@ -760,10 +766,10 @@ sub select {
760 766
     croak qq{"join" must be array reference } . _subname
761 767
       unless ref $join eq 'ARRAY';
762 768
     my $relation = delete $args{relation};
763
-    warn "select() relation option is DEPRECATED! use join option instead"
769
+    warn "select() relation option is DEPRECATED!"
764 770
       if $relation;
765 771
     my $param = delete $args{param} || {}; # DEPRECATED!
766
-    warn "select() param option is DEPRECATED! use where_param option instead"
772
+    warn "select() param option is DEPRECATED!"
767 773
       if keys %$param;
768 774
     my $where_param = delete $args{where_param} || $param || {};
769 775
     my $wrap = delete $args{wrap};
... ...
@@ -1244,7 +1250,7 @@ sub _connect {
1244 1250
     
1245 1251
     # Attributes
1246 1252
     my $dsn = $self->data_source;
1247
-    warn "data_source is DEPRECATED! use dsn instead\n"
1253
+    warn "data_source is DEPRECATED!\n"
1248 1254
       if $dsn;
1249 1255
     $dsn ||= $self->dsn;
1250 1256
     croak qq{"dsn" must be specified } . _subname
... ...
@@ -1420,7 +1426,6 @@ sub _where_to_obj {
1420 1426
     return $obj;
1421 1427
 }
1422 1428
 
1423
-# DEPRECATED!
1424 1429
 sub _apply_filter {
1425 1430
     my ($self, $table, @cinfos) = @_;
1426 1431
 
... ...
@@ -1500,10 +1505,7 @@ sub create_query {
1500 1505
 sub apply_filter {
1501 1506
     my $self = shift;
1502 1507
     
1503
-    warn "apply_filter is DEPRECATED! " . 
1504
-         "use type_rule method and DBIx::Custom::Result filter method, " .
1505
-         "instead";
1506
-    
1508
+    warn "apply_filter is DEPRECATED!";
1507 1509
     return $self->_apply_filter(@_);
1508 1510
 }
1509 1511
 
... ...
@@ -1740,7 +1742,7 @@ sub _add_relation_table {
1740 1742
 
1741 1743
 =head1 NAME
1742 1744
 
1743
-DBIx::Custom - Useful database access, respecting SQL!
1745
+DBIx::Custom - Execute insert, update, delete, and select statement easily
1744 1746
 
1745 1747
 =head1 SYNOPSYS
1746 1748
 
... ...
@@ -2503,6 +2505,12 @@ Create a new L<DBIx::Custom> object.
2503 2505
 DBIx::Custom::NotExists object, indicating the column is not exists.
2504 2506
 This is used by C<clause> of L<DBIx::Custom::Where> .
2505 2507
 
2508
+=head2 C<order> EXPERIMENTAL
2509
+
2510
+    my $order = $dbi->order;
2511
+
2512
+Create a new L<DBIx::Custom::Order> object.
2513
+
2506 2514
 =head2 C<register_filter>
2507 2515
 
2508 2516
     $dbi->register_filter(
... ...
@@ -2931,10 +2939,91 @@ executed SQL and bind values are printed to STDERR.
2931 2939
 
2932 2940
 DEBUG output encoding. Default to UTF-8.
2933 2941
 
2934
-=head1 STABILITY
2942
+=head1 DEPRECATED FUNCTIONALITIES
2943
+
2944
+L<DBIx::Custom>
2945
+
2946
+    # Attribute methods
2947
+    data_source # Removed at 2017/1/1
2948
+    dbi_options # Removed at 2017/1/1
2949
+    filter_check # Removed at 2017/1/1
2950
+    reserved_word_quote # Removed at 2017/1/1
2951
+    
2952
+    # Methods
2953
+    create_query # Removed at 2017/1/1
2954
+    apply_filter # Removed at 2017/1/1
2955
+    select_at # Removed at 2017/1/1
2956
+    delete_at # Removed at 2017/1/1
2957
+    update_at # Removed at 2017/1/1
2958
+    insert_at # Removed at 2017/1/1
2959
+    register_tag # Removed at 2017/1/1
2960
+    default_bind_filter # Removed at 2017/1/1
2961
+    default_fetch_filter # Removed at 2017/1/1
2962
+    insert_param_tag # Removed at 2017/1/1
2963
+    register_tag_processor # Removed at 2017/1/1
2964
+    update_param_tag # Removed at 2017/1/1
2965
+    
2966
+    # Options
2967
+    select method relation option # Removed at 2017/1/1
2968
+    select method param option # Removed at 2017/1/1
2969
+    
2970
+    # Others
2971
+    execute("select * from {= title}"); # execute tag parsing functionality
2972
+                                        # Removed at 2017/1/1
2973
+
2974
+L<DBIx::Custom::Model>
2975
+
2976
+    # Attribute method
2977
+    filter # Removed at 2017/1/1
2978
+    name # Removed at 2017/1/1
2979
+    type # Removed at 2017/1/1
2980
+
2981
+L<DBIx::Custom::Query>
2982
+    
2983
+    # Attribute method
2984
+    default_filter # Removed at 2017/1/1
2985
+
2986
+L<DBIx::Custom::QueryBuilder>
2987
+    
2988
+    # Attribute method
2989
+    tags # Removed at 2017/1/1
2990
+    tag_processors # Removed at 2017/1/1
2991
+    
2992
+    # Method
2993
+    register_tag # Removed at 2017/1/1
2994
+    register_tag_processor # Removed at 2017/1/1
2995
+    
2996
+    # Others
2997
+    build_query("select * from {= title}"); # tag parsing functionality
2998
+                                            # Removed at 2017/1/1
2999
+
3000
+L<DBIx::Custom::Result>
3001
+    
3002
+    # Attribute method
3003
+    filter_check # Removed at 2017/1/1
3004
+    
3005
+    # Methods
3006
+    end_filter # Removed at 2017/1/1
3007
+    remove_end_filter # Removed at 2017/1/1
3008
+    remove_filter # Removed at 2017/1/1
3009
+    default_filter # Removed at 2017/1/1
3010
+
3011
+L<DBIx::Custom::Tag>
3012
+
3013
+    This module is DEPRECATED! # Removed at 2017/1/1
3014
+
3015
+=head1 BACKWORD COMPATIBLE POLICY
3016
+
3017
+If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3018
+except for attribute method.
3019
+You can check all DEPRECATED functionalities by document.
3020
+DEPRECATED functionality is removed after five years,
3021
+but if at least one person use the functionality and tell me that thing
3022
+I extend one year each time you tell me it.
3023
+
3024
+EXPERIMENTAL functionality will be changed without warnings.
2935 3025
 
2936
-L<DBIx::Custom> is stable. APIs keep backword compatible
2937
-except EXPERIMENTAL one in the feature.
3026
+This policy is changed at 2011/6/28
2938 3027
 
2939 3028
 =head1 BUGS
2940 3029
 
+74
lib/DBIx/Custom/Order.pm
... ...
@@ -0,0 +1,74 @@
1
+package DBIx::Custom::Order;
2
+use Object::Simple -base;
3
+use overload
4
+  'bool'   => sub {1},
5
+  '""'     => sub { shift->to_string },
6
+  fallback => 1;
7
+
8
+has orders => sub { [] };
9
+
10
+sub prepend { unshift @{shift->orders}, @_ }
11
+
12
+sub to_string {
13
+    my $self = shift;
14
+    
15
+    my $exists = {};
16
+    my @orders;
17
+    foreach my $order (@{$self->orders}) {
18
+        next unless defined $order;
19
+        $order =~ s/^\s+//;
20
+        $order =~ s/\s+$//;
21
+        my ($column, $direction) = split /\s+/, $order;
22
+        push @orders, $order unless $exists->{$column};
23
+        $exists->{$column} = 1;
24
+    }
25
+    
26
+    return '' unless @orders;
27
+    return 'order by ' . join(', ', @orders);
28
+}
29
+
30
+1;
31
+
32
+=head1 NAME
33
+
34
+DBIx::Custom::Order - Order by EXPERIMENTAL
35
+
36
+=head1 SYNOPSIS
37
+
38
+    # Result
39
+    my $order = DBIx::Custom::Order->new;
40
+    $order->prepend('title', 'author desc');
41
+    my $order_by = "$order";
42
+    
43
+
44
+=head1 ATTRIBUTES
45
+
46
+=head2 C<orders>
47
+
48
+    my $orders = $result->orders;
49
+    $result = $result->orders(\%orders);
50
+
51
+Parts of order by clause
52
+
53
+=head1 METHODS
54
+
55
+L<DBIx::Custom::Result> inherits all methods from L<Object::Simple>
56
+and implements the following new ones.
57
+
58
+=head2 C<prepend>
59
+
60
+    $order->prepend('title', 'author desc');
61
+
62
+Prepend order parts to C<orders>.
63
+
64
+=head2 C<to_string>
65
+
66
+    my $order_by = $order->to_string;
67
+
68
+Create order by clause. If column name is duplicated, First one is used.
69
+C<to_string> override stringification. so you can write the follwoing way.
70
+
71
+    my $order_by = "$order";
72
+
73
+=cut
74
+
+1 -1
lib/DBIx/Custom/QueryBuilder.pm
... ...
@@ -284,7 +284,7 @@ has tag_processors => sub { {} };
284 284
 # DEPRECATED!
285 285
 sub register_tag_processor {
286 286
     my $self = shift;
287
-    warn "register_tag_processor is DEPRECATED! use register_tag instead";
287
+    warn "register_tag_processor is DEPRECATED!";
288 288
     # Merge tag
289 289
     my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
290 290
     $self->tag_processors({%{$self->tag_processors}, %{$tag_processors}});
+4 -7
lib/DBIx/Custom/Result.pm
... ...
@@ -284,6 +284,7 @@ sub type_rule2_on {
284 284
 
285 285
 # DEPRECATED!
286 286
 sub end_filter {
287
+    warn "end_filter method is DEPRECATED!";
287 288
     my $self = shift;
288 289
     if (@_) {
289 290
         my $end_filter = {};
... ...
@@ -309,27 +310,24 @@ sub end_filter {
309 310
     }
310 311
     return $self->{end_filter} ||= {};
311 312
 }
312
-
313 313
 # DEPRECATED!
314 314
 sub remove_end_filter {
315
+    warn "remove_end_filter is DEPRECATED!";
315 316
     my $self = shift;
316
-    warn "remove_end_filter is DEPRECATED! use filter_off attribute instead";
317 317
     $self->{end_filter} = {};
318 318
     return $self;
319 319
 }
320
-
321 320
 # DEPRECATED!
322 321
 sub remove_filter {
322
+    warn "remove_filter is DEPRECATED!";
323 323
     my $self = shift;
324
-    warn "remove_filter is DEPRECATED! use filter_off attribute instead";
325 324
     $self->{filter} = {};
326 325
     return $self;
327 326
 }
328
-
329 327
 # DEPRECATED!
330 328
 sub default_filter {
331
-    my $self = shift;
332 329
     warn "default_filter is DEPRECATED!";
330
+    my $self = shift;
333 331
     if (@_) {
334 332
         my $fname = $_[0];
335 333
         if (@_ && !$fname) {
... ...
@@ -344,7 +342,6 @@ sub default_filter {
344 342
     }
345 343
     return $self->{default_filter};
346 344
 }
347
-
348 345
 # DEPRECATED!
349 346
 has 'filter_check'; 
350 347
 
+21
t/dbix-custom-core-sqlite.t
... ...
@@ -3286,4 +3286,25 @@ $dbi->execute("insert into table1 (key1) values (:table2.key1)", {'table2.key1'
3286 3286
 $result = $dbi->select(table => 'table1');
3287 3287
 is($result->one->{key1}, 'A');
3288 3288
 
3289
+
3290
+test 'order';
3291
+$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3292
+{
3293
+    $dbi->execute("create table table1 (key1, key2)");
3294
+    $dbi->insert({key1 => 1, key2 => 1}, table => 'table1');
3295
+    $dbi->insert({key1 => 1, key2 => 3}, table => 'table1');
3296
+    $dbi->insert({key1 => 2, key2 => 2}, table => 'table1');
3297
+    $dbi->insert({key1 => 2, key2 => 4}, table => 'table1');
3298
+    my $order = $dbi->order;
3299
+    $order->prepend('key1', 'key2 desc');
3300
+    $result = $dbi->select(table => 'table1', append => "$order");
3301
+    is_deeply($result->all, [{key1 => 1, key2 => 3}, {key1 => 1, key2 => 1},
3302
+      {key1 => 2, key2 => 4}, {key1 => 2, key2 => 2}]);
3303
+    $order->prepend('key1 desc');
3304
+    $result = $dbi->select(table => 'table1', append => "$order");
3305
+    is_deeply($result->all, [{key1 => 2, key2 => 4}, {key1 => 2, key2 => 2},
3306
+      {key1 => 1, key2 => 3}, {key1 => 1, key2 => 1}]);
3307
+}
3308
+
3309
+
3289 3310
 =cut
+2
t/dbix-custom-result-sqlite.t
... ...
@@ -3,6 +3,8 @@ use strict;
3 3
 use warnings;
4 4
 use DBI;
5 5
 
6
+$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
7
+
6 8
 BEGIN {
7 9
     eval { require DBD::SQLite; 1 }
8 10
         or plan skip_all => 'DBD::SQLite required';