Skip to content

Instantly share code, notes, and snippets.

@yappo
Created December 21, 2012 04:59
Show Gist options
  • Save yappo/4350711 to your computer and use it in GitHub Desktop.
Save yappo/4350711 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
package Model {
use parent 'Teng';
}
package Model::Schema {
use Teng::Schema::Declare;
table {
name 'teng';
pk 'id';
columns qw( id at );
inflate at => sub {
my $val = shift;
"at = $val";
};
deflate at => sub {
my $val = shift;
$val =~ s/^at = // or die 'bad format';
$val;
};
};
}
package main {
use Test::More;
use Teng;
my $db = Model->new(
connect_info => [ 'dbi:SQLite:dbname=:memory:' ]
);
$db->dbh->do(q{CREATE TABLE teng ( id INTEGER PRIMARY KEY, at INTEGER)});
$db->insert( 'teng', { id => 1, at => 'at = 1000' } );
my $row = $db->single( 'teng', { id => 1 } );
subtest 'ok pattern' => sub {
is $row->at, 'at = 1000';
$row->at(10);
is $row->at, 'at = 10';
$row->update({ at => 'at = 1' });
is $row->at, 'at = 1';
$row->update({ at => 'at = 1' });
is $row->at, 'at = 1';
};
subtest 'ここのサブテスト通るの bug?' => sub {
$row->at(31);
eval {
$row->update;
};
like $@, qr/bad format/; # deflate のなかで die させてる
};
done_testing;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment