Showing 6 changed files with 342 additions and 207 deletions
+3 -1
Changes
... ...
@@ -1,3 +1,5 @@
1
+0.1660
2
+    - update pod
1 3
 0.1659
2 4
     - EXPERIMETAL fork safety implementaion.
3 5
     - removed EXPERIMENTAL selection
... ...
@@ -181,7 +183,7 @@
181 183
     - update document
182 184
     - renamed DBIx::Custom::QueryBuilder::TagProcessors functions(not backword compatible)
183 185
 0.1607
184
-    - where argument of select() method can specify array(string, paramters)
186
+    - where argument of select() method can specify array(string, parameters)
185 187
     - renamed build_query() to create_query()(not backword compatible)
186 188
 0.1606
187 189
     - fix testing bug
+331 -198
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1659';
3
+our $VERSION = '0.1660';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -22,43 +22,6 @@ use Encode qw/encode_utf8 decode_utf8/;
22 22
 __PACKAGE__->attr(
23 23
     [qw/data_source password pid user/],
24 24
     cache => 1,
25
-    dbi_option => sub { {} },
26
-    default_dbi_option => sub {{
27
-        RaiseError => 1,
28
-        PrintError => 0,
29
-        AutoCommit => 1
30
-    }},
31
-    models => sub { {} },
32
-    query_builder => sub { DBIx::Custom::QueryBuilder->new },
33
-    result_class  => 'DBIx::Custom::Result',
34
-    safety_character => '\w',
35
-    stash => sub { {} }
36
-);
37
-
38
-sub dbh {
39
-    my $self = shift;
40
-
41
-    if (@_) {
42
-        $self->{dbh} = $_[0];
43
-        return $self;
44
-    }
45
-    else {
46
-        my $pid = $$;
47
-        if ($self->pid eq $pid) {
48
-            return $self->{dbh};
49
-        }
50
-        else {
51
-            # Create new connection in child process
52
-            croak "Process is forked in transaction"
53
-              unless $self->{dbh}->{AutoCommit};
54
-            $self->pid($pid);
55
-            $self->{dbh}->{InactiveDestroy} = 1;
56
-            return $self->{dbh} = $self->_connect;
57
-        }
58
-    }
59
-}
60
-
61
-__PACKAGE__->attr(
62 25
     cache_method => sub {
63 26
         sub {
64 27
             my $self = shift;
... ...
@@ -66,22 +29,32 @@ __PACKAGE__->attr(
66 29
             $self->{_cached} ||= {};
67 30
             
68 31
             if (@_ > 1) {
69
-                $self->{_cached}{$_[0]} = $_[1] 
32
+                $self->{_cached}{$_[0]} = $_[1];
70 33
             }
71 34
             else {
72
-                return $self->{_cached}{$_[0]}
35
+                return $self->{_cached}{$_[0]};
73 36
             }
74 37
         }
75
-    }
76
-);
77
-
78
-__PACKAGE__->attr(
38
+    },
39
+    dbi_option => sub { {} },
40
+    default_dbi_option => sub {
41
+        {
42
+            RaiseError => 1,
43
+            PrintError => 0,
44
+            AutoCommit => 1
45
+        }
46
+    },
79 47
     filters => sub {
80 48
         {
81 49
             encode_utf8 => sub { encode_utf8($_[0]) },
82 50
             decode_utf8 => sub { decode_utf8($_[0]) }
83 51
         }
84
-    }
52
+    },
53
+    models => sub { {} },
54
+    query_builder => sub { DBIx::Custom::QueryBuilder->new },
55
+    result_class  => 'DBIx::Custom::Result',
56
+    safety_character => '\w',
57
+    stash => sub { {} }
85 58
 );
86 59
 
87 60
 our $AUTOLOAD;
... ...
@@ -241,6 +214,29 @@ sub create_query {
241 214
     return $query;
242 215
 }
243 216
 
217
+sub dbh {
218
+    my $self = shift;
219
+
220
+    if (@_) {
221
+        $self->{dbh} = $_[0];
222
+        return $self;
223
+    }
224
+    else {
225
+        my $pid = $$;
226
+        if ($self->pid eq $pid) {
227
+            return $self->{dbh};
228
+        }
229
+        else {
230
+            # Create new connection in child process
231
+            croak "Process is forked in transaction"
232
+              unless $self->{dbh}->{AutoCommit};
233
+            $self->pid($pid);
234
+            $self->{dbh}->{InactiveDestroy} = 1;
235
+            return $self->{dbh} = $self->_connect;
236
+        }
237
+    }
238
+}
239
+
244 240
 our %VALID_DELETE_ARGS
245 241
   = map { $_ => 1 } qw/table where append filter allow_delete_all query/;
246 242
 
