Skip to content
Browse files

fixed issue #79, cached AUTOLOAD column method code-refs

  • Loading branch information...
1 parent 0051bd3 commit a7b640e039d3f012f979a7c60307a8526c8f73b8 @yappo yappo committed Oct 2, 2012
Showing with 19 additions and 4 deletions.
  1. +6 −4 lib/Teng/Row.pm
  2. +13 −0 t/001_basic/015_row_class.t
View
10 lib/Teng/Row.pm
@@ -8,8 +8,9 @@ sub new {
my ($class, $args) = @_;
my $self = bless {
- _get_column_cached => {},
- _dirty_columns => {},
+ _get_column_cached => {},
+ _dirty_columns => {},
+ _autoload_column_cache => {},
%$args,
}, $class;
@@ -176,10 +177,11 @@ sub _where_cond {
}
}
-sub AUTOLOAD{
+# for +columns option by some search methods
+sub AUTOLOAD {
my $self = shift;
my($method) = ($AUTOLOAD =~ /([^:']+$)/);
- $self->generate_column_accessor($method)->($self);
+ ($self->{_autoload_column_cache}{$method} ||= $self->generate_column_accessor($method))->($self);
}
### don't autoload this
View
13 t/001_basic/015_row_class.t
@@ -93,10 +93,23 @@ subtest 'handle' => sub {
can_ok $row->handle, 'single';
};
+subtest 'your row class AUTOLOAD' => sub {
+ my $row = $db_basic_row->single('mock_basic_row',{id => 1},{'+columns' => [\'id+10 as id_plus_ten']});
+ isa_ok $row, 'Mock::BasicRow::Row::MockBasicRow';
+ is $row->foo, 'foo';
+ is $row->id, 1;
+ is $row->name, 'perl';
+ is $row->id_plus_ten, 11;
+
+ ok $row->can('id');
+ ok ! $row->can('mock_basic_id');
+};
+
subtest 'AUTOLOAD' => sub {
my $row = $db_basic->search_by_sql(q{select id as mock_basic_id from mock_basic where id = 1})->next;
isa_ok $row, 'Teng::Row';
is $row->mock_basic_id, 1;
+ ok ! $row->can('mock_basic_id');
};
subtest 'can not use (update|delete) method' => sub {

0 comments on commit a7b640e

Please sign in to comment.
Something went wrong with that request. Please try again.