Newer Older
102 lines | 2.205kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::Basic;
2

            
3
use warnings;
4
use strict;
update document
yuki-kimoto authored on 2010-01-30
5

            
6
use base 'DBIx::Custom';
update document
yuki-kimoto authored on 2009-11-17
7
use Encode qw/decode encode/;
packaging one directory
yuki-kimoto authored on 2009-11-16
8

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
9
__PACKAGE__->add_filter(
version 0.0901
yuki-kimoto authored on 2009-12-17
10
    encode_utf8 => sub { encode('UTF-8', shift) },
packaging one directory
yuki-kimoto authored on 2009-11-16
11
    decode_utf8 => sub { decode('UTF-8', shift) }
12
);
13

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
14
__PACKAGE__->add_format(
packaging one directory
yuki-kimoto authored on 2009-11-16
15
    'SQL99_date'        => '%Y-%m-%d',
16
    'SQL99_datetime'    => '%Y-%m-%d %H:%M:%S',
17
    'SQL99_time'        => '%H:%M:%S',
18
    'ISO-8601_date'     => '%Y-%m-%d',
19
    'ISO-8601_datetime' => '%Y-%m-%dT%H:%M:%S',
20
    'ISO-8601_time'     => '%H:%M:%S',
21
);
22

            
23
sub utf8_filter_on {
24
    my $self = shift;
update document
yuki-kimoto authored on 2009-11-19
25
    
26
    # Set utf8 filters
packaging one directory
yuki-kimoto authored on 2009-11-16
27
    $self->bind_filter($self->filters->{encode_utf8});
28
    $self->fetch_filter($self->filters->{decode_utf8});
update document
yuki-kimoto authored on 2009-11-19
29
    
30
    return $self;
packaging one directory
yuki-kimoto authored on 2009-11-16
31
}
32

            
33
1;
34

            
35
=head1 NAME
36

            
37
DBIx::Custom::Basic - DBIx::Custom basic implementation
38

            
update document
yuki-kimoto authored on 2010-01-30
39
=head1 SYNOPSYS
packaging one directory
yuki-kimoto authored on 2009-11-16
40

            
update document
yuki-kimoto authored on 2010-01-30
41
    # New
42
    my $dbi = DBIx::Custom::Basic->new(
43
        data_source => "dbi:mysql:database=books",
44
        user        => 'ken',
45
        password    => '!LFKD%$&'
46
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
47

            
update document
yuki-kimoto authored on 2010-01-30
48
=head1 METHODS
packaging one directory
yuki-kimoto authored on 2009-11-16
49

            
update document
yuki-kimoto authored on 2010-01-30
50
This class is L<DBIx::Custom> subclass.
51
You can use all methods of L<DBIx::Custom>
update document
yuki-kimoto authored on 2009-11-19
52

            
53
=head2 utf8_filter_on
54

            
55
Encode and decode utf8 filter on
56

            
57
    $dbi->utf8_filter_on;
58

            
59
This equel to
60

            
61
    $dbi->bind_filter($dbi->filters->{encode_utf8});
62
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
63

            
update document
yuki-kimoto authored on 2010-01-30
64
=head1 FILTERS
packaging one directory
yuki-kimoto authored on 2009-11-16
65

            
66
=head2 encode_utf8
67

            
version 0.0901
yuki-kimoto authored on 2009-12-17
68
Encode internal string to UTF-8 byte stream
69
If need, utf8::upgrade is also done.
70

            
packaging one directory
yuki-kimoto authored on 2009-11-16
71
    $dbi->filters->{encode_utf8}->($value);
72
    
73
This filter is generally used as bind filter
74

            
75
    $dbi->bind_filter($dbi->filters->{encode_utf8});
76

            
77
=head2 decode_utf8
78

            
version 0.0901
yuki-kimoto authored on 2009-12-17
79
Decode UTF-8 byte stream to internal string
packaging one directory
yuki-kimoto authored on 2009-11-16
80
    $dbi->filters->{decode_utf8}->($value);
81
    
82
This filter is generally used as fetch filter
83

            
84
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
85

            
update document
yuki-kimoto authored on 2010-01-30
86
=head1 DATE FORMATS
packaging one directory
yuki-kimoto authored on 2009-11-16
87
    
88
strptime formats is available
89
    
90
    # format name        format
91
    'SQL99_date'         '%Y-%m-%d',
92
    'SQL99_datetime'     '%Y-%m-%d %H:%M:%S',
93
    'SQL99_time'         '%H:%M:%S',
94
    'ISO-8601_date'      '%Y-%m-%d',
95
    'ISO-8601_datetime'  '%Y-%m-%dT%H:%M:%S',
96
    'ISO-8601_time'      '%H:%M:%S',
97

            
98
You get format as the following
99

            
100
    my $format = $dbi->formats->{$format_name};
101

            
102
=cut