DBICx::...Subclass(3)

πŸ’– DBICx::...Subclass(3) β€” bestie edition πŸ’–

okay so this is the DBICx::...Subclass(3) page from User Contributed Perl Documentation, and it’s literally here to let you build a test database class that’s yours. No cap. πŸ¦‹

πŸŽ€ NAME πŸŽ€

DBICx::TestDatabase::Subclass - a DBICx::TestDatabase you can add your own methods to. That’s the whole assignment, bestie. πŸ’…

✨ SYNOPSIS ✨

Your test database subclass:

package MyApp::TestDatabase
use base qw(DBICx::TestDatabase::Subclass MyApp::Schema);

sub foo {
   my $self = shift;
   return $self->resultset('Foo')->create({ foo => 'bar' });
}

Later:

use MyApp::TestDatabase;
my $schema = MyApp::TestDatabase->connect;
my $foo_row = $schema->foo; # MyApp::TestDatabase::foo
my $bars = $schema->resultset('Bar'); # MyApp::Schema::resultset

🌸 DESCRIPTION 🌸

Sometimes DBICx::TestDatabase doesn't give you enough control over the object returned. This module lets you create a custom test database class. It’s giving β€œI want it my way” and honestly? Iconic. 🫢

πŸ’… METHODS πŸ’…

πŸ’– connect πŸ’–

This method creates the temporary database and returns the connection. If your subclass needs to change the way connect works, do something like this:

sub connect {
    my ($class) = @_;

    say 'This happens before we create the test database.';
    my $schema = $class->next::method;
    say '$schema is the temporary test database';

    return $schema;
}

πŸ‘€ SEE ALSO πŸ‘€

If you want a simple test database based on a DBIC schema, just use DBICx::TestDatabase. Easy. Slay. πŸ’–

πŸ’œ AUTHOR πŸ’œ

Jonathan Rockway "<jrockway@cpan.org>"

πŸŽ€ LICENSE πŸŽ€

Copyright (c) 2007 Jonathan Rockway.

This program is free software. You may use, modify, and redistribute it under the same terms as Perl itself.


that’s the whole page, bestie β€” source/version perl v5.42.0, dated 2017-10-12, manual name DBICx::...Subclass(3). 🌈✨

πŸ“¦ where this page comes from