Revision history for Perl extension DBIx::Class::Schema::Loader
+ - do not delete default custom content comment and ending 1; from custom
+ content in files that are being renamed (RT#70507)
- use MooseX::MarkAsMethods instead of namespace::autoclean for the
use_moose option, this protects operator overloads, only_autoclean
option added for the old behavior
my $custom_content = $old_custom || '';
- # prepend extra custom content from a *renamed* class (singularization effect)
+ # Use custom content from a renamed class, the class names in it are
+ # rewritten below.
if (my $renamed_class = $self->_upgrading_classes->{$class}) {
my $old_filename = $self->_get_dump_filename($renamed_class);
if (-f $old_filename) {
- my $extra_custom = ($self->_parse_generated_file ($old_filename))[4];
-
- $extra_custom =~ s/\n\n# You can replace.*\n1;\n//;
-
- $custom_content = join ("\n", '', $extra_custom, $custom_content)
- if $extra_custom;
+ $custom_content = ($self->_parse_generated_file ($old_filename))[4];
unlink $old_filename;
}
use Exporter 'import';
use Data::Dumper ();
-our @EXPORT_OK = qw/split_name dumper dumper_squashed eval_package_without_redefine_warnings class_path no_warnings warnings_exist warnings_exist_silent slurp_file/;
+our @EXPORT_OK = qw/split_name dumper dumper_squashed eval_package_without_redefine_warnings class_path no_warnings warnings_exist warnings_exist_silent slurp_file write_file/;
use constant BY_CASE_TRANSITION_V7 =>
qr/(?<=[[:lower:]\d])[\W_]*(?=[[:upper:]])|[\W_]+/;
return $data;
}
+sub write_file($$) {
+ open my $fh, '>:encoding(UTF-8)', shift;
+ print $fh shift;
+ close $fh;
+}
+
1;
# vim:et sts=4 sw=4 tw=0:
-use warnings;
use strict;
-
-use File::Temp ();
+use warnings;
use Test::More;
-
+use DBIx::Class::Schema::Loader::Utils qw/slurp_file write_file/;
+use namespace::clean;
+use File::Temp ();
use lib qw(t/lib);
use dbixcsl_dumper_tests;
my $t = 'dbixcsl_dumper_tests';
],
);
+# test fix for RT#70507 (end comment and 1; gets lost if left with actual
+# custom content)
+
+$t->dump_test(
+ classname => 'DBICTest::DumpMore::Upgrade',
+ options => {
+ use_namespaces => 0,
+ },
+);
+
+my $file = $t->class_file('DBICTest::DumpMore::Upgrade::Foo');
+
+my $code = slurp_file $file;
+
+$code =~ s/(?=# You can replace)/sub custom_method { 'custom_method works' }\n0;\n\n/;
+
+write_file $file, $code;
+
+$t->dump_test(
+ classname => 'DBICTest::DumpMore::Upgrade',
+ options => {
+ use_namespaces => 1,
+ },
+ regexes => {
+ 'Result/Foo' => [
+ qr/sub custom_method { 'custom_method works' }\n0;\n\n# You can replace.*\n1;\n\z/,
+ ],
+ },
+);
+
done_testing;
# vim:et sts=4 sw=4 tw=0:
rmtree($DUMP_PATH, 1, 1);
}
-sub append_to_class {
- my ($self, $class, $string) = @_;
+sub class_file {
+ my ($self, $class) = @_;
+
$class =~ s{::}{/}g;
$class = $DUMP_PATH . '/' . $class . '.pm';
+
+ return $class;
+}
+
+sub append_to_class {
+ my ($self, $class, $string) = @_;
+
+ $class = $self->class_file($class);
+
open(my $appendfh, '>>', $class) or die "Failed to open '$class' for append: $!";
+
print $appendfh $string;
+
close($appendfh);
}