added experimental DBIx::Cus...
|
1 |
package DBIx::Custom::Table; |
2 | ||
3 |
use strict; |
|
4 |
use warnings; |
|
5 | ||
6 |
use base 'Object::Simple'; |
|
7 | ||
8 |
use Carp 'croak'; |
|
9 | ||
added experimental DBIx::Cus...
|
10 |
# Carp trust relationship |
11 |
push @DBIx::Custom::CARP_NOT, __PACKAGE__; |
|
12 | ||
table object call dbi object...
|
13 |
__PACKAGE__->attr(['dbi', 'name', 'base']); |
added experimental DBIx::Cus...
|
14 | |
15 |
our $AUTOLOAD; |
|
16 | ||
17 |
sub AUTOLOAD { |
|
18 |
my $self = shift; |
|
19 | ||
renamed experimental DBIx::C...
|
20 |
# Method name |
21 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added experimental DBIx::Cus...
|
22 | |
renamed experimental DBIx::C...
|
23 |
# Method |
24 |
$self->{_methods} ||= {}; |
|
table object call dbi object...
|
25 |
|
26 |
# Method |
|
27 |
if (my $method = $self->{_methods}->{$mname}) { |
|
28 |
return $self->$method(@_) |
|
29 |
} |
|
30 |
|
|
31 |
# DBI method |
|
32 |
return $self->dbi->$mname(@_); |
|
added experimental DBIx::Cus...
|
33 |
} |
34 | ||
renamed experimental DBIx::C...
|
35 |
sub method { |
added experimental DBIx::Cus...
|
36 |
my $self = shift; |
37 |
|
|
38 |
# Merge |
|
renamed experimental DBIx::C...
|
39 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
40 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
added experimental DBIx::Cus...
|
41 |
|
42 |
return $self; |
|
43 |
} |
|
44 | ||
added insert, update, update...
|
45 |
sub new { |
46 |
my $self = shift->SUPER::new(@_); |
|
47 |
|
|
many changed
|
48 |
# Methods |
added insert, update, update...
|
49 |
my @methods = qw/insert update update_all delete delete_all select/; |
50 |
foreach my $method (@methods) { |
|
renamed experimental DBIx::C...
|
51 |
$self->method( |
added insert, update, update...
|
52 |
$method => sub { |
53 |
my $self = shift; |
|
54 |
return $self->dbi->$method(table => $self->name, @_); |
|
55 |
} |
|
56 |
); |
|
57 |
} |
|
many changed
|
58 |
|
added insert, update, update...
|
59 |
return $self; |
60 |
} |
|
61 | ||
added experimental DBIx::Cus...
|
62 |
sub DESTROY { } |
63 | ||
64 |
1; |
|
65 | ||
66 |
=head1 NAME |
|
67 | ||
add examples
|
68 |
DBIx::Custom::Table - Table base class(experimental) |
added experimental DBIx::Cus...
|
69 | |
70 |
=head1 SYNOPSIS |
|
71 | ||
72 |
use DBIx::Custom::Table; |
|
73 | ||
74 |
my $table = DBIx::Custom::Table->new(name => 'books'); |
|
75 | ||
76 |
=head1 METHODS |
|
77 | ||
78 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
|
79 |
and implements the following new ones. |
|
80 | ||
added insert, update, update...
|
81 |
=head2 C<delete> |
82 | ||
83 |
$table->delete(where => \%where); |
|
84 |
|
|
85 |
Same as C<delete()> of L<DBIx::Custom> except that |
|
86 |
you don't have to specify table name. |
|
87 | ||
88 |
=head2 C<delete_all> |
|
89 | ||
90 |
$table->delete_all(param => $param); |
|
91 |
|
|
92 |
Same as C<delete_all()> of L<DBIx::Custom> except that |
|
93 |
you don't have to specify table name. |
|
94 | ||
renamed experimental DBIx::C...
|
95 |
=head2 C<method> |
added experimental DBIx::Cus...
|
96 | |
renamed experimental DBIx::C...
|
97 |
$table->method(insert => sub { |
simplified DBIx::Custom::Mod...
|
98 |
my $self = shift; |
99 |
|
|
100 |
return $self->dbi->insert(table => $self->name, @_); |
|
added experimental DBIx::Cus...
|
101 |
}); |
102 |
|
|
renamed experimental DBIx::C...
|
103 |
Add method to a L<DBIx::Custom::Table> object. |
added experimental DBIx::Cus...
|
104 | |
added insert, update, update...
|
105 |
=head2 C<insert> |
106 | ||
107 |
$table->insert(param => \%param); |
|
108 |
|
|
109 |
Same as C<insert()> of L<DBIx::Custom> except that |
|
110 |
you don't have to specify table name. |
|
111 | ||
112 |
=head2 C<method> |
|
113 | ||
114 |
$table->method( |
|
115 |
select_complex => sub { |
|
116 |
my $self = shift; |
|
117 |
|
|
118 |
return $self->dbi->select($self->name, ...); |
|
119 |
}, |
|
120 |
some_method => sub { ... } |
|
121 |
); |
|
122 | ||
123 |
Define method. |
|
124 | ||
125 |
=head2 C<new> |
|
126 | ||
127 |
my $table = DBIx::Custom::Table->new; |
|
128 | ||
129 |
Create a L<DBIx::Custom::Table> object. |
|
130 | ||
131 |
=head2 C<select> |
|
132 | ||
133 |
$table->select(param => $param); |
|
134 |
|
|
135 |
Same as C<select()> of L<DBIx::Custom> except that |
|
136 |
you don't have to specify table name. |
|
137 | ||
138 |
=head2 C<update> |
|
139 | ||
140 |
$table->update(param => \%param, where => \%where); |
|
141 |
|
|
142 |
Same as C<update()> of L<DBIx::Custom> except that |
|
143 |
you don't have to specify table name. |
|
144 | ||
145 |
=head2 C<update_all> |
|
146 | ||
147 |
$table->update_all(param => \%param); |
|
148 |
|
|
149 |
Same as C<update_all()> of L<DBIx::Custom> except that |
|
150 |
you don't have to specify table name. |