Newer Older
119 lines | 2.591kb
packing
yuki-kimoto authored on 2009-11-12
1
package DBIx::Custom::Basic;
filter argument exchange key...
yuki-kimoto authored on 2009-11-12
2
use 5.008001;
packing
yuki-kimoto authored on 2009-11-12
3
use base 'DBIx::Custom';
4
use Encode qw/decode encode/;
5

            
6
use warnings;
7
use strict;
8

            
filter argument exchange key...
yuki-kimoto authored on 2009-11-12
9
our $VERSION = '0.0201';
packing
yuki-kimoto authored on 2009-11-12
10

            
11
my $class = __PACKAGE__;
12

            
13
$class->add_filter(
filter argument exchange key...
yuki-kimoto authored on 2009-11-12
14
    encode_utf8 => sub {
15
        my $value = shift;
16
        utf8::upgrade($value) unless Encode::is_utf8($value);
17
        return encode('UTF-8', $value);
18
    },
19
    decode_utf8 => sub { decode('UTF-8', shift) }
packing
yuki-kimoto authored on 2009-11-12
20
);
21

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

            
filter argument exchange key...
yuki-kimoto authored on 2009-11-12
31
# Methods
32
sub utf8_filter_on {
33
    my $self = shift;
34
    $self->bind_filter($self->filters->{encode_utf8});
35
    $self->fetch_filter($self->filters->{decode_utf8});
36
}
37

            
packing
yuki-kimoto authored on 2009-11-12
38
1;
39

            
40
=head1 NAME
41

            
Various change
yuki-kimoto authored on 2009-11-12
42
DBIx::Custom::Basic - DBIx::Custom basic implementation
packing
yuki-kimoto authored on 2009-11-12
43

            
Various change
yuki-kimoto authored on 2009-11-12
44
=head1 Version
packing
yuki-kimoto authored on 2009-11-12
45

            
filter argument exchange key...
yuki-kimoto authored on 2009-11-12
46
Version 0.0201
47

            
Various change
yuki-kimoto authored on 2009-11-12
48
=head1 See DBIx::Custom documentation
49

            
50
This class is L<DBIx::Custom> subclass.
51

            
52
You can use all methods of L<DBIx::Custom>
53

            
54
Please see L<DBIx::Custom> documentation
55

            
56
=head1 Filters
filter argument exchange key...
yuki-kimoto authored on 2009-11-12
57

            
58
=head2 encode_utf8
59

            
60
    # Encode to UTF-8 byte stream (utf8::upgrade is done if need)
61
    $dbi->filters->{encode_utf8}->($value);
62
    
63
This filter is generally used as bind filter
64

            
65
    $dbi->bind_filter($dbi->filters->{encode_utf8});
66

            
67
=head2 decode_utf8
68

            
69
    # Decode to perl internal string
70
    $dbi->filters->{decode_utf8}->($value);
71
    
72
This filter is generally used as fetch filter
73

            
74
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
75

            
Various change
yuki-kimoto authored on 2009-11-12
76
=head2 Formats
filter argument exchange key...
yuki-kimoto authored on 2009-11-12
77
    
78
strptime formats is available
79
    
80
    # format name        format
81
    'SQL99_date'         '%Y-%m-%d',
82
    'SQL99_datetime'     '%Y-%m-%d %H:%M:%S',
83
    'SQL99_time'         '%H:%M:%S',
84
    'ISO-8601_date'      '%Y-%m-%d',
85
    'ISO-8601_datetime'  '%Y-%m-%dT%H:%M:%S',
86
    'ISO-8601_time'      '%H:%M:%S',
87

            
88
You get format as the following
89

            
90
    my $format = $dbi->formats->{$format_name};
91

            
Various change
yuki-kimoto authored on 2009-11-12
92
=head1 Methods
filter argument exchange key...
yuki-kimoto authored on 2009-11-12
93

            
94
=head2 utf8_filter_on
95

            
96
    # Encode and decode utf8 filter on
97
    $dbi->utf8_filter_on;
98

            
99
This equel to
100

            
101
    $dbi->bind_filter($dbi->filters->{encode_utf8});
102
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
packing
yuki-kimoto authored on 2009-11-12
103

            
104
=head1 AUTHOR
105

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

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

            
Various change
yuki-kimoto authored on 2009-11-12
110
I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom>
111

            
packing
yuki-kimoto authored on 2009-11-12
112
=head1 COPYRIGHT & LICENSE
113

            
114
Copyright 2009 Yuki Kimoto, all rights reserved.
115

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

            
119
=cut