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 | ||
removed experimental DBIx::C...
|
13 |
__PACKAGE__->attr(['dbi', 'name']); |
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 | ||
table object call dbi object...
|
78 |
L<DBIx::Custom> inherits all methods from L<Object::Simple>, |
79 |
and you can use all methods of the object set to C<dbi>. |
|
added experimental DBIx::Cus...
|
80 |
and implements the following new ones. |
81 | ||
added insert, update, update...
|
82 |
=head2 C<delete> |
83 | ||
table object call dbi object...
|
84 |
$table->delete(...); |
added insert, update, update...
|
85 |
|
86 |
Same as C<delete()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
87 |
you don't have to specify C<table> option. |
added insert, update, update...
|
88 | |
89 |
=head2 C<delete_all> |
|
90 | ||
table object call dbi object...
|
91 |
$table->delete_all(...); |
added insert, update, update...
|
92 |
|
93 |
Same as C<delete_all()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
94 |
you don't have to specify C<table> option. |
added insert, update, update...
|
95 | |
renamed experimental DBIx::C...
|
96 |
=head2 C<method> |
added experimental DBIx::Cus...
|
97 | |
table object call dbi object...
|
98 |
$table->method( |
99 |
count => sub { |
|
100 |
my $self = shift; |
|
simplified DBIx::Custom::Mod...
|
101 |
|
table object call dbi object...
|
102 |
return $self->select(column => 'count(*)', @_) |
103 |
->fetch_first->[0]; |
|
104 |
} |
|
105 |
); |
|
added experimental DBIx::Cus...
|
106 |
|
renamed experimental DBIx::C...
|
107 |
Add method to a L<DBIx::Custom::Table> object. |
added experimental DBIx::Cus...
|
108 | |
added insert, update, update...
|
109 |
=head2 C<insert> |
110 | ||
table object call dbi object...
|
111 |
$table->insert(...); |
added insert, update, update...
|
112 |
|
113 |
Same as C<insert()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
114 |
you don't have to specify C<table> option. |
added insert, update, update...
|
115 | |
116 |
=head2 C<new> |
|
117 | ||
118 |
my $table = DBIx::Custom::Table->new; |
|
119 | ||
120 |
Create a L<DBIx::Custom::Table> object. |
|
121 | ||
122 |
=head2 C<select> |
|
123 | ||
table object call dbi object...
|
124 |
$table->select(...); |
added insert, update, update...
|
125 |
|
126 |
Same as C<select()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
127 |
you don't have to specify C<table> option. |
added insert, update, update...
|
128 | |
129 |
=head2 C<update> |
|
130 | ||
table object call dbi object...
|
131 |
$table->update(...); |
added insert, update, update...
|
132 |
|
133 |
Same as C<update()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
134 |
you don't have to specify C<table> option. |
added insert, update, update...
|
135 | |
136 |
=head2 C<update_all> |
|
137 | ||
138 |
$table->update_all(param => \%param); |
|
139 |
|
|
140 |
Same as C<update_all()> of L<DBIx::Custom> except that |
|
141 |
you don't have to specify table name. |