Newer Older
115 lines | 2.498kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::Basic;
2
use base 'DBIx::Custom';
3

            
4
use warnings;
5
use strict;
update document
yuki-kimoto authored on 2009-11-17
6
use Encode qw/decode encode/;
packaging one directory
yuki-kimoto authored on 2009-11-16
7

            
8
my $class = __PACKAGE__;
9

            
10
$class->add_filter(
version 0.0901
yuki-kimoto authored on 2009-12-17
11
    encode_utf8 => sub { encode('UTF-8', shift) },
packaging one directory
yuki-kimoto authored on 2009-11-16
12
    decode_utf8 => sub { decode('UTF-8', shift) }
13
);
14

            
15
$class->add_format(
16
    'SQL99_date'        => '%Y-%m-%d',
17
    'SQL99_datetime'    => '%Y-%m-%d %H:%M:%S',
18
    'SQL99_time'        => '%H:%M:%S',
19
    'ISO-8601_date'     => '%Y-%m-%d',
20
    'ISO-8601_datetime' => '%Y-%m-%dT%H:%M:%S',
21
    'ISO-8601_time'     => '%H:%M:%S',
22
);
23

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

            
35
1;
36

            
37
=head1 NAME
38

            
39
DBIx::Custom::Basic - DBIx::Custom basic implementation
40

            
41
=head1 See DBIx::Custom documentation
42

            
43
This class is L<DBIx::Custom> subclass.
44

            
45
You can use all methods of L<DBIx::Custom>
46

            
47
Please see L<DBIx::Custom> documentation
48

            
update document
yuki-kimoto authored on 2009-11-19
49
=head1 Methods
50

            
51
=head2 utf8_filter_on
52

            
53
Encode and decode utf8 filter on
54

            
55
    $dbi->utf8_filter_on;
56

            
57
This equel to
58

            
59
    $dbi->bind_filter($dbi->filters->{encode_utf8});
60
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
61

            
62
=head1 Available filters
packaging one directory
yuki-kimoto authored on 2009-11-16
63

            
64
=head2 encode_utf8
65

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

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

            
73
    $dbi->bind_filter($dbi->filters->{encode_utf8});
74

            
75
=head2 decode_utf8
76

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

            
82
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
83

            
update document
yuki-kimoto authored on 2009-11-19
84
=head2 Available formats
packaging one directory
yuki-kimoto authored on 2009-11-16
85
    
86
strptime formats is available
87
    
88
    # format name        format
89
    'SQL99_date'         '%Y-%m-%d',
90
    'SQL99_datetime'     '%Y-%m-%d %H:%M:%S',
91
    'SQL99_time'         '%H:%M:%S',
92
    'ISO-8601_date'      '%Y-%m-%d',
93
    'ISO-8601_datetime'  '%Y-%m-%dT%H:%M:%S',
94
    'ISO-8601_time'      '%H:%M:%S',
95

            
96
You get format as the following
97

            
98
    my $format = $dbi->formats->{$format_name};
99

            
100
=head1 AUTHOR
101

            
102
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
103

            
104
Github L<http://github.com/yuki-kimoto>
105

            
106
I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom>
107

            
108
=head1 COPYRIGHT & LICENSE
109

            
110
Copyright 2009 Yuki Kimoto, all rights reserved.
111

            
112
This program is free software; you can redistribute it and/or modify it
113
under the same terms as Perl itself.
114

            
115
=cut