Newer Older
121 lines | 2.683kb
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;
fix timeformat tests
yuki-kimoto authored on 2009-11-23
13
        return $value unless defined $value;
packaging one directory
yuki-kimoto authored on 2009-11-16
14
        utf8::upgrade($value) unless Encode::is_utf8($value);
15
        return encode('UTF-8', $value);
16
    },
17
    decode_utf8 => sub { decode('UTF-8', shift) }
18
);
19

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

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

            
40
1;
41

            
42
=head1 NAME
43

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

            
46
=head1 See DBIx::Custom documentation
47

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

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

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

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

            
56
=head2 utf8_filter_on
57

            
58
Encode and decode utf8 filter on
59

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

            
65
This equel to
66

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

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

            
72
=head2 encode_utf8
73

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

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

            
81
=head2 decode_utf8
82

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

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

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

            
102
You get format as the following
103

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

            
106
=head1 AUTHOR
107

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

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

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

            
114
=head1 COPYRIGHT & LICENSE
115

            
116
Copyright 2009 Yuki Kimoto, all rights reserved.
117

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

            
121
=cut