use Class::Unload;
use File::Temp qw/tempfile tempdir/;
use IO::File;
+use File::Slurp 'slurp';
use DBIx::Class::Schema::Loader ();
use lib qw(t/lib);
use make_dbictest_db2;
# test upgraded dynamic schema with external content loaded
{
- my $temp_dir = tempdir;
+ my $temp_dir = tempdir(CLEANUP => 1);
push @INC, $temp_dir;
my $external_result_dir = join '/', $temp_dir, split /::/, $SCHEMA_CLASS;
run_v5_tests($res);
- rmtree $temp_dir;
pop @INC;
}
# test upgraded dynamic schema with use_namespaces with external content loaded
{
- my $temp_dir = tempdir;
+ my $temp_dir = tempdir(CLEANUP => 1);
push @INC, $temp_dir;
my $external_result_dir = join '/', $temp_dir, split /::/, $SCHEMA_CLASS;
run_v5_tests($res);
- rmtree $temp_dir;
pop @INC;
}
# test upgraded static schema with external content loaded
{
- my $temp_dir = tempdir;
+ my $temp_dir = tempdir(CLEANUP => 1);
push @INC, $temp_dir;
my $external_result_dir = join '/', $temp_dir, split /::/, $SCHEMA_CLASS;
'names are translated in static schema';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/package ${SCHEMA_CLASS}::Quux;/,
'package line translated correctly from external custom content in static dump';
like $code, qr/sub a_method { 'dongs' }/,
'external custom content loaded into static dump correctly';
- rmtree $temp_dir;
pop @INC;
}
my $quuxs_pm = $schema->_loader
->_get_dump_filename($res->{classes}{quuxs});
{
- local ($^I, @ARGV) = ('', $quuxs_pm);
+ local ($^I, @ARGV) = ('.bak', $quuxs_pm);
while (<>) {
if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
print;
print;
}
}
+ close ARGV;
+ unlink "${quuxs_pm}.bak" or die $^E;
}
# Rerun the loader in backcompat mode to make sure it's still in backcompat
'unsingularized class names in custom content are translated';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/sub a_method { 'mtfnpy' }/,
'custom content from unsingularized Result loaded into static dump correctly';
my $quuxs_pm = $schema->_loader
->_get_dump_filename($res->{classes}{quuxs});
{
- local ($^I, @ARGV) = ('', $quuxs_pm);
+ local ($^I, @ARGV) = ('.bak', $quuxs_pm);
while (<>) {
if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
print;
print;
}
}
+ close ARGV;
+ unlink "${quuxs_pm}.bak" or die $^E;
}
# now upgrade the schema
'unsingularized class names in custom content are translated';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/sub a_method { 'mtfnpy' }/,
'custom content from unsingularized Result loaded into static dump correctly';
# test running against v4 schema with load_namespaces, upgrade to v5 but
# downgrade to load_classes, with external content
{
- my $temp_dir = tempdir;
+ my $temp_dir = tempdir(CLEANUP => 1);
push @INC, $temp_dir;
my $external_result_dir = join '/', $temp_dir, split /::/,
my $quuxs_pm = $schema->_loader
->_get_dump_filename($res->{classes}{quuxs});
{
- local ($^I, @ARGV) = ('', $quuxs_pm);
+ local ($^I, @ARGV) = ('.bak', $quuxs_pm);
while (<>) {
if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
print;
print;
}
}
+ close ARGV;
+ unlink "${quuxs_pm}.bak" or die $^E;
}
# now upgrade the schema to v5 but downgrade to load_classes
'names are translated in static schema';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/sub a_method { 'mtfnpy' }/,
'custom content from unsingularized Result loaded into static dump correctly';
like $code, qr/sub b_method { 'dongs' }/,
'external content from unsingularized Result loaded into static dump correctly';
- rmtree $temp_dir;
pop @INC;
}
my $quuxs_pm = $schema->_loader
->_get_dump_filename($res->{classes}{quuxs});
{
- local ($^I, @ARGV) = ('', $quuxs_pm);
+ local ($^I, @ARGV) = ('.bak', $quuxs_pm);
while (<>) {
if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
print;
print;
}
}
+ close ARGV;
+ unlink "${quuxs_pm}.bak" or die $^E;
}
# test that with no use_namespaces option, there is a warning and
'un-namespaced class names in custom content are translated';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/sub a_method { 'mtfnpy' }/,
'custom content from un-namespaced Result loaded into static dump correctly';
my $quuxs_pm = $schema->_loader
->_get_dump_filename($res->{classes}{quuxs});
{
- local ($^I, @ARGV) = ('', $quuxs_pm);
+ local ($^I, @ARGV) = ('.bak', $quuxs_pm);
while (<>) {
if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
print;
print;
}
}
+ close ARGV;
+ unlink "${quuxs_pm}.bak" or die $^E;
}
# test that with no use_namespaces option, use_namespaces is preserved
'downgrade';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/sub a_method { 'mtfnpy' }/,
'custom content from namespaced Result loaded into static dump correctly '.
my $quuxs_pm = $schema->_loader
->_get_dump_filename($res->{classes}{quuxs});
{
- local ($^I, @ARGV) = ('', $quuxs_pm);
+ local ($^I, @ARGV) = ('.bak', $quuxs_pm);
while (<>) {
if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
print;
print;
}
}
+ close ARGV;
+ unlink "${quuxs_pm}.bak" or die $^E;
}
# test that with no use_namespaces option, use_namespaces is preserved, and
'downgrade';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/sub a_method { 'mtfnpy' }/,
'custom content from namespaced Result loaded into static dump correctly '.
{
rmtree $DUMP_DIR;
mkdir $DUMP_DIR;
- my $temp_dir = tempdir;
+ my $temp_dir = tempdir(CLEANUP => 1);
push @INC, $temp_dir;
my $external_result_dir = join '/', $temp_dir, split /::/,
my $quuxs_pm = $schema->_loader
->_get_dump_filename($res->{classes}{quuxs});
{
- local ($^I, @ARGV) = ('', $quuxs_pm);
+ local ($^I, @ARGV) = ('.bak', $quuxs_pm);
while (<>) {
if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
print;
print;
}
}
+ close ARGV;
+ unlink "${quuxs_pm}.bak" or die $^E;
}
# Rewrite implicit 'Result' to 'MyResult'
'class names in custom content are translated when rewriting result_namespace';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/sub a_method { 'mtfnpy' }/,
'custom content from namespaced Result loaded into static dump correctly '.
'result_namespace';
$file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
- $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ $code = slurp $file;
like $code, qr/sub a_method { 'mtfnpy' }/,
'custom content from namespaced Result loaded into static dump correctly '.
like $code, qr/sub c_method { 'dongs' }/,
'external content from unsingularized Result loaded into static dump correctly';
- rmtree $temp_dir;
pop @INC;
}
my $schema = $res->{schema};
my $file = $schema->_loader->_get_dump_filename($SCHEMA_CLASS);
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
my ($dumped_ver) =
$code =~ /^# Created by DBIx::Class::Schema::Loader v(\S+)/m;
my $bar_pm = $schema->_loader
->_get_dump_filename($res->{classes}{bar});
{
- local ($^I, @ARGV) = ('', $bar_pm);
+ local ($^I, @ARGV) = ('.bak', $bar_pm);
while (<>) {
if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
print;
print;
}
}
+ close ARGV;
+ unlink "${bar_pm}.bak" or die $^E;
}
# now upgrade the schema
'name are translated';
my $file = $schema->_loader->_get_dump_filename($res->{classes}{bar});
- my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+ my $code = slurp $file;
like $code, qr/sub a_method { 'lalala' }/,
'custom content from Result with unchanged name loaded into static dump ' .