Newer Older
113 lines | 2.482kb
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

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
8
__PACKAGE__->add_filter(
version 0.0901
yuki-kimoto authored on 2009-12-17
9
    encode_utf8 => sub { encode('UTF-8', shift) },
packaging one directory
yuki-kimoto authored on 2009-11-16
10
    decode_utf8 => sub { decode('UTF-8', shift) }
11
);
12

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
13
__PACKAGE__->add_format(
packaging one directory
yuki-kimoto authored on 2009-11-16
14
    'SQL99_date'        => '%Y-%m-%d',
15
    'SQL99_datetime'    => '%Y-%m-%d %H:%M:%S',
16
    'SQL99_time'        => '%H:%M:%S',
17
    'ISO-8601_date'     => '%Y-%m-%d',
18
    'ISO-8601_datetime' => '%Y-%m-%dT%H:%M:%S',
19
    'ISO-8601_time'     => '%H:%M:%S',
20
);
21

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

            
33
1;
34

            
35
=head1 NAME
36

            
37
DBIx::Custom::Basic - DBIx::Custom basic implementation
38

            
39
=head1 See DBIx::Custom documentation
40

            
41
This class is L<DBIx::Custom> subclass.
42

            
43
You can use all methods of L<DBIx::Custom>
44

            
45
Please see L<DBIx::Custom> documentation
46

            
update document
yuki-kimoto authored on 2009-11-19
47
=head1 Methods
48

            
49
=head2 utf8_filter_on
50

            
51
Encode and decode utf8 filter on
52

            
53
    $dbi->utf8_filter_on;
54

            
55
This equel to
56

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

            
60
=head1 Available filters
packaging one directory
yuki-kimoto authored on 2009-11-16
61

            
62
=head2 encode_utf8
63

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

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

            
71
    $dbi->bind_filter($dbi->filters->{encode_utf8});
72

            
73
=head2 decode_utf8
74

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

            
80
    $dbi->fetch_filter($dbi->filters->{decode_utf8});
81

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

            
94
You get format as the following
95

            
96
    my $format = $dbi->formats->{$format_name};
97

            
98
=head1 AUTHOR
99

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

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

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

            
106
=head1 COPYRIGHT & LICENSE
107

            
108
Copyright 2009 Yuki Kimoto, all rights reserved.
109

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

            
113
=cut