return [@files{sort keys %files}]
}
+method _ddl_preinstall_consume_filenames($type, $version) {
+ $self->__ddl_consume_with_prefix($type, [ $version ], 'preinstall')
+}
+
method _ddl_schema_consume_filenames($type, $version) {
$self->__ddl_consume_with_prefix($type, [ $version ], 'schema')
}
carp "$filename should define a run method that takes a schema but it didn't!";
}
} else {
- croak "A file got to deploy that wasn't sql or perl!";
+ croak "A file ($filename) got to deploy that wasn't sql or perl!";
}
}
));
}
+sub preinstall_scripts {
+ my $self = shift;
+ my $version = shift || $self->schema_version;
+
+ my @files = @{$self->_ddl_preinstall_consume_filenames(
+ $self->storage->sqlt_type,
+ $version,
+ )};
+
+ for my $filename (@files) {
+ # We ignore sql for now (till I figure out what to do with it)
+ if ( $filename =~ /^(.+)\.pl$/ ) {
+ my $package = $1;
+ my $filedata = do { local( @ARGV, $/ ) = $filename; <> };
+ # make the package name more palateable to perl
+ $package =~ s/\W/_/g;
+
+ no warnings 'redefine';
+ eval "package $package;\n\n$filedata";
+ use warnings;
+ if (my $fn = $package->can('run')) {
+ $fn->()
+ } else {
+ carp "$filename should define a run sub but it didn't!";
+ }
+ } else {
+ croak "A file ($filename) got to preinstall_scripts that wasn't sql or perl!";
+ }
+ }
+}
+
sub _prepare_install {
my $self = shift;
my $sqltargs = { %{$self->sql_translator_args}, %{shift @_} };
ok( $dm, 'DBIC::DH::DM::SQL::Translator gets instantiated correctly' );
$dm->prepare_deploy;
+
+ mkpath(catfile(qw( t sql SQLite preinstall 1.0 )));
+ open my $prerun, '>',
+ catfile(qw( t sql SQLite preinstall 1.0 003-semiautomatic.pl ));
+ print {$prerun} "sub run {use File::Touch; touch(q(foobar));}";
+ close $prerun;
+ $dm->preinstall_scripts('1.0');
+
+ ok -e 'foobar';
+
{
my $warned = 0;
local $SIG{__WARN__} = sub{$warned = 1};
bar => 'frew',
baz => 'frew',
})
- } 'schema is downpgrayyed';
+ } 'schema is downgrayyed';
$dm->upgrade_single_step([qw( 1.0 2.0 )]);
}