Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add Table::set_(inflator|deflator)
  • Loading branch information
nekokak committed Jan 18, 2011
1 parent 0d206d0 commit 333b661
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions lib/Teng/Schema/Table.pm
Expand Up @@ -8,10 +8,9 @@ use Class::Accessor::Lite
columns
sql_types
row_class
inflators
deflators
) ]
;
use Carp ();
use Class::Load ();

sub new {
Expand Down Expand Up @@ -42,8 +41,24 @@ sub get_sql_type {
$self->sql_types->{ $column_name };
}

sub get_deflator { $_[0]->deflators->{$_[1]} }
sub get_inflator { $_[0]->inflators->{$_[1]} }
sub get_deflator { $_[0]->{deflators}->{$_[1]} }
sub get_inflator { $_[0]->{inflators}->{$_[1]} }
sub set_deflator {
my ($self, $col, $code) = @_;

unless (ref($code) eq 'CODE') {
Carp::croak('deflate code must be coderef.');
}
$self->{deflators}->{$col} = $code;
}
sub set_inflator {
my ($self, $col, $code) = @_;

unless (ref($code) eq 'CODE') {
Carp::croak('deflate code must be coderef.');
}
$self->{inflators}->{$col} = $code;
}

sub call_deflate {
my ($self, $col_name, $col_value) = @_;
Expand Down Expand Up @@ -89,6 +104,14 @@ get deflate coderef.
get inflate coderef.
=item $table->set_deflator
set deflate coderef.
=item $table->set_inflator
set inflate coderef.
=item $table->call_deflate
execute deflate.
Expand Down

0 comments on commit 333b661

Please sign in to comment.