« DBIx/Class/Migration/SandboxDirSandboxBuilder.pm
↑ Summary
DBIx/Class/Migration/RunScript/Trait/TargetPath.pm »
| 1 | package DBIx::Class::Migration::TempDirSandboxBuilder; | ||
| 2 | |||
| 3 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use File::Temp 'tempdir'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | has migration => ( | |
| 7 | is => 'ro', | ||
| 8 | weak_ref => 1, | ||
| 9 | required => 1); | ||
| 10 | |||
| 11 | 0 | ▶ | sub build { |
|
Subroutine
build: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 12 | 0 | my $migration = shift->migration; | |
| 13 | 0 | return $migration->db_sandbox_class | |
| 14 | ->new(target_dir=>tempdir(CLEANUP=>1), | ||
| 15 | schema_class=>$migration->_infer_schema_class); | ||
| 16 | } | ||
| 17 | |||
| 18 | 1 | __PACKAGE__->meta->make_immutable; | |
| 19 | |||
| 20 | =head1 NAME | ||
| 21 | |||
| 22 | DBIx::Class::Migration::TempDirSandboxBuilder - Build a sandbox in a temporary directory | ||
| 23 | |||
| 24 | =head1 SYNOPSIS | ||
| 25 | |||
| 26 | use DBIx::Class::Migration; | ||
| 27 | |||
| 28 | my $migration = DBIx::Class::Migration->new( | ||
| 29 | schema_class => 'MyApp::Schema', | ||
| 30 | db_sandbox_builder_class => 'DBIx::Class::Migration::TempDirSandboxBuilder'); | ||
| 31 | |||
| 32 | $migration->install; | ||
| 33 | |||
| 34 | $migration->schema->resultset('User') | ||
| 35 | ->create({name=>'Test User'}); | ||
| 36 | |||
| 37 | $migration->schema->resultset('Role') | ||
| 38 | ->create({name=>'Administrator'}); | ||
| 39 | |||
| 40 | $migration->dump_named_sets('users', 'roles'); | ||
| 41 | |||
| 42 | =head1 DESCRIPTION | ||
| 43 | |||
| 44 | Helper class that creates a C<db_sandbox> in the temporary directory, and then | ||
| 45 | deletes the directory when the migration object goes out of scope. You might | ||
| 46 | wish to use this for testing. | ||
| 47 | |||
| 48 | =head1 SEE ALSO | ||
| 49 | |||
| 50 | L<DBIx::Class::Migration>. | ||
| 51 | |||
| 52 | =head1 AUTHOR | ||
| 53 | |||
| 54 | See L<DBIx::Class::Migration> for author information | ||
| 55 | |||
| 56 | =head1 COPYRIGHT & LICENSE | ||
| 57 | |||
| 58 | See L<DBIx::Class::Migration> for copyright and license information | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | |||