Showing 4 changed files with 36 additions and 34 deletions
+2
Changes
... ...
@@ -1,3 +1,5 @@
1
+0.1678
2
+    - DBIx::Custom::Model filter attribute can receive hash reference
1 3
 0.1677
2 4
     - improved table search in column and join clause
3 5
     - DEPRECATED table tag. use table option.
+32 -31
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1677';
3
+our $VERSION = '0.1678';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -350,9 +350,10 @@ sub create_model {
350 350
     $model->table($model_table) unless $model->table;
351 351
     
352 352
     # Apply filter
353
-    croak "$model_class filter must be array reference"
354
-      unless ref $model->filter eq 'ARRAY';
355
-    $self->apply_filter($model->table, @{$model->filter});
353
+    my $filter = ref $model->filter eq 'HASH'
354
+               ? [%{$model->filter}]
355
+               : $model->filter;
356
+    $self->apply_filter($model->table, @$filter);
356 357
     
357 358
     # Associate table with model
358 359
     croak "Table name is duplicated"
... ...
@@ -1693,13 +1694,13 @@ and C<PrintError> option is false by default.
1693 1694
         join => [
1694 1695
             'inner join company on book.comparny_id = company.id'
1695 1696
         ],
1696
-        filter => [
1697
+        filter => {
1697 1698
             publish_date => {
1698 1699
                 out => 'tp_to_date',
1699 1700
                 in => 'date_to_tp',
1700 1701
                 end => 'tp_to_displaydate'
1701 1702
             }
1702
-        ]
1703
+        }
1703 1704
     );
1704 1705
 
1705 1706
 Create L<DBIx::Custom::Model> object and initialize model.
... ...
@@ -1792,13 +1793,13 @@ filter name registerd by C<register_filter()>.
1792 1793
     # Basic
1793 1794
     $dbi->execute(
1794 1795
         $sql,
1795
-        filter => [
1796
+        filter => {
1796 1797
             title  => sub { uc $_[0] }
1797 1798
             author => sub { uc $_[0] }
1798
-        ]
1799
+        }
1799 1800
     );
1800 1801
     
