Newer Older
112 lines | 2.519kb
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;
31
    $self->bind_filter($self->filters->{encode_utf8});
32
    $self->fetch_filter($self->filters->{decode_utf8});
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

            
49
=head1 Filters
50

            
51
=head2 encode_utf8
52

            
53
    # Encode to UTF-8 byte stream (utf8::upgrade is done if need)
54
    $dbi->filters->{encode_utf8}->($value);
55
    
56
This filter is generally used as bind filter
57

            
58
    $dbi->bind_filter($dbi->filters->{encode_utf8});
59

            
60
=head2 decode_utf8
61

            
62
    # Decode to perl internal string
63
    $dbi->filters->{decode_utf8}->($value);
64
    
65
This filter is generally used as fetch filter
66

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

            
69
=head2 Formats
70
    
71
strptime formats is available
72
    
73
    # format name        format
74
    'SQL99_date'         '%Y-%m-%d',
75
    'SQL99_datetime'     '%Y-%m-%d %H:%M:%S',
76
    'SQL99_time'         '%H:%M:%S',
77
    'ISO-8601_date'      '%Y-%m-%d',
78
    'ISO-8601_datetime'  '%Y-%m-%dT%H:%M:%S',
79
    'ISO-8601_time'      '%H:%M:%S',
80

            
81
You get format as the following
82

            
83
    my $format = $dbi->formats->{$format_name};
84

            
85
=head1 Methods
86

            
87
=head2 utf8_filter_on
88

            
89
    # Encode and decode utf8 filter on
90
    $dbi->utf8_filter_on;
91

            
92
This equel to
93

            
94
    $dbi->bind_filter($dbi->filters->{encode_utf8});
95
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
96

            
97
=head1 AUTHOR
98

            
99
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
100

            
101
Github L<http://github.com/yuki-kimoto>
102

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

            
105
=head1 COPYRIGHT & LICENSE
106

            
107
Copyright 2009 Yuki Kimoto, all rights reserved.
108

            
109
This program is free software; you can redistribute it and/or modify it
110
under the same terms as Perl itself.
111

            
112
=cut