Skip to content

Commit

Permalink
inflate/deflateの処理をSchema側に追い出した
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.coderepos.org/share/lang/perl/DBIx-Skinny/trunk@27822 d0d07461-0603-4401-acd4-de1884942a52
  • Loading branch information
nekokak committed Jan 3, 2009
1 parent f4a4249 commit e0a421f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
18 changes: 4 additions & 14 deletions lib/DBIx/Skinny.pm
Expand Up @@ -181,13 +181,8 @@ sub insert {
$class->call_schema_trigger('pre_insert', $table, $args);

# deflate
my $inflate_rules = $class->schema->inflate_rules;
for my $rule (keys %{$inflate_rules}) {
for my $col (keys %{$args}) {
if ($col =~ /$rule/ and my $code = $inflate_rules->{$rule}->{deflate}) {
$args->{$col} = $code->($args->{$col});
}
}
for my $col (keys %{$args}) {
$args->{$col} = $class->schema->call_deflate($col, $args->{$col});
}

my (@cols,@bind);
Expand Down Expand Up @@ -217,13 +212,8 @@ sub update {
$class->call_schema_trigger('pre_update', $table, $args);

# deflate
my $inflate_rules = $class->schema->inflate_rules;
for my $rule (keys %{$inflate_rules}) {
for my $col (keys %{$args}) {
if ($col =~ /$rule/ and my $code = $inflate_rules->{$rule}->{deflate}) {
$args->{$col} = $code->($args->{$col});
}
}
for my $col (keys %{$args}) {
$args->{$col} = $class->schema->call_deflate($col, $args->{$col});
}

my (@set,@bind);
Expand Down
11 changes: 2 additions & 9 deletions lib/DBIx/Skinny/Row.pm
Expand Up @@ -25,16 +25,9 @@ sub _razy_get_data {

return sub {
my $self = shift;
my $data = $self->get_column($col);

# inflate
my $inflate_rules = $self->skinny->schema->inflate_rules;
for my $rule (keys %{$inflate_rules}) {
if ($col =~ /$rule/ and my $code = $inflate_rules->{$rule}->{inflate}) {
$data = $code->($data);
}
}
return $data;
my $data = $self->get_column($col);
$self->skinny->schema->call_inflate($col, $data);
};
}

Expand Down
28 changes: 26 additions & 2 deletions lib/DBIx/Skinny/Schema.pm
Expand Up @@ -17,8 +17,8 @@ sub import {
install_table
schema pk columns schema_info
install_inflate_rule
inflate deflate
callback
inflate deflate call_inflate call_deflate
callback _do_inflate
trigger call_trigger
install_utf8_columns
is_utf8_column utf8_on utf8_off
Expand Down Expand Up @@ -115,6 +115,30 @@ sub deflate (&) {
}->{deflate} = $code;
}

sub call_inflate {
my $class = shift;

return $class->_do_inflate('inflate', @_);
}

sub call_deflate {
my $class = shift;

return $class->_do_inflate('deflate', @_);
}

sub _do_inflate {
my ($class, $key, $col, $data) = @_;

my $inflate_rules = $class->inflate_rules;
for my $rule (keys %{$inflate_rules}) {
if ($col =~ /$rule/ and my $code = $inflate_rules->{$rule}->{$key}) {
$data = $code->($data);
}
}
return $data;
}

sub callback (&) { shift }

sub install_utf8_columns (@) {
Expand Down
4 changes: 3 additions & 1 deletion tools/benchmark.pl
Expand Up @@ -26,6 +26,8 @@
2 wallclock secs ( 2.01 usr + 0.01 sys = 2.02 CPU) @ 29.21/s (n=59)
2008-01-02 15:14
2 wallclock secs ( 2.15 usr + 0.00 sys = 2.15 CPU) @ 28.84/s (n=62)
2008-01-03 1435
2008-01-03 14:35
2 wallclock secs ( 2.00 usr + 0.01 sys = 2.01 CPU) @ 43.28/s (n=87)
2008-01-03 14:50
2 wallclock secs ( 2.00 usr + 0.00 sys = 2.00 CPU) @ 43.50/s (n=87)

0 comments on commit e0a421f

Please sign in to comment.