add feture. all model class ...
|
1 |
package DBIx::Custom::Model; |
added experimental DBIx::Cus...
|
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 | ||
add feture. all model class ...
|
13 |
__PACKAGE__->attr(['dbi', 'table']); |
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 |
if (my $method = $self->{_methods}->{$mname}) { |
26 |
return $self->$method(@_) |
|
27 |
} |
|
add feture. all model class ...
|
28 |
elsif ($self->dbi->can($mname)) { |
29 |
$self->dbi->$mname(@_); |
|
30 |
} |
|
31 |
elsif ($self->dbi->dbh->can($mname)) { |
|
32 |
$self->dbi->dbh->$mname(@_); |
|
33 |
} |
|
34 |
else { |
|
35 |
croak qq/Can't locate object method "$mname" via "$package"/ |
|
36 |
} |
|
added experimental DBIx::Cus...
|
37 |
} |
38 | ||
renamed experimental DBIx::C...
|
39 |
sub method { |
added experimental DBIx::Cus...
|
40 |
my $self = shift; |
41 |
|
|
42 |
# Merge |
|
renamed experimental DBIx::C...
|
43 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
44 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
added experimental DBIx::Cus...
|
45 |
|
46 |
return $self; |
|
47 |
} |
|
48 | ||
added insert, update, update...
|
49 |
sub new { |
50 |
my $self = shift->SUPER::new(@_); |
|
51 |
|
|
many changed
|
52 |
# Methods |
added insert, update, update...
|
53 |
my @methods = qw/insert update update_all delete delete_all select/; |
54 |
foreach my $method (@methods) { |
|
renamed experimental DBIx::C...
|
55 |
$self->method( |
added insert, update, update...
|
56 |
$method => sub { |
57 |
my $self = shift; |
|
add feture. all model class ...
|
58 |
return $self->dbi->$method(table => $self->table, @_); |
added insert, update, update...
|
59 |
} |
60 |
); |
|
61 |
} |
|
many changed
|
62 |
|
added insert, update, update...
|
63 |
return $self; |
64 |
} |
|
65 | ||
added experimental DBIx::Cus...
|
66 |
sub DESTROY { } |
67 | ||
68 |
1; |
|
69 | ||
70 |
=head1 NAME |
|
71 | ||
add examples
|
72 |
DBIx::Custom::Table - Table base class(experimental) |
added experimental DBIx::Cus...
|
73 | |
74 |
=head1 SYNOPSIS |
|
75 | ||
76 |
use DBIx::Custom::Table; |
|
77 | ||
add feture. all model class ...
|
78 |
my $table = DBIx::Custom::Model->new(table => 'books'); |
added experimental DBIx::Cus...
|
79 | |
80 |
=head1 METHODS |
|
81 | ||
table object call dbi object...
|
82 |
L<DBIx::Custom> inherits all methods from L<Object::Simple>, |
83 |
and you can use all methods of the object set to C<dbi>. |
|
added experimental DBIx::Cus...
|
84 |
and implements the following new ones. |
85 | ||
added insert, update, update...
|
86 |
=head2 C<delete> |
87 | ||
table object call dbi object...
|
88 |
$table->delete(...); |
added insert, update, update...
|
89 |
|
90 |
Same as C<delete()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
91 |
you don't have to specify C<table> option. |
added insert, update, update...
|
92 | |
93 |
=head2 C<delete_all> |
|
94 | ||
table object call dbi object...
|
95 |
$table->delete_all(...); |
added insert, update, update...
|
96 |
|
97 |
Same as C<delete_all()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
98 |
you don't have to specify C<table> option. |
added insert, update, update...
|
99 | |
renamed experimental DBIx::C...
|
100 |
=head2 C<method> |
added experimental DBIx::Cus...
|
101 | |
table object call dbi object...
|
102 |
$table->method( |
103 |
count => sub { |
|
104 |
my $self = shift; |
|
simplified DBIx::Custom::Mod...
|
105 |
|
table object call dbi object...
|
106 |
return $self->select(column => 'count(*)', @_) |
107 |
->fetch_first->[0]; |
|
108 |
} |
|
109 |
); |
|
added experimental DBIx::Cus...
|
110 |
|
renamed experimental DBIx::C...
|
111 |
Add method to a L<DBIx::Custom::Table> object. |
added experimental DBIx::Cus...
|
112 | |
added insert, update, update...
|
113 |
=head2 C<insert> |
114 | ||
table object call dbi object...
|
115 |
$table->insert(...); |
added insert, update, update...
|
116 |
|
117 |
Same as C<insert()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
118 |
you don't have to specify C<table> option. |
added insert, update, update...
|
119 | |
120 |
=head2 C<new> |
|
121 | ||
122 |
my $table = DBIx::Custom::Table->new; |
|
123 | ||
124 |
Create a L<DBIx::Custom::Table> object. |
|
125 | ||
126 |
=head2 C<select> |
|
127 | ||
table object call dbi object...
|
128 |
$table->select(...); |
added insert, update, update...
|
129 |
|
130 |
Same as C<select()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
131 |
you don't have to specify C<table> option. |
added insert, update, update...
|
132 | |
133 |
=head2 C<update> |
|
134 | ||
table object call dbi object...
|
135 |
$table->update(...); |
added insert, update, update...
|
136 |
|
137 |
Same as C<update()> of L<DBIx::Custom> except that |
|
table object call dbi object...
|
138 |
you don't have to specify C<table> option. |
added insert, update, update...
|
139 | |
140 |
=head2 C<update_all> |
|
141 | ||
142 |
$table->update_all(param => \%param); |
|
143 |
|
|
144 |
Same as C<update_all()> of L<DBIx::Custom> except that |
|
145 |
you don't have to specify table name. |