... ...
@@ -307,8 +303,7 @@ sub delete {
307 303
 sub delete_all { shift->delete(allow_delete_all => 1, @_) }
308 304
 
309 305
 our %VALID_DELETE_AT_ARGS
310
-  = map { $_ => 1 } qw/table where append filter query
311
-                       primary_key param/;
306
+  = map { $_ => 1 } qw/table where append filter query primary_key param/;
312 307
 
313 308
 sub delete_at {
314 309
     my ($self, %args) = @_;
... ...
@@ -450,8 +445,9 @@ sub execute{
450 445
     return $affected;
451 446
 }
452 447
 
453
-our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append
454
-                                            filter query/;
448
+our %VALID_INSERT_ARGS
449
+  = map { $_ => 1 } qw/table param append filter query/;
450
+
455 451
 sub insert {
456 452
     my ($self, %args) = @_;
457 453
 
... ...
@@ -503,9 +499,8 @@ sub insert {
503 499
 }
504 500
 
505 501
 our %VALID_INSERT_AT_ARGS
506
-  = map { $_ => 1 } qw/table param
507
-                       where append filter query
508
-                       primary_key param/;
502
+  = map { $_ => 1 } qw/table param where append filter
503
+                       query primary_key param/;
509 504
 
510 505
 sub insert_at {
511 506
     my ($self, %args) = @_;
... ...
@@ -551,7 +546,7 @@ sub insert_at {
551 546
 sub insert_param {
552 547
     my ($self, $param) = @_;
553 548
     
554
-    # Insert paramter tag
549
+    # Insert parameter tag
555 550
     my @tag;
556 551
     push @tag, '{insert_param';
557 552
     my $safety = $self->safety_character;
... ...
@@ -921,8 +916,8 @@ sub setup_model {
921 916
 }
922 917
 
923 918
 our %VALID_UPDATE_ARGS
924
-  = map { $_ => 1 } qw/table param
925
-                       where append filter allow_update_all query/;
919
+  = map { $_ => 1 } qw/table param where append filter
920
+                       allow_update_all query/;
926 921
 
927 922
 sub update {
928 923
     my ($self, %args) = @_;
... ...
@@ -1019,9 +1014,8 @@ sub update {
1019 1014
 sub update_all { shift->update(allow_update_all => 1, @_) };
1020 1015
 
1021 1016
 our %VALID_UPDATE_AT_ARGS
1022
-  = map { $_ => 1 } qw/table param
1023
-                       where append filter query
1024
-                       primary_key param/;
1017
+  = map { $_ => 1 } qw/table param where append filter
1018
+                       query primary_key param/;
1025 1019
 
1026 1020
 sub update_at {
1027 1021
     my ($self, %args) = @_;
... ...
@@ -1490,10 +1484,8 @@ default to the following values.
1490 1484
         AutoCommit => 1,
1491 1485
     }
1492 1486
 
1493
-You should not change C<AutoCommit> value directly
1494
-to check if the process is in transaction.
1495
-L<DBIx::Custom> determin the process is in transaction
1496
-if AutoCommit is 0. 
1487
+You should not change C<AutoCommit> value directly,
1488
+the value is used to check if the process is in transaction.
1497 1489
 
1498 1490
 =head2 C<filters>
1499 1491
 
... ...
@@ -1502,7 +1494,7 @@ if AutoCommit is 0.
1502 1494
 
1503 1495
 Filters, registered by C<register_filter()>.
1504 1496
 
1505
-=head2 C<models EXPERIMENTAL>
1497
+=head2 C<models> EXPERIMENTAL
1506 1498
 
1507 1499
     my $models = $dbi->models;
1508 1500
     $dbi       = $dbi->models(\%models);
... ...
@@ -1530,12 +1522,12 @@ Query builder, default to L<DBIx::Custom::QueryBuilder> object.
1530 1522
 
1531 1523
 Result class, default to L<DBIx::Custom::Result>.
1532 1524
 
1533
-=head2 C<safety_character EXPERIMENTAL>
1525
+=head2 C<safety_character> EXPERIMENTAL
1534 1526
 
1535 1527
     my $safety_character = $self->safety_character;
1536 1528
     $dbi                 = $self->safety_character($character);
1537 1529
 
1538
-Regex of safety character consist of table and column name, default to '\w'.
1530
+Regex of safety character for table and column name, default to '\w'.
1539 1531
 Note that you don't have to specify like '[\w]'.
1540 1532
 
1541 1533
 =head2 C<user>
... ...
@@ -1551,53 +1543,95 @@ L<DBIx::Custom> inherits all methods from L<Object::Simple>
1551 1543
 and use all methods of L<DBI>
1552 1544
 and implements the following new ones.
1553 1545
 
1554
-=head2 C<apply_filter EXPERIMENTAL>
1546
+=head2 C<apply_filter> EXPERIMENTAL
1555 1547
 
1556 1548
     $dbi->apply_filter(
1557 1549
         'book',
1558
-        $column1 => {out => $outfilter1, in => $infilter1, end => $endfilter1}
1559
-        $column2 => {out => $outfilter2, in => $infilter2, end => $endfilter2}
1560
-        ...,
1550
+        'issue_date' => {
1551
+            out => 'tp_to_date',
1552
+            in  => 'date_to_tp',
1553
+            end => 'tp_to_displaydate'
1554
+        },
1555
+        'write_date' => {
1556
+            out => 'tp_to_date',
1557
+            in  => 'date_to_tp',
1558
+            end => 'tp_to_displaydate'
1559
+        }
1561 1560
     );
1562 1561
 
1563
-Apply filter to specified column, C<out> is the direction from perl to database,
1564
-C<in> is the direction from database to perl,
1565
-C<end> is filter after C<in> filter.
1562
+Apply filter to columns.
1563
+C<out> filter is executed before data is send to database.
1564
+C<in> filter is executed after a row is fetch.
1565
+C<end> filter is execute after C<in> filter is executed.
1566
+
1567
+Filter is applied to the follwoing tree column name pattern.
1566 1568
 
1567
-You can use three column name to apply filter to column data.
1569
+       PETTERN         EXAMPLE
1570
+    1. Column        : author
1571
+    2. Table.Column  : book.author
1572
+    3. Table__Column : book__author
1568 1573
 
1569
-                       (Example)
1570
-    1. column        : author
1571
-    2. table.column  : book.author
1572
-    3. table__column : book__author
1574
+If column name is duplicate with other table,
1575
+Main filter specified by C<table> option is used.
1576
+
1577
+You can set multiple filters at once.
1578
+
1579
+    $dbi->apply_filter(
1580
+        'book',
1581
+        [qw/issue_date write_date/] => {
1582
+            out => 'tp_to_date',
1583
+            in  => 'date_to_tp',
1584
+            end => 'tp_to_displaydate'
1585
+        }
1586
+    );
1573 1587
 
1574 1588
 =head2 C<cache_method>
1575 1589
 
1576 1590
     $dbi          = $dbi->cache_method(\&cache_method);
1577 1591
     $cache_method = $dbi->cache_method
1578 1592
 
1579
-Method to set and get caches.
1593
+Method to set and get cache.
1594
+Default to the following one.
1595
+
1596
+    sub {
1597
+        my $self = shift;
1598
+        
1599
+        $self->{_cached} ||= {};
1600
+        
1601
+        if (@_ > 1) {
1602
+            $self->{_cached}{$_[0]} = $_[1];
1603
+        }
1604
+        else {
1605
+            return $self->{_cached}{$_[0]};
1606
+        }
1607
+    }
1580 1608
 
1581 1609
 =head2 C<connect>
1582 1610
 
1583
-    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
1584
-                                    user => 'ken', password => '!LFKD%$&');
1611
+    my $dbi = DBIx::Custom->connect(
1612
+        data_source => "dbi:mysql:database=dbname",
1613
+        user => 'ken',
1614
+        password => '!LFKD%$&',
1615
+        dbi_option => {mysql_enable_utf8 => 1}
1616
+    );
1617
+
1618
+Connect to the database and create a new L<DBIx::Custom> object.
1585 1619
 
1586
-Create a new L<DBIx::Custom> object and connect to the database.
1587 1620
 L<DBIx::Custom> is a wrapper of L<DBI>.
1588 1621
 C<AutoCommit> and C<RaiseError> options are true, 
1589
-and C<PrintError> option is false by default. 
1622
+and C<PrintError> option is false by default.
1590 1623
 
1591 1624
 =head2 C<create_query>
1592 1625
     
1593 1626
     my $query = $dbi->create_query(
1594
-        "select * from book where {= author} and {like title};"
1627
+        "insert into book {insert_param title author};";
1595 1628
     );
1596 1629
 
1597
-Create the instance of L<DBIx::Custom::Query> from the source of SQL.
1630
+Create L<DBIx::Custom::Query> object.
1631
+
1598 1632
 If you want to get high performance,
1599
-use C<create_query()> method and execute it by C<execute()> method
1600
-instead of suger methods.
1633
+create L<DBIx::Custom::Query> object and execute the query by C<execute()>
1634
+instead of other methods, such as C<insert>, C<update>.
1601 1635
 
1602 1636
     $dbi->execute($query, {author => 'Ken', title => '%Perl%'});
1603 1637
 
... ...
@@ -1608,18 +1642,66 @@ instead of suger methods.
1608 1642
 
1609 1643
 Get and set database handle of L<DBI>.
1610 1644
 
1611
-If process is changed by forking, new connection is created
1612
-and get new database hande ofL<DBI>. This feature is EXPERIMETNAL.
1645
+If process is spawn by forking, new connection is created automatically.
1646
+This feature is EXPERIMETNAL.
1613 1647
 
1614 1648
 =head2 C<execute>
1615 1649
 
1616
-    my $result = $dbi->execute($query,  param => $params, filter => \@filter);
1617
-    my $result = $dbi->execute($source, param => $params, filter => \@filter);
1650
+    my $result = $dbi->execute(
1651
+        "select * from book where {= title} and {like author}",
1652
+        param => {title => 'Perl', author => '%Ken%'}
1653
+    );
1654
+
1655
+Execute SQL, containing tags.
1656
+Return value is L<DBIx::Custom::Result> in select statement, or
1657
+the count of affected rows in insert, update, delete statement.
1658
+
1659
+Tag is turned into the statement containing place holder
1660
+before SQL is executed.
1661
+
1662
+    select * from where title = ? and author like ?;
1663
+
1664
+See also L<Tags/Tags>.
1665
+
1666
+The following opitons are currently available.
1667
+
1668
+=over 4
1669
+
1670
+=item C<filter>
1671
+
1672
+Filter, executed before data is send to database. This is array reference.
1673
+Filter value is code reference or
1674
+filter name registerd by C<register_filter()>.
1675
+
1676
+    # Basic
1677
+    $dbi->execute(
1678
+        $sql,
1679
+        filter => [
1680
+            title  => sub { uc $_[0] }
1681
+            author => sub { uc $_[0] }
1682
+        ]
1683
+    );
1684
+    
1685
+    # At once
1686
+    $dbi->execute(
1687
+        $sql,
1688
+        filter => [
1689
+            [qw/title author/]  => sub { uc $_[0] }
1690
+        ]
1691
+    );
1692
+    
1693
+    # Filter name
1694
+    $dbi->execute(
1695
+        $sql,
1696
+        filter => [
1697
+            title  => 'upper_case',
1698
+            author => 'upper_case'
1699
+        ]
1700
+    );
1701
+
1702
+These filters are added to the C<out> filters, set by C<apply_filter()>.
1618 1703
 
1619
-Execute query or the source of SQL.
1620
-Query is L<DBIx::Custom::Query> object.
1621
-Return value is L<DBIx::Custom::Result> if select statement is executed,
1622
-or the count of affected rows if insert, update, delete statement is executed.
1704
+=back
1623 1705
 
1624 1706
 =head2 C<delete>
1625 1707
 
... ...
@@ -1629,6 +1711,8 @@ Delete statement.
1629 1711
 
1630 1712
 The following opitons are currently available.
1631 1713
 
1714
+=over 4
1715
+
1632 1716
 =item C<table>
1633 1717
 
1634 1718
 Table name.
... ...
@@ -1686,7 +1770,7 @@ filter name registerd by C<register_filter()>.
1686 1770
 
1687 1771
 These filters are added to the C<out> filters, set by C<apply_filter()>.
1688 1772
 
1689
-=item C<query EXPERIMENTAL>
1773
+=item C<query> EXPERIMENTAL
1690 1774
 
1691 1775
 Get L<DBIx::Custom::Query> object instead of executing SQL.
1692 1776
 This is true or false value.
... ...
@@ -1697,6 +1781,8 @@ You can check SQL.
1697 1781
 
1698 1782
     my $sql = $query->sql;
1699 1783
 
1784
+=back
1785
+
1700 1786
 =head2 C<delete_all>
1701 1787
 
1702 1788
     $dbi->delete_all(table => $table);
... ...
@@ -1704,7 +1790,7 @@ You can check SQL.
1704 1790
 Delete statement to delete all rows.
1705 1791
 Options is same as C<delete()>.
1706 1792
 
1707
-=head2 C<delete_at() EXPERIMENTAL>
1793
+=head2 C<delete_at()> EXPERIMENTAL
1708 1794
 
1709 1795
 Delete statement, using primary key.
1710 1796
 
... ...
@@ -1718,7 +1804,9 @@ This method is same as C<delete()> exept that
1718 1804
 C<primary_key> is specified and C<where> is constant value or array refrence.
1719 1805
 all option of C<delete()> is available.
1720 1806
 
1721
-=head2 C<primary_key>
1807
+=over 4
1808
+
1809
+=item C<primary_key>
1722 1810
 
1723 1811
 Primary key. This is constant value or array reference.
1724 1812
     
... ...
@@ -1730,7 +1818,7 @@ Primary key. This is constant value or array reference.
1730 1818
 
1731 1819
 This is used to create where clause.
1732 1820
 
1733
-=head2 C<where>
1821
+=item C<where>
1734 1822
 
1735 1823
 Where clause, created from primary key information.
1736 1824
 This is constant value or array reference.
... ...
@@ -1747,6 +1835,8 @@ In first examle, the following SQL is created.
1747 1835
 
1748 1836
 Place holder is set to 5.
1749 1837
 
1838
+=back
1839
+
1750 1840
 =head2 C<insert>
1751 1841
 
1752 1842
     $dbi->insert(
... ...
@@ -1758,6 +1848,8 @@ Insert statement.
1758 1848
 
1759 1849
 The following opitons are currently available.
1760 1850
 
1851
+=over 4
1852
+
1761 1853
 =item C<table>
1762 1854
 
1763 1855
 Table name.
... ...
@@ -1766,8 +1858,6 @@ Table name.
1766 1858
 
1767 1859
 =item C<param>
1768 1860
 
1769
-=item C<param>
1770
-
1771 1861
 Insert data. This is hash reference.
1772 1862
 
1773 1863
     $dbi->insert(param => {title => 'Perl'});
... ...
@@ -1809,7 +1899,7 @@ filter name registerd by C<register_filter()>.
1809 1899
 
1810 1900
 These filters are added to the C<out> filters, set by C<apply_filter()>.
1811 1901
 
1812
-=item C<query EXPERIMENTAL>
1902
+=item C<query> EXPERIMENTAL
1813 1903
 
1814 1904
 Get L<DBIx::Custom::Query> object instead of executing SQL.
1815 1905
 This is true or false value.
... ...
@@ -1820,7 +1910,9 @@ You can check SQL.
1820 1910
 
1821 1911
     my $sql = $query->sql;
1822 1912
 
1823
-=head2 C<insert_at() EXPERIMENTAL>
1913
+=back
1914
+
1915
+=head2 C<insert_at()> EXPERIMENTAL
1824 1916
 
1825 1917
 Insert statement, using primary key.
1826 1918
 
... ...
@@ -1835,7 +1927,9 @@ This method is same as C<insert()> exept that
1835 1927
 C<primary_key> is specified and C<where> is constant value or array refrence.
1836 1928
 all option of C<insert()> is available.
1837 1929
 
1838
-=head2 C<primary_key>
1930
+=over 4
1931
+
1932
+=item C<primary_key>
1839 1933
 
1840 1934
 Primary key. This is constant value or array reference.
1841 1935
     
... ...
@@ -1847,7 +1941,7 @@ Primary key. This is constant value or array reference.
1847 1941
 
1848 1942
 This is used to create parts of insert data.
1849 1943
 
1850
-=head2 C<where>
1944
+=item C<where>
1851 1945
 
1852 1946
 Parts of Insert data, create from primary key information.
1853 1947
 This is constant value or array reference.
... ...
@@ -1864,19 +1958,21 @@ In first examle, the following SQL is created.
1864 1958
 
1865 1959
 Place holders are set to 5 and 'Perl'.
1866 1960
 
1867
-=head2 C<insert_param EXPERIMENTAL>
1961
+=back
1962
+
1963
+=head2 C<insert_param> EXPERIMENTAL
1868 1964
 
1869 1965
     my $insert_param = $dbi->insert_param({title => 'a', age => 2});
1870 1966
 
1871 1967
 Create insert parameter tag.
1872 1968
 
1873
-    {title => 'a', age => 2}   ->   {insert_param title age}
1969
+    {insert_param title age}
1874 1970
 
1875
-=head2 C<each_column EXPERIMENTAL>
1971
+=head2 C<each_column> EXPERIMENTAL
1876 1972
 
1877 1973
     $dbi->each_column(
1878 1974
         sub {
1879
-            my ($self, $table, $column, $column_info) = @_;
1975
+            my ($dbi, $table, $column, $column_info) = @_;
1880 1976
             
1881 1977
             my $type = $column_info->{TYPE_NAME};
1882 1978
             
... ...
@@ -1885,125 +1981,161 @@ Create insert parameter tag.
1885 1981
             }
1886 1982
         }
1887 1983
     );
1888
-Get column informations from database.
1889
-Argument is callback.
1890
-You can do anything in callback.
1984
+
1985
+Iterate all column informations of all table from database.
1986
+Argument is callback when one column is found.
1891 1987
 Callback receive four arguments, dbi object, table name,
1892 1988
 column name and column information.
1893 1989
 
1894
-=head2 C<include_model EXPERIMENTAL>
1990
+=head2 C<include_model> EXPERIMENTAL
1895 1991
 
1896
-    $dbi->include_model(
1897
-        'MyModel' => [
1898
-            'book', 'person', 'company'
1899
-        ]
1900
-    );
1992
+    $dbi->include_model('MyModel');
1901 1993
 
1902
-Include models. First argument is name space.
1903
-Second argument is array reference of class base names.
1994
+Include models from specified namespace,
1995
+the following layout is needed to include models.
1904 1996
 
1905
-If you don't specify second argument, All models under name space is
1906
-included.
1997
+    lib / MyModel.pm
1998
+        / MyModel / book.pm
1999
+                  / company.pm
1907 2000
 
1908
-    $dbi->include_model('MyModel');
2001
+Name space module, extending L<DBIx::Custom::Model>.
1909 2002
 
1910
-Note that in this case name spece module is needed.
2003
+B<MyModel.pm>
1911 2004
 
1912
-    # MyModel.pm
1913 2005
     package MyModel;
1914 2006
     
1915 2007
     use base 'DBIx::Custom::Model';
2008
+    
2009
+    1;
1916 2010
 
1917
-The following model is instantiated and included.
2011
+Model modules, extending name space module.
1918 2012
 
1919
-    MyModel::book
1920
-    MyModel::person
1921
-    MyModel::company
2013
+B<MyModel/book.pm>
1922 2014
 
1923
-You can get these instance by C<model()>.
2015
+    package MyModel::book;
2016
+    
2017
+    use base 'MyModel';
2018
+    
2019
+    1;
1924 2020
 
1925
-    my $book_model = $dbi->model('book');
2021
+B<MyModel/company.pm>
1926 2022
 
1927
-If you want to other name as model class,
1928
-you can do like this.
2023
+    package MyModel::company;
2024
+    
2025
+    use base 'MyModel';
2026
+    
2027
+    1;
2028
+    
2029
+MyModel::book and MyModel::company is included by C<include_model()>.
1929 2030
 
1930
-    $dbi->include_model(
1931
-        'MyModel' => [
1932
-            {'book' => 'Book'},
1933
-            {'person' => 'Person'}
1934
-        ]
1935
-    );
2031
+You can get model object by C<model()>.
2032
+
2033
+    my $book_model    = $dbi->model('book');
2034
+    my $company_model = $dbi->model('company');
1936 2035
 
1937
-=head2 C<method EXPERIMENTAL>
2036
+See L<DBIx::Custom::Model> to know model features.
2037
+
2038
+=head2 C<method> EXPERIMENTAL
1938 2039
 
1939 2040
     $dbi->method(
1940 2041
         update_or_insert => sub {
1941 2042
             my $self = shift;
1942
-            # do something
2043
+            
2044
+            # Process
1943 2045
         },
1944 2046
         find_or_create   => sub {
1945 2047
             my $self = shift;
1946
-            # do something
2048
+            
2049
+            # Process
1947 2050
         }
1948 2051
     );
1949 2052
 
1950
-Register method. These method is called from L<DBIx::Custom> object directory.
2053
+Register method. These method is called directly from L<DBIx::Custom> object.
1951 2054
 
1952 2055
     $dbi->update_or_insert;
1953 2056
     $dbi->find_or_create;
1954 2057
 
2058
+=head2 C<model> EXPERIMENTAL
2059
+
2060
+    $dbi->model('book')->method(
2061
+        insert => sub { ... },
2062
+        update => sub { ... }
2063
+    );
2064
+    
2065
+    my $model = $dbi->model('book');
2066
+
2067
+Set and get a L<DBIx::Custom::Model> object,
2068
+
1955 2069
 =head2 C<new>
1956 2070
 
1957
-    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
1958
-                                    user => 'ken', password => '!LFKD%$&');
2071
+    my $dbi = DBIx::Custom->new(
2072
+        data_source => "dbi:mysql:database=dbname",
2073
+        user => 'ken',
2074
+        password => '!LFKD%$&',
2075
+        dbi_option => {mysql_enable_utf8 => 1}
2076
+    );
1959 2077
 
1960 2078
 Create a new L<DBIx::Custom> object.
1961 2079
 
1962
-=head2 C<not_exists EXPERIMENTAL>
2080
+=head2 C<not_exists> EXPERIMENTAL
1963 2081
 
1964 2082
     my $not_exists = $dbi->not_exists;
1965 2083
 
1966
-Get DBIx::Custom::NotExists object.
2084
+DBIx::Custom::NotExists object, indicating the column is not exists.
2085
+This is used by C<clause> of L<DBIx::Custom::Where> .
1967 2086
 
1968 2087
 =head2 C<register_filter>
1969 2088
 
1970
-    $dbi->register_filter(%filters);
1971
-    $dbi->register_filter(\%filters);
2089
+    $dbi->register_filter(
2090
+        # Time::Piece object to database DATE format
2091
+        tp_to_date => sub {
2092
+            my $tp = shift;
2093
+            return $tp->strftime('%Y-%m-%d');
2094
+        },
2095
+        # database DATE format to Time::Piece object
2096
+        date_to_tp => sub {
2097
+           my $date = shift;
2098
+           return Time::Piece->strptime($date, '%Y-%m-%d');
2099
+        }
2100
+    );
1972 2101
     
1973
-Register filter. Registered filters is available in the following attributes
1974
-or arguments.
1975
-
1976
-=over 4
2102
+Register filters, used by C<filter> option of many methods.
1977 2103
 
1978
-=item *
1979
-
1980
-C<filter> argument of C<insert()>, C<update()>,
1981
-C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1982
-methods
2104
+=head2 C<register_tag>
1983 2105
 
1984
-=item *
2106
+    $dbi->register_tag(
2107
+        update => sub {
2108
+            my @columns = @_;
2109
+            
2110
+            # Update parameters
2111
+            my $s = 'set ';
2112
+            $s .= "$_ = ?, " for @columns;
2113
+            $s =~ s/, $//;
2114
+            
2115
+            return [$s, \@columns];
2116
+        }
2117
+    );
1985 2118
 
1986
-C<execute()> method
2119
+Register tag, used by C<execute()>.
1987 2120
 
1988
-=item *
2121
+See also L<Tags/Tags> about tag registered by default.
1989 2122
 
1990
-C<default_filter> and C<filter> of C<DBIx::Custom::Query>
2123
+Tag parser receive arguments specified in tag.
2124
+In the following tag, 'title' and 'author' is parser arguments
1991 2125
 
1992
-=item *
2126
+    {update_param title author} 
1993 2127
 
1994
-C<default_filter> and C<filter> of C<DBIx::Custom::Result>
2128
+Tag parser must return array refrence,
2129
+first element is the result statement, 
2130
+second element is column names corresponding to place holders.
1995 2131
 
1996
-=back
2132
+In this example, result statement is 
1997 2133
 
1998
-=head2 C<register_tag>
2134
+    set title = ?, author = ?
1999 2135
 
2000
-    $dbi->register_tag(
2001
-        limit => sub {
2002
-            ...;
2003
-        }
2004
-    );
2136
+Column names is
2005 2137
 
2006
-Register tag.
2138
+    ['title', 'author']
2007 2139
 
2008 2140
 =head2 C<select>
2009 2141
 
... ...
@@ -2040,7 +2172,7 @@ Default is '*' unless C<column> is specified.
2040 2172
     # Default
2041 2173
     $dbi->select(column => '*');
2042 2174
 
2043
-=item C<all_column EXPERIMENTAL>
2175
+=item C<all_column> EXPERIMENTAL
2044 2176
 
2045 2177
 Colum clause, contains all columns of joined table. This is true or false value
2046 2178
 
... ...
@@ -2077,7 +2209,7 @@ Where clause. This is hash reference or L<DBIx::Custom::Where> object.
2077 2209
     );
2078 2210
     $dbi->select(where => $where);
2079 2211
 
2080
-=item C<join EXPERIMENTAL>
2212
+=item C<join> EXPERIMENTAL
2081 2213
 
2082 2214
 Join clause used in need. This is array reference.
2083 2215
 
... ...
@@ -2145,7 +2277,7 @@ filter name registerd by C<register_filter()>.
2145 2277
 
2146 2278
 These filters are added to the C<out> filters, set by C<apply_filter()>.
2147 2279
 
2148
-=item C<query EXPERIMENTAL>
2280
+=item C<query> EXPERIMENTAL
2149 2281
 
2150 2282
 Get L<DBIx::Custom::Query> object instead of executing SQL.
2151 2283
 This is true or false value.
... ...
@@ -2158,7 +2290,7 @@ You can check SQL.
2158 2290
 
2159 2291
 =back
2160 2292
 
2161
-=head2 C<select_at() EXPERIMENTAL>
2293
+=head2 C<select_at()> EXPERIMENTAL
2162 2294
 
2163 2295
 Select statement, using primary key.
2164 2296
 
... ...
@@ -2172,7 +2304,9 @@ This method is same as C<select()> exept that
2172 2304
 C<primary_key> is specified and C<where> is constant value or array refrence.
2173 2305
 all option of C<select()> is available.
2174 2306
 
2175
-=head2 C<primary_key>
2307
+=over 4
2308
+
2309
+=item C<primary_key>
2176 2310
 
2177 2311
 Primary key. This is constant value or array reference.
2178 2312
     
... ...
@@ -2184,7 +2318,7 @@ Primary key. This is constant value or array reference.
2184 2318
 
2185 2319
 This is used to create where clause.
2186 2320
 
2187
-=head2 C<where>
2321
+=item C<where>
2188 2322
 
2189 2323
 Where clause, created from primary key information.
2190 2324
 This is constant value or array reference.
... ...
@@ -2201,6 +2335,8 @@ In first examle, the following SQL is created.
2201 2335
 
2202 2336
 Place holder is set to 5.
2203 2337
 
2338
+=back
2339
+
2204 2340
 =head2 C<update>
2205 2341
 
2206 2342
     $dbi->update(
... ...
@@ -2215,6 +2351,8 @@ The following opitons are currently available.
2215 2351
 
2216 2352
 =over 4
2217 2353
 
2354
+=item C<table>
2355
+
2218 2356
 Table name.
2219 2357
 
2220 2358
     $dbi->update(table => 'book');
... ...
@@ -2276,18 +2414,7 @@ filter name registerd by C<register_filter()>.
2276 2414
 
2277 2415
 These filters are added to the C<out> filters, set by C<apply_filter()>.
2278 2416
 
2279
-=head2 C<model EXPERIMENTAL>
2280
-
2281
-    $dbi->model('book')->method(
2282
-        insert => sub { ... },
2283
-        update => sub { ... }
2284
-    );
2285
-    
2286
-    my $model = $dbi->model('book');
2287
-
2288
-Set and get a L<DBIx::Custom::Model> object,
2289
-
2290
-=item C<query EXPERIMENTAL>
2417
+=item C<query> EXPERIMENTAL
2291 2418
 
2292 2419
 Get L<DBIx::Custom::Query> object instead of executing SQL.
2293 2420
 This is true or false value.
... ...
@@ -2298,6 +2425,8 @@ You can check SQL.
2298 2425
 
2299 2426
     my $sql = $query->sql;
2300 2427
 
2428
+=back
2429
+
2301 2430
 =head2 C<update_all>
2302 2431
 
2303 2432
     $dbi->update_all(table => 'book', param => {title => 'Perl'});
... ...
@@ -2305,7 +2434,7 @@ You can check SQL.
2305 2434
 Update statement to update all rows.
2306 2435
 Options is same as C<update()>.
2307 2436
 
2308
-=head2 C<update_at() EXPERIMENTAL>
2437
+=head2 C<update_at()> EXPERIMENTAL
2309 2438
 
2310 2439
 Update statement, using primary key.
2311 2440
 
... ...
@@ -2320,7 +2449,9 @@ This method is same as C<update()> exept that
2320 2449
 C<primary_key> is specified and C<where> is constant value or array refrence.
2321 2450
 all option of C<update()> is available.
2322 2451
 
2323
-=head2 C<primary_key>
2452
+=over 4
2453
+
2454
+=item C<primary_key>
2324 2455
 
2325 2456
 Primary key. This is constant value or array reference.
2326 2457
     
... ...
@@ -2332,7 +2463,7 @@ Primary key. This is constant value or array reference.
2332 2463
 
2333 2464
 This is used to create where clause.
2334 2465
 
2335
-=head2 C<where>
2466
+=item C<where>
2336 2467
 
2337 2468
 Where clause, created from primary key information.
2338 2469
 This is constant value or array reference.
... ...
@@ -2349,7 +2480,9 @@ In first examle, the following SQL is created.
2349 2480
 
2350 2481
 Place holders are set to 'Perl' and 5.
2351 2482
 
2352
-=head2 C<update_param EXPERIMENTAL>
2483
+=back
2484
+
2485
+=head2 C<update_param> EXPERIMENTAL
2353 2486
 
2354 2487
     my $update_param = $dbi->update_param({title => 'a', age => 2});
2355 2488
 
... ...
@@ -2357,7 +2490,7 @@ Create update parameter tag.
2357 2490
 
2358 2491
     {update_param title age}
2359 2492
 
2360
-=head2 C<where EXPERIMENTAL>
2493
+=head2 C<where> EXPERIMENTAL
2361 2494
 
2362 2495
     my $where = $dbi->where(
2363 2496
         clause => ['and', '{= title}', '{= author}'],
... ...
@@ -2366,24 +2499,24 @@ Create update parameter tag.
2366 2499
 
2367 2500
 Create a new L<DBIx::Custom::Where> object.
2368 2501
 
2369
-=head2 C<setup_model EXPERIMENTAL>
2502
+=head2 C<setup_model> EXPERIMENTAL
2370 2503
 
2371 2504
     $dbi->setup_model;
2372 2505
 
2373 2506
 Setup all model objects.
2374
-C<columns> and C<primary_key> is automatically set.
2507
+C<columns> of model object is automatically set, parsing database information.
2375 2508
 
2376 2509
 =head1 Tags
2377 2510
 
2378 2511
 The following tags is available.
2379 2512
 
2380
-=head2 C<table EXPERIMENTAL>
2513
+=head2 C<table> EXPERIMENTAL
2381 2514
 
2382 2515
 Table tag
2383 2516
 
2384 2517
     {table TABLE}    ->    TABLE
2385 2518
 
2386
-This is used to teach what is applied table to C<execute()>.
2519
+This is used to tell C<execute()> what table is needed .
2387 2520
 
2388 2521
 =head2 C<?>
2389 2522
 
+2 -2
lib/DBIx/Custom/Model.pm
... ...
@@ -161,7 +161,7 @@ sub update_at {
161 161
 
162 162
 =head1 NAME
163 163
 
164
-DBIx::Custom::Model - Model (experimental)
164
+DBIx::Custom::Model - Model EXPERIMENTAL
165 165
 
166 166
 =head1 SYNOPSIS
167 167
 
... ...
@@ -197,7 +197,7 @@ This filter is applied when L<DBIx::Custom> C<include_model()> is called.
197 197
 
198 198
 Model name.
199 199
 
200
-=head2 C<(experimental) join>
200
+=head2 C<join>
201 201
 
202 202
     my $join = $model->join;
203 203
     $model   = $model->join(
+4 -4
lib/DBIx/Custom/Result.pm
... ...
@@ -372,7 +372,7 @@ Statement handle of L<DBI>.
372 372
 L<DBIx::Custom::Result> inherits all methods from L<Object::Simple>
373 373
 and implements the following new ones.
374 374
 
375
-=head2 C<(experimental) end_filter>
375
+=head2 C<end_filter> EXPERIMENTAL
376 376
 
377 377
     $result = $result->end_filter(title  => 'to_something',
378 378
                                      author => 'to_something');
... ...
@@ -444,19 +444,19 @@ Filters.
444 444
 These each filters override the filters applied by C<apply_filter> of
445 445
 L<DBIx::Custom>.
446 446
 
447
-=head2 C<(experimental) remove_end_filter>
447
+=head2 C<remove_end_filter> EXPERIMENTAL
448 448
 
449 449
     $result->remove_end_filter;
450 450
 
451 451
 Remove end filter.
452 452
 
453
-=head2 C<(experimental) remove_filter>
453
+=head2 C<remove_filter> EXPERIMENTAL
454 454
 
455 455
     $result->remove_filter;
456 456
 
457 457
 Remove filter. End filter is not removed.
458 458
 
459
-=head2 C<(experimental) stash>
459
+=head2 C<stash> EXPERIMENTAL
460 460
 
461 461
     my $stash = $result->stash;
462 462
     my $foo = $result->stash->{foo};
+1 -1
lib/DBIx/Custom/Tag.pm
... ...
@@ -68,7 +68,7 @@ sub placeholder {
68 68
 sub update_param {
69 69
     my @columns = @_;
70 70
     
71
-    # Update paramters
71
+    # Update parameters
72 72
     my $s = 'set ';
73 73
     $s .= "$_ = ?, " for @columns;
74 74
     $s =~ s/, $//;
+1 -1
lib/DBIx/Custom/Where.pm
... ...
@@ -112,7 +112,7 @@ sub _parse {
112 112
 
113 113
 =head1 NAME
114 114
 
115
-DBIx::Custom::Where - Where clause
115
+DBIx::Custom::Where - Where clause EXPERIMENTAL
116 116
 
117 117
 =head1 SYNOPSYS
118 118