... | ... |
@@ -1,3 +1,6 @@ |
1 |
+0.1640 |
|
2 |
+ autoload DBI method |
|
3 |
+ removed experimental expand |
|
1 | 4 |
0.1639 |
2 | 5 |
improved delete() and update() where option. you can use DBIx::Custom::Where object |
3 | 6 |
added experimental not_exists() |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
|
3 |
-our $VERSION = '0.1639'; |
|
3 |
+our $VERSION = '0.1640'; |
|
4 | 4 |
|
5 | 5 |
use 5.008001; |
6 | 6 |
use strict; |
... | ... |
@@ -53,21 +53,7 @@ __PACKAGE__->attr( |
53 | 53 |
} |
54 | 54 |
); |
55 | 55 |
|
56 |
-# DBI methods |
|
57 |
-foreach my $method (qw/begin_work commit rollback/) { |
|
58 |
- my $code = sub { |
|
59 |
- my $self = shift; |
|
60 |
- my $ret = eval {$self->dbh->$method}; |
|
61 |
- croak $@ if $@; |
|
62 |
- return $ret; |
|
63 |
- }; |
|
64 |
- no strict 'refs'; |
|
65 |
- my $pkg = __PACKAGE__; |
|
66 |
- *{"${pkg}::$method"} = $code; |
|
67 |
-}; |
|
68 |
- |
|
69 | 56 |
our $AUTOLOAD; |
70 |
- |
|
71 | 57 |
sub AUTOLOAD { |
72 | 58 |
my $self = shift; |
73 | 59 |
|
... | ... |
@@ -76,10 +62,11 @@ sub AUTOLOAD { |
76 | 62 |
|
77 | 63 |
# Method |
78 | 64 |
$self->{_methods} ||= {}; |
79 |
- croak qq/Can't locate object method "$mname" via "$package"/ |
|
80 |
- unless my $method = $self->{_methods}->{$mname}; |
|
65 |
+ my $method = $self->{_methods}->{$mname}; |
|
66 |
+ return $self->$method(@_) if $method; |
|
81 | 67 |
|
82 |
- return $self->$method(@_); |
|
68 |
+ # DBI method |
|
69 |
+ return $self->dbh->$mname(@_); |
|
83 | 70 |
} |
84 | 71 |
|
85 | 72 |
sub apply_filter { |
... | ... |
@@ -371,21 +358,6 @@ sub execute{ |
371 | 358 |
return $affected; |
372 | 359 |
} |
373 | 360 |
|
374 |
-sub expand { |
|
375 |
- my $self = shift; |
|
376 |
- my $source = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
377 |
- my $table = (keys %$source)[0]; |
|
378 |
- my $param = $source->{$table}; |
|
379 |
- |
|
380 |
- # Expand table name |
|
381 |
- my $expand = {}; |
|
382 |
- foreach my $column (keys %$param) { |
|
383 |
- $expand->{"$table.$column"} = $param->{$column}; |
|
384 |
- } |
|
385 |
- |
|
386 |
- return %$expand; |
|
387 |
-} |
|
388 |
- |
|
389 | 361 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append |
390 | 362 |
filter query/; |
391 | 363 |
sub insert { |
... | ... |
@@ -1001,6 +973,7 @@ C<connect()> method use this value to connect the database. |
1001 | 973 |
=head1 METHODS |
1002 | 974 |
|
1003 | 975 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
976 |
+and use all method of L<DBI> |
|
1004 | 977 |
and implements the following new ones. |
1005 | 978 |
|
1006 | 979 |
=head2 C<(experimental) apply_filter> |
... | ... |
@@ -1025,23 +998,6 @@ arguments. |
1025 | 998 |
table => ['table1'] |
1026 | 999 |
); |
1027 | 1000 |
|
1028 |
-=head2 C<begin_work> |
|
1029 |
- |
|
1030 |
- $dbi->begin_work; |
|
1031 |
- |
|
1032 |
-Start transaction. |
|
1033 |
-This is same as L<DBI>'s C<begin_work>. |
|
1034 |
- |
|
1035 |
-L<DBIx::Custom> inherits all methods from L<Object::Simple> |
|
1036 |
-and implements the following new ones. |
|
1037 |
- |
|
1038 |
-=head2 C<commit> |
|
1039 |
- |
|
1040 |
- $dbi->commit; |
|
1041 |
- |
|
1042 |
-Commit transaction. |
|
1043 |
-This is same as L<DBI>'s C<commit>. |
|
1044 |
- |
|
1045 | 1001 |
=head2 C<connect> |
1046 | 1002 |
|
1047 | 1003 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
... | ... |
@@ -574,7 +574,7 @@ is($dbi->two, 2, "second"); |
574 | 574 |
is($dbi->twice(5), 10 , "second"); |
575 | 575 |
|
576 | 576 |
eval {$dbi->XXXXXX}; |
577 |
-like($@, qr/\QCan't locate object method "XXXXXX" via "DBIx::Custom"/, "not exists"); |
|
577 |
+ok($@, "not exists"); |
|
578 | 578 |
|
579 | 579 |
test 'out filter'; |
580 | 580 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-use Test::More tests => 12; |
|
1 |
+use Test::More 'no_plan'; |
|
2 | 2 |
use strict; |
3 | 3 |
use warnings; |
4 | 4 |
|
... | ... |
@@ -83,21 +83,6 @@ is($dbi->filters->{a}->(), 1); |
83 | 83 |
$dbi->register_filter({b => sub {2}}); |
84 | 84 |
is($dbi->filters->{b}->(), 2); |
85 | 85 |
|
86 |
- |
|
87 |
-test 'expand'; |
|
88 |
-{ |
|
89 |
- $dbi = DBIx::Custom->new; |
|
90 |
- my $source = {books => {title => 'Perl', author => 'Ken'}}; |
|
91 |
- is_deeply({$dbi->expand($source)}, |
|
92 |
- {'books.title' => 'Perl', 'books.author' => 'Ken'}); |
|
93 |
-} |
|
94 |
-{ |
|
95 |
- $dbi = DBIx::Custom->new; |
|
96 |
- my %source = (books => {title => 'Perl', author => 'Ken'}); |
|
97 |
- is_deeply({$dbi->expand(%source)}, |
|
98 |
- {'books.title' => 'Perl', 'books.author' => 'Ken'}); |
|
99 |
-} |
|
100 |
- |
|
101 | 86 |
test 'invalid attribute name'; |
102 | 87 |
eval {$dbi = DBIx::Custom->new(a => 1) }; |
103 | 88 |
like ($@, qr/"a" is invalid attribute name/); |