package DBIx::Class::Migration::RunScript::Trait::Dump; use Moose::Role; use File::Spec::Functions 'catdir', 'catfile'; use File::Path 'mkpath'; requires 'schema'; sub dump { my ($self, @sets) = @_; $ENV{DBIC_MIGRATION_FIXTURES_OBJ}->dump_config_sets({ schema => $self->schema, configs => [map { "$_.json" } @sets], directory_template => sub { my ($fixture, $params, $set) = @_; $set =~s/\.json//; my $fixture_conf_dir = catdir($ENV{DBIC_MIGRATION_FIXTURE_DIR}, $set); mkpath($fixture_conf_dir) unless -d $fixture_conf_dir; return $fixture_conf_dir; }, }); } 1; =head1 NAME DBIx::Class::Migration::RunScript::Trait::Dump - Dump fixtures =head1 SYNOPSIS use DBIx::Class::Migration::RunScript; builder { 'SchemaLoader', 'Dump', sub { shift->dump('countries'); }; }; =head1 DESCRIPTION This is a L that adds a C method to your run script. This will let you dump fixtures from your runscripts, based on previously defined fixture configurations. This might be useful to you if you are building fixtures if they don't already exist (see L) and then want to dump them as part of building up your database. For example: use DBIx::Class::Migration::RunScript; migrate { my $self = shift; if($self->set_has_fixtures('all_tables')) { $self->populate('all_tables'); } else { $self->schema ->resultset('Country') ->populate([ ['code'], ['bel'], ['deu'], ['fra'], ]); $self->dump('all_tables'); } }; In the above example if the fixture set exists and has previously been dumped we will populate the database with it. Else, we will create some data manually and then dump it so that next time it is available. This trait requires a C previously defined, such as provided by L. This trait is one of the defaults for the exported method C in L. =head1 methods This class defines the follow methods. =head2 dump Requires $arg || @args Given a fixture set (or list of sets), use L to dump them from the current database. When naming sets, you skip the '.json' extension. =head1 SEE ALSO L, L =head1 AUTHOR See L for author information =head1 COPYRIGHT & LICENSE See L for copyright and license information =cut