Checking in changes prior to tagging of version 1.000. Changelog diff is:
[catagits/Catalyst-Authentication-Store-Htpasswd.git] / t / lib / TestApp / Model / Tangram.pm
CommitLineData
16585083 1package Users;
2use strict;
3use warnings;
4use base qw/Class::Accessor/;
5
6__PACKAGE__->mk_accessors(qw/username password/);
7
8sub new {
9 my ($class, %p) = @_;
10 bless { %p }, $class;
11}
12
13package TestApp::Model::Tangram;
14use strict;
15use warnings;
16use base qw/Catalyst::Model/;
17use DBI;
18use Tangram::Relational;
19use Tangram::Storage;
20use Tangram::Type::String;
21use Class::C3;
22use File::Temp qw/tempfile/;
23
24BEGIN {
25 __PACKAGE__->mk_accessors(qw/storage schema _sqlite_file/);
26}
27
28sub COMPONENT {
29 my ($class, $app, @rest) = @_;
30 my $self = $class->next::method($app, @rest);
31 my ($fh, $fn) = tempfile;
32 close($fh);
33 $self->{_sqlite_file} = $fn;
34 my @dsn = ("DBI:SQLite:dbname=$fn", '', '');
35 my $dbh = DBI->connect(@dsn);
36 $self->{schema} = Tangram::Relational->schema( {
37 classes => [
38 Users => {
39 fields => {
40 string => [qw/username password/],
41 },
42 },
43 ],
44 });
45 Tangram::Relational->deploy($self->schema, $dbh);
46 $dbh->disconnect;
47 $self->{storage} = Tangram::Relational->connect(
48 $self->schema, @dsn
49 );
50 my $test_user = Users->new(username => 'testuser', password => 'testpass');
51 $self->storage->insert($test_user);
52 return $self;
53}
54
55sub DESTROY {
56 my ($self) = @_;
57 $self->storage->disconnect if $self->storage;
58 unlink $self->{_sqlite_file};
59}
60
611;
62