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

filter: Statementstmt 61.1% 11 / 18 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 59.2% 16 / 27 CC 3 SCAR 13.5
CC
3
Cov
55%
populate
6.0
set_has_fixtures
6.0
BEGIN
1.0
CRAP 3.9
« Test/DBIx/Class/FixtureCommand/Population.pm ↑ Summary DBIx/Class/Migration.pm »
1 package DBIx::Class::Migration::RunScript::Trait::Populate;
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 JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 requires 'schema';
8  
9 0 ▶sub populate {
Subroutine populate: not called CC=2 SCAR=17.9
Pod documented
10 0 my ($self, @sets) = @_;
11  
12 my $fixtures_init_args =
13 0 JSON::MaybeXS->new->decode( $ENV{DBIC_MIGRATION_FIXTURES_INIT_ARGS} );
14 my $fixtures_obj =
15 0 $ENV{DBIC_MIGRATION_FIXTURES_CLASS}->new($fixtures_init_args);
16  
17 0 foreach my $set(@sets) {
18 $fixtures_obj->populate({
19 no_deploy => 1,
20 schema => $self->schema,
21 0 directory => catdir($ENV{DBIC_MIGRATION_FIXTURE_DIR}, $set) });
22 }
23 }
24  
25 0 ▶sub set_has_fixtures {
Subroutine set_has_fixtures: not called CC=2 SCAR=17.9
Pod documented
26 0 my ($self, $set_to_check) = @_;
27 0 ▶ return -d catdir($ENV{DBIC_MIGRATION_FIXTURE_DIR}, $set_to_check) ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
-d catdir($ENV{'DBIC_MIGRATION_FIXTURE_DIR'}, $set_to_check) ? : 0 0 0
28 }
29  
30 2 1;
31  
32 =head1 NAME
33  
34 DBIx::Class::Migration::RunScript::Trait::Populate - Populate fixtures
35 =head1 SYNOPSIS
36  
37 use DBIx::Class::Migration::RunScript;
38  
39 builder {
40 'SchemaLoader',
41 'Populate',
42 sub {
43 shift->populate('countries');
44 };
45 };
46  
47 =head1 DESCRIPTION
48  
49 This is a L<Moo::Role> that adds a C<populate> method to your run script.
50 This allows you to access any of your previously dumped fixtures. You might
51 find this useful when installing a database that was previously setup.
52  
53 This trait requires a C<schema> previously defined, such as provided by
54 L<DBIx::Class::Migration::RunScript::Trait::SchemaLoader>.
55  
56 =head1 methods
57  
58 This class defines the follow methods.
59  
60 =head2 populate
61  
62 Requires $arg || @args
63  
64 Given a fixture set (or list of sets), use L<DBIx::Class::Fixtures> to populate
65 them to the current database.
66  
67 When naming sets, you skip the '.json' extension.
68  
69 =head2 set_has_fixtures
70  
71 Requires $arg
72  
73 Given a set name, returns a boolean about if that set actually has fixtures
74 previously dumped.
75  
76 =head1 SEE ALSO
77  
78 L<DBIx::Class::Migration>, L<DBIx::Class::Migration::RunScript>
79  
80 =head1 AUTHOR
81  
82 See L<DBIx::Class::Migration> for author information
83  
84 =head1 COPYRIGHT & LICENSE
85  
86 See L<DBIx::Class::Migration> for copyright and license information
87  
88 =cut
89  
90  
« Test/DBIx/Class/FixtureCommand/Population.pm ↑ Summary DBIx/Class/Migration.pm »