X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FTestApp%2FModel%2FTangram.pm;fp=t%2Flib%2FTestApp%2FModel%2FTangram.pm;h=98e26daf81e27d274f721e183cbb7c7e9fa2c1b3;hb=1658508350f43b56a125c3d276b7af0ad7d9b8e8;hp=0000000000000000000000000000000000000000;hpb=34f62807d3de40b6dfe807e2e3e36d996a519120;p=catagits%2FCatalyst-Authentication-Store-Htpasswd.git diff --git a/t/lib/TestApp/Model/Tangram.pm b/t/lib/TestApp/Model/Tangram.pm new file mode 100644 index 0000000..98e26da --- /dev/null +++ b/t/lib/TestApp/Model/Tangram.pm @@ -0,0 +1,62 @@ +package Users; +use strict; +use warnings; +use base qw/Class::Accessor/; + +__PACKAGE__->mk_accessors(qw/username password/); + +sub new { + my ($class, %p) = @_; + bless { %p }, $class; +} + +package TestApp::Model::Tangram; +use strict; +use warnings; +use base qw/Catalyst::Model/; +use DBI; +use Tangram::Relational; +use Tangram::Storage; +use Tangram::Type::String; +use Class::C3; +use File::Temp qw/tempfile/; + +BEGIN { + __PACKAGE__->mk_accessors(qw/storage schema _sqlite_file/); +} + +sub COMPONENT { + my ($class, $app, @rest) = @_; + my $self = $class->next::method($app, @rest); + my ($fh, $fn) = tempfile; + close($fh); + $self->{_sqlite_file} = $fn; + my @dsn = ("DBI:SQLite:dbname=$fn", '', ''); + my $dbh = DBI->connect(@dsn); + $self->{schema} = Tangram::Relational->schema( { + classes => [ + Users => { + fields => { + string => [qw/username password/], + }, + }, + ], + }); + Tangram::Relational->deploy($self->schema, $dbh); + $dbh->disconnect; + $self->{storage} = Tangram::Relational->connect( + $self->schema, @dsn + ); + my $test_user = Users->new(username => 'testuser', password => 'testpass'); + $self->storage->insert($test_user); + return $self; +} + +sub DESTROY { + my ($self) = @_; + $self->storage->disconnect if $self->storage; + unlink $self->{_sqlite_file}; +} + +1; +