DBIx-Custom / lib / DBI / Custom.pm /
Newer Older
189 lines | 3.496kb
first commit
yuki-kimoto authored on 2009-10-13
1
package DBI::Custom;
2
use Object::Simple;
add test
yuki-kimoto authored on 2009-10-16
3

            
4
our $VERSION = '0.0101';
5

            
6
use Carp 'croak';
add some method
yuki-kimoto authored on 2009-10-14
7
use DBI;
first commit
yuki-kimoto authored on 2009-10-13
8

            
cleanup
yuki-kimoto authored on 2009-10-15
9
# Model
10
sub model : ClassAttr { auto_build => \&_inherit_model }
first commit
yuki-kimoto authored on 2009-10-13
11

            
cleanup
yuki-kimoto authored on 2009-10-15
12
# Inherit super class model
13
sub _inherit_model {
add test
yuki-kimoto authored on 2009-10-16
14
    my $class = shift;
cleanup
yuki-kimoto authored on 2009-10-15
15
    my $super = do {
16
        no strict 'refs';
17
        ${"${class}::ISA"}[0];
18
    };
19
    my $model = eval{$super->can('model')}
20
                         ? $super->model->clone
21
                         : $class->Object::Simple::new;
cleanup
yuki-kimoto authored on 2009-10-14
22
    
23
    $class->model($model);
first commit
yuki-kimoto authored on 2009-10-13
24
}
25

            
cleanup
yuki-kimoto authored on 2009-10-15
26
# New
27
sub new {
28
    my $self = shift->Object::Simple::new(@_);
29
    my $class = ref $self;
30
    return bless {%{$class->model->clone}, %{$self}}, $class;
first commit
yuki-kimoto authored on 2009-10-13
31
}
32

            
cleanup
yuki-kimoto authored on 2009-10-15
33
# Initialize modle
34
sub initialize_model {
35
    my ($class, $callback) = @_;
first commit
yuki-kimoto authored on 2009-10-13
36
    
cleanup
yuki-kimoto authored on 2009-10-15
37
    # Callback to initialize model
38
    $callback->($class->model);
first commit
yuki-kimoto authored on 2009-10-13
39
}
40

            
cleanup
yuki-kimoto authored on 2009-10-15
41
# Clone
42
sub clone {
cleanup
yuki-kimoto authored on 2009-10-14
43
    my $self = shift;
cleanup
yuki-kimoto authored on 2009-10-15
44
    my $new = $self->Object::Simple::new;
add test
yuki-kimoto authored on 2009-10-16
45
    $new->connect_info(%{$self->connect_info || {}});
cleanup
yuki-kimoto authored on 2009-10-15
46
    $new->filters(%{$self->filters || {}});
add test
yuki-kimoto authored on 2009-10-16
47
    $new->bind_filter($self->bind_filter);
48
    $new->fetch_filter($self->fetch_filter);
cleanup
yuki-kimoto authored on 2009-10-14
49
}
50

            
cleanup
yuki-kimoto authored on 2009-10-15
51
# Attribute
52
sub connect_info       : Attr { type => 'hash',  auto_build => sub { shift->connect_info({}) } }
cleanup
yuki-kimoto authored on 2009-10-15
53

            
add test
yuki-kimoto authored on 2009-10-16
54
sub bind_filter : Attr {}
55
sub fetch_filter : Attr {}
cleanup
yuki-kimoto authored on 2009-10-15
56

            
add test
yuki-kimoto authored on 2009-10-16
57
sub filters : Attr { type => 'hash', deref => 1, auto_build => sub { shift->filters({}) } }
cleanup
yuki-kimoto authored on 2009-10-15
58
sub add_filter { shift->filters(@_) }
59

            
cleanup
yuki-kimoto authored on 2009-10-15
60
sub dbh          : Attr { auto_build => sub { shift->connect } }
add test
yuki-kimoto authored on 2009-10-16
61

            
62
our %VALID_CONNECT_INFO = map {$_ => 1} qw/data_source user password options/;
cleanup
yuki-kimoto authored on 2009-10-14
63

            
add some method
yuki-kimoto authored on 2009-10-14
64
sub connect {
65
    my $self = shift;
66
    my $connect_info = $self->connect_info;
67
    
add test
yuki-kimoto authored on 2009-10-16
68
    foreach my $key (keys %{$self->connect_info}) {
69
        
70
    }
71
    
add some method
yuki-kimoto authored on 2009-10-14
72
    my $dbh = DBI->connect(
add test
yuki-kimoto authored on 2009-10-16
73
        $connect_info->{data_source},
add some method
yuki-kimoto authored on 2009-10-14
74
        $connect_info->{user},
75
        $connect_info->{password},
76
        {
77
            RaiseError => 1,
78
            PrintError => 0,
79
            AutoCommit => 1,
80
            %{$connect_info->{options} || {} }
81
        }
82
    );
83
    
84
    $self->dbh($dbh);
85
}
first commit
yuki-kimoto authored on 2009-10-13
86

            
add some method
yuki-kimoto authored on 2009-10-14
87
sub query {
first commit
yuki-kimoto authored on 2009-10-13
88
    
89
}
90

            
91
Object::Simple->build_class;
92

            
93
=head1 NAME
94

            
95
DBI::Custom - The great new DBI::Custom!
96

            
97
=head1 VERSION
98

            
add test
yuki-kimoto authored on 2009-10-16
99
Version 0.0101
first commit
yuki-kimoto authored on 2009-10-13
100

            
101
=cut
102

            
103
=head1 SYNOPSIS
104

            
add test
yuki-kimoto authored on 2009-10-16
105
  my $dbi = DBI::Custom->new;
first commit
yuki-kimoto authored on 2009-10-13
106

            
add test
yuki-kimoto authored on 2009-10-16
107
=head1 METHODS
first commit
yuki-kimoto authored on 2009-10-13
108

            
add test
yuki-kimoto authored on 2009-10-16
109
=head2 add_filter
first commit
yuki-kimoto authored on 2009-10-13
110

            
add test
yuki-kimoto authored on 2009-10-16
111
=head2 bind_filter
first commit
yuki-kimoto authored on 2009-10-13
112

            
add test
yuki-kimoto authored on 2009-10-16
113
=head2 clone
first commit
yuki-kimoto authored on 2009-10-13
114

            
add test
yuki-kimoto authored on 2009-10-16
115
=head2 connect
first commit
yuki-kimoto authored on 2009-10-13
116

            
add test
yuki-kimoto authored on 2009-10-16
117
=head2 connect_info
first commit
yuki-kimoto authored on 2009-10-13
118

            
add test
yuki-kimoto authored on 2009-10-16
119
=head2 dbh
first commit
yuki-kimoto authored on 2009-10-13
120

            
add test
yuki-kimoto authored on 2009-10-16
121
=head2 fetch_filter
first commit
yuki-kimoto authored on 2009-10-13
122

            
add test
yuki-kimoto authored on 2009-10-16
123
=head2 filters
first commit
yuki-kimoto authored on 2009-10-13
124

            
add test
yuki-kimoto authored on 2009-10-16
125
=head2 initialize_model
first commit
yuki-kimoto authored on 2009-10-13
126

            
add test
yuki-kimoto authored on 2009-10-16
127
=head2 model
first commit
yuki-kimoto authored on 2009-10-13
128

            
add test
yuki-kimoto authored on 2009-10-16
129
=head2 new
130

            
131
=head2 query
first commit
yuki-kimoto authored on 2009-10-13
132

            
133
=head1 AUTHOR
134

            
135
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
136

            
137
=head1 BUGS
138

            
139
Please report any bugs or feature requests to C<bug-dbi-custom at rt.cpan.org>, or through
140
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBI-Custom>.  I will be notified, and then you'll
141
automatically be notified of progress on your bug as I make changes.
142

            
143

            
144

            
145

            
146
=head1 SUPPORT
147

            
148
You can find documentation for this module with the perldoc command.
149

            
150
    perldoc DBI::Custom
151

            
152

            
153
You can also look for information at:
154

            
155
=over 4
156

            
157
=item * RT: CPAN's request tracker
158

            
159
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBI-Custom>
160

            
161
=item * AnnoCPAN: Annotated CPAN documentation
162

            
163
L<http://annocpan.org/dist/DBI-Custom>
164

            
165
=item * CPAN Ratings
166

            
167
L<http://cpanratings.perl.org/d/DBI-Custom>
168

            
169
=item * Search CPAN
170

            
171
L<http://search.cpan.org/dist/DBI-Custom/>
172

            
173
=back
174

            
175

            
176
=head1 ACKNOWLEDGEMENTS
177

            
178

            
179
=head1 COPYRIGHT & LICENSE
180

            
181
Copyright 2009 Yuki Kimoto, all rights reserved.
182

            
183
This program is free software; you can redistribute it and/or modify it
184
under the same terms as Perl itself.
185

            
186

            
187
=cut
188

            
189
1; # End of DBI::Custom