1DBICx::TestDatabase::SuUbscelrasCso(n3t)ributed Perl DocDuBmIeCnxt:a:tTieosntDatabase::Subclass(3)
2
3
4
6 DBICx::TestDatabase::Subclass - a DBICx::TestDatabase you can add your
7 own methods to
8
10 Your test database subclass:
11
12 package MyApp::TestDatabase
13 use base qw(DBICx::TestDatabase::Subclass MyApp::Schema);
14
15 sub foo {
16 my $self = shift;
17 return $self->resultset('Foo')->create({ foo => 'bar' });
18 }
19
20 Later:
21
22 use MyApp::TestDatabase;
23 my $schema = MyApp::TestDatabase->connect;
24 my $foo_row = $schema->foo; # MyApp::TestDatabase::foo
25 my $bars = $schema->resultset('Bar'); # MyApp::Schema::resultset
26
28 Sometimes DBICx::TestDatabase doesn't give you enough control over the
29 object returned. This module lets you create a custom test database
30 class.
31
33 connect
34 This method creates the temporary database and returns the connection.
35 If your subclass needs to change the way connect works, do something
36 like this:
37
38 sub connect {
39 my ($class) = @_;
40
41 say 'This happens before we create the test database.';
42 my $schema = $class->next::method;
43 say '$schema is the temporary test database';
44
45 return $schema;
46 }
47
49 If you want a simple test database based on a DBIC schema, just use
50 DBICx::TestDatabase.
51
53 Jonathan Rockway "<jrockway@cpan.org>"
54
56 Copyright (c) 2007 Jonathan Rockway.
57
58 This program is free software. You may use, modify, and redistribute
59 it under the same terms as Perl itself.
60
61
62
63perl v5.32.0 2020-07-28 DBICx::TestDatabase::Subclass(3)