| 1 | package Test::Chado::FixtureLoader::Preset; | ||
| 2 | { | ||
| 3 | $Test::Chado::FixtureLoader::Preset::VERSION = 'v4.1.1'; | ||
| 4 | } | ||
| 5 | 6 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 6 | ▶ | use Test::Chado; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 6 | ▶ | use File::ShareDir qw/module_dir module_file/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 6 | ▶ | use DBIx::Class::Fixtures; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 6 | ▶ | use Archive::Tar; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 6 | ▶ | use Types::Standard qw/Str/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 6 | ▶ | use File::Temp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 6 | ▶ | use File::Spec::Functions; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 0 | ▶ | use File::Find::Rule; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 14 | use File::Basename; | ||
| 15 | |||
| 16 | has 'namespace' => ( | ||
| 17 | is => 'rw', | ||
| 18 | isa => Str, | ||
| 19 | lazy => 1, | ||
| 20 | default => 'test-chado' | ||
| 21 | ); | ||
| 22 | |||
| 23 | sub load_fixtures { | ||
| 24 | my ($self) = @_; | ||
| 25 | my $staging_temp = File::Temp->newdir; | ||
| 26 | |||
| 27 | my $preset = module_file( 'Test::Chado', 'preset.tar.bz2' ); | ||
| 28 | my $archive = Archive::Tar->new($preset); | ||
| 29 | $archive->setcwd($staging_temp); | ||
| 30 | $archive->extract; | ||
| 31 | |||
| 32 | my $fixture = DBIx::Class::Fixtures->new( | ||
| 33 | { config_dir => | ||
| 34 | catdir( module_dir('Test::Chado'), 'fixture_config' ) | ||
| 35 | } | ||
| 36 | ); | ||
| 37 | for my $config_file ( sort $fixture->available_config_sets ) { | ||
| 38 | my $fixture_dir = catdir( $staging_temp, 'fixtures', | ||
| 39 | ( ( split /\./, $config_file ) )[0] ); | ||
| 40 | $fixture->populate( | ||
| 41 | { directory => $fixture_dir, | ||
| 42 | no_deploy => 1, | ||
| 43 | schema => $self->dynamic_schema | ||
| 44 | } | ||
| 45 | ); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | sub load_custom_fixtures { | ||
| 50 | my ( $self, $preset ) = @_; | ||
| 51 | |||
| 52 | die "could not find $preset file\n" if !-e $preset; | ||
| 53 | |||
| 54 | my $staging_temp = File::Temp->newdir; | ||
| 55 | my $archive = Archive::Tar->new($preset); | ||
| 56 | $archive->setcwd($staging_temp); | ||
| 57 | $archive->extract; | ||
| 58 | |||
| 59 | my $config_dir = catdir( $staging_temp, 'config' ); | ||
| 60 | my $fixture = DBIx::Class::Fixtures->new( { config_dir => $config_dir } ); | ||
| 61 | |||
| 62 | my @all_configs = map { basename $_} | ||
| 63 | File::Find::Rule->file->name(qr/\.json$/)->in($config_dir); | ||
| 64 | |||
| 65 | for my $config_file (@all_configs) { | ||
| 66 | my $fixture_dir = catdir( $staging_temp, 'fixtures', | ||
| 67 | ( ( split /\./, $config_file ) )[0] ); | ||
| 68 | $fixture->populate( | ||
| 69 | { directory => $fixture_dir, | ||
| 70 | no_deploy => 1, | ||
| 71 | schema => $self->dynamic_schema | ||
| 72 | } | ||
| 73 | ); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | with 'Test::Chado::Role::Helper::WithBcs'; | ||
| 78 | |||
| 79 | 1; | ||
| 80 | |||
| 81 | __END__ | ||