1801
-    # At once
1802
+    # At once (use array reference)
1802 1803
     $dbi->execute(
1803 1804
         $sql,
1804 1805
         filter => [
... ...
@@ -1809,10 +1810,10 @@ filter name registerd by C<register_filter()>.
1809 1810
     # Filter name
1810 1811
     $dbi->execute(
1811 1812
         $sql,
1812
-        filter => [
1813
+        filter => {
1813 1814
             title  => 'upper_case',
1814 1815
             author => 'upper_case'
1815
-        ]
1816
+        }
1816 1817
     );
1817 1818
 
1818 1819
 These filters are added to the C<out> filters, set by C<apply_filter()>.
... ...
@@ -1872,13 +1873,13 @@ filter name registerd by C<register_filter()>.
1872 1873
 
1873 1874
     # Basic
1874 1875
     $dbi->delete(
1875
-        filter => [
1876
+        filter => {
1876 1877
             title  => sub { uc $_[0] }
1877 1878
             author => sub { uc $_[0] }
1878
-        ]
1879
+        }
1879 1880
     );
1880 1881
     
1881
-    # At once
1882
+    # At once (use array reference)
1882 1883
     $dbi->delete(
1883 1884
         filter => [
1884 1885
             [qw/title author/]  => sub { uc $_[0] }
... ...
@@ -1887,10 +1888,10 @@ filter name registerd by C<register_filter()>.
1887 1888
     
1888 1889
     # Filter name
1889 1890
     $dbi->delete(
1890
-        filter => [
1891
+        filter => {
1891 1892
             title  => 'upper_case',
1892 1893
             author => 'upper_case'
1893
-        ]
1894
+        }
1894 1895
     );
1895 1896
 
1896 1897
 These filters are added to the C<out> filters, set by C<apply_filter()>.
... ...
@@ -2010,13 +2011,13 @@ filter name registerd by C<register_filter()>.
2010 2011
 
2011 2012
     # Basic
2012 2013
     $dbi->insert(
2013
-        filter => [
2014
+        filter => {
2014 2015
             title  => sub { uc $_[0] }
2015 2016
             author => sub { uc $_[0] }
2016
-        ]
2017
+        }
2017 2018
     );
2018 2019
     
2019
-    # At once
2020
+    # At once (use array reference)
2020 2021
     $dbi->insert(
2021 2022
         filter => [
2022 2023
             [qw/title author/]  => sub { uc $_[0] }
... ...
@@ -2025,10 +2026,10 @@ filter name registerd by C<register_filter()>.
2025 2026
     
2026 2027
     # Filter name
2027 2028
     $dbi->insert(
2028
-        filter => [
2029
+        filter => {
2029 2030
             title  => 'upper_case',
2030 2031
             author => 'upper_case'
2031
-        ]
2032
+        }
2032 2033
     );
2033 2034
 
2034 2035
 These filters are added to the C<out> filters, set by C<apply_filter()>.
... ...
@@ -2390,13 +2391,13 @@ filter name registerd by C<register_filter()>.
2390 2391
 
2391 2392
     # Basic
2392 2393
     $dbi->select(
2393
-        filter => [
2394
+        filter => {
2394 2395
             title  => sub { uc $_[0] }
2395 2396
             author => sub { uc $_[0] }
2396
-        ]
2397
+        }
2397 2398
     );
2398 2399
     
2399
-    # At once
2400
+    # At once (use array reference)
2400 2401
     $dbi->select(
2401 2402
         filter => [
2402 2403
             [qw/title author/]  => sub { uc $_[0] }
... ...
@@ -2405,10 +2406,10 @@ filter name registerd by C<register_filter()>.
2405 2406
     
2406 2407
     # Filter name
2407 2408
     $dbi->select(
2408
-        filter => [
2409
+        filter => {
2409 2410
             title  => 'upper_case',
2410 2411
             author => 'upper_case'
2411
-        ]
2412
+        }
2412 2413
     );
2413 2414
 
2414 2415
 These filters are added to the C<out> filters, set by C<apply_filter()>.
... ...
@@ -2547,13 +2548,13 @@ filter name registerd by C<register_filter()>.
2547 2548
 
2548 2549
     # Basic
2549 2550
     $dbi->update(
2550
-        filter => [
2551
+        filter => {
2551 2552
             title  => sub { uc $_[0] }
2552 2553
             author => sub { uc $_[0] }
2553
-        ]
2554
+        }
2554 2555
     );
2555 2556
     
2556
-    # At once
2557
+    # At once (use array reference)
2557 2558
     $dbi->update(
2558 2559
         filter => [
2559 2560
             [qw/title author/]  => sub { uc $_[0] }
... ...
@@ -2562,10 +2563,10 @@ filter name registerd by C<register_filter()>.
2562 2563
     
2563 2564
     # Filter name
2564 2565
     $dbi->update(
2565
-        filter => [
2566
+        filter => {
2566 2567
             title  => 'upper_case',
2567 2568
             author => 'upper_case'
2568
-        ]
2569
+        }
2569 2570
     );
2570 2571
 
2571 2572
 These filters are added to the C<out> filters, set by C<apply_filter()>.
-1
lib/DBIx/Custom/Util.pm
... ...
@@ -8,7 +8,6 @@ sub array_to_hash {
8 8
     
9 9
     return $array if ref $array eq 'HASH';
10 10
     return unless $array;
11
-    return $array if ref $array eq 'HASH';
12 11
     
13 12
     my $hash = {};
14 13
     
+2 -2
t/dbix-custom-core-sqlite/MyModel8/table2.pm
... ...
@@ -3,9 +3,9 @@ package MyModel8::table2;
3 3
 use base 'MyModel8';
4 4
 
5 5
 __PACKAGE__->attr(filter => sub {
6
-    [
6
+    {
7 7
         key3 => {out => sub { $_[0] * 2}, in => sub { $_[0] * 3}, end => sub { $_[0] * 4 }}
8
-    ]
8
+    }
9 9
 });
10 10
 
11 11
 1;