DBIx/Class/Migration/RunScript/Trait/Dump.pm

filter: Statementstmt 58.3% 14 / 24 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 1 / 1 totaltotal 57.5% 19 / 33 CC 2 SCAR 9.4
CC
2
Cov
54%
__ANON__
6.0
dump
2.0
BEGIN
1.0
CRAP 2.6
« DBIx/Class/Migration/ShareDirBuilder.pm ↑ Summary DBIx/Class/Migration/Population.pm »
1 package DBIx::Class::Migration::RunScript::Trait::Dump;
2  
3 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use File::Spec::Functions 'catdir', 'catfile';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use File::Path 'mkpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 requires 'schema';
9  
10 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
Pod documented
11 0 my ($self, @sets) = @_;
12  
13 my $fixtures_init_args =
14 0 JSON::MaybeXS->new->decode( $ENV{DBIC_MIGRATION_FIXTURES_INIT_ARGS} );
15 my $fixtures_obj =
16 0 $ENV{DBIC_MIGRATION_FIXTURES_CLASS}->new($fixtures_init_args);
17  
18 $fixtures_obj->dump_config_sets({
19 schema => $self->schema,
20 0 configs => [map { "$_.json" } @sets],
21 0 ▶ directory_template => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
22 0 my ($fixture, $params, $set) = @_;
23 0 $set =~s/\.json//;
24 0 my $fixture_conf_dir = catdir($ENV{DBIC_MIGRATION_FIXTURE_DIR}, $set);
25 0 ▶ mkpath($fixture_conf_dir)
Branch: 1 branch
BranchTrueFalseTotal
unless -d $fixture_conf_dir 0 0 0
26 unless -d $fixture_conf_dir;
27 0 return $fixture_conf_dir;
28 },
29 0 });
30 }
31  
32 2 1;
33  
34 =head1 NAME
35  
36 DBIx::Class::Migration::RunScript::Trait::Dump - Dump fixtures
37  
38 =head1 SYNOPSIS
39  
40 use DBIx::Class::Migration::RunScript;
41  
42 builder {
43 'SchemaLoader',
44 'Dump',
45 sub {
46 shift->dump('countries');
47 };
48 };
49  
50 =head1 DESCRIPTION
51  
52 This is a L<Moo::Role> that adds a C<dump> method to your run script. This
53 will let you dump fixtures from your runscripts, based on previously defined
54 fixture configurations.
55  
56 This might be useful to you if you are building fixtures if they don't already
57 exist (see L<DBIx::Class::Migration::RunScript::Trait::Populate>) and then want
58 to dump them as part of building up your database. For example:
59  
60 use DBIx::Class::Migration::RunScript;
61  
62 migrate {
63 my $self = shift;
64 if($self->set_has_fixtures('all_tables')) {
65 $self->populate('all_tables');
66 } else {
67 $self->schema
68 ->resultset('Country')
69 ->populate([
70 ['code'],
71 ['bel'],
72 ['deu'],
73 ['fra'],
74 ]);
75  
76 $self->dump('all_tables');
77 }
78 };
79  
80 In the above example if the fixture set exists and has previously been dumped
81 we will populate the database with it. Else, we will create some data manually
82 and then dump it so that next time it is available.
83  
84 This trait requires a C<schema> previously defined, such as provided by
85 L<DBIx::Class::Migration::RunScript::Trait::SchemaLoader>.
86  
87 This trait is one of the defaults for the exported method C<migrate> in
88 L<DBIx::Class::Migration::RunScript>.
89  
90 =head1 methods
91  
92 This class defines the follow methods.
93  
94 =head2 dump
95  
96 Requires $arg || @args
97  
98 Given a fixture set (or list of sets), use L<DBIx::Class::Fixtures> to dump
99 them from the current database.
100  
101 When naming sets, you skip the '.json' extension.
102  
103 =head1 SEE ALSO
104  
105 L<DBIx::Class::Migration>, L<DBIx::Class::Migration::RunScript>
106  
107 =head1 AUTHOR
108  
109 See L<DBIx::Class::Migration> for author information
110  
111 =head1 COPYRIGHT & LICENSE
112  
113 See L<DBIx::Class::Migration> for copyright and license information
114  
115 =cut
116  
117  
« DBIx/Class/Migration/ShareDirBuilder.pm ↑ Summary DBIx/Class/Migration/Population.pm »