Newer Older
120 lines | 2.638kb
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(
11
    encode_utf8 => sub {
12
        my $value = shift;
13
        utf8::upgrade($value) unless Encode::is_utf8($value);
14
        return encode('UTF-8', $value);
15
    },
16
    decode_utf8 => sub { decode('UTF-8', shift) }
17
);
18

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

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

            
39
1;
40

            
41
=head1 NAME
42

            
43
DBIx::Custom::Basic - DBIx::Custom basic implementation
44

            
45
=head1 See DBIx::Custom documentation
46

            
47
This class is L<DBIx::Custom> subclass.
48

            
49
You can use all methods of L<DBIx::Custom>
50

            
51
Please see L<DBIx::Custom> documentation
52

            
update document
yuki-kimoto authored on 2009-11-19
53
=head1 Methods
54

            
55
=head2 utf8_filter_on
56

            
57
Encode and decode utf8 filter on
58

            
59
    $self = $self->utf8_filter_on;
60
    
61
    # Sample
62
    $dbi->utf8_filter_on;
63

            
64
This equel to
65

            
66
    $dbi->bind_filter($dbi->filters->{encode_utf8});
67
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
68

            
69
=head1 Available filters
packaging one directory
yuki-kimoto authored on 2009-11-16
70

            
71
=head2 encode_utf8
72

            
73
    # Encode to UTF-8 byte stream (utf8::upgrade is done if need)
74
    $dbi->filters->{encode_utf8}->($value);
75
    
76
This filter is generally used as bind filter
77

            
78
    $dbi->bind_filter($dbi->filters->{encode_utf8});
79

            
80
=head2 decode_utf8
81

            
82
    # Decode to perl internal string
83
    $dbi->filters->{decode_utf8}->($value);
84
    
85
This filter is generally used as fetch filter
86

            
87
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
88

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

            
101
You get format as the following
102

            
103
    my $format = $dbi->formats->{$format_name};
104

            
105
=head1 AUTHOR
106

            
107
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
108

            
109
Github L<http://github.com/yuki-kimoto>
110

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

            
113
=head1 COPYRIGHT & LICENSE
114

            
115
Copyright 2009 Yuki Kimoto, all rights reserved.
116

            
117
This program is free software; you can redistribute it and/or modify it
118
under the same terms as Perl itself.
119

            
120
=cut