Skip to content

Commit

Permalink
Ensure schema files are generated as binary files on Windows
Browse files Browse the repository at this point in the history
Otherwise they'll be generated with \r newlines in them, which breaks
checksumming and portability of schemas to other OSes.
  • Loading branch information
wchristian authored and ilmari committed May 5, 2015
1 parent f05f6b6 commit 160b07c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -5,6 +5,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader
- Document how to add perltidy markers via filter_generated_code
- Fix DB2 foreign-key introspection
- Remove dependency on List::MoreUtils and Sub::Name
- Ensure schema files are generated as binary files on Windows

0.07042 2014-08-20
- Fix unescaped left braces in regexes in tests
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/Class/Schema/Loader/Base.pm
Expand Up @@ -2187,7 +2187,7 @@ sub _write_classfile {
$self->omit_timestamp ? undef : POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime)
);

open(my $fh, '>:encoding(UTF-8)', $filename)
open(my $fh, '>:raw:encoding(UTF-8)', $filename)
or croak "Cannot open '$filename' for writing: $!";

# Write the top half and its MD5 sum
Expand Down
14 changes: 8 additions & 6 deletions t/lib/dbixcsl_dumper_tests.pm
Expand Up @@ -210,19 +210,21 @@ sub _test_dumps {
}
}

sub _dump_file_like {
sub _slurp {
my $path = shift;
open(my $dumpfh, '<', $path) or die "Failed to open '$path': $!";
open(my $dumpfh, '<:raw', $path) or die "Failed to open '$path': $!";
my $contents = do { local $/; <$dumpfh>; };
close($dumpfh);
return ($path, $contents);
}

sub _dump_file_like {
my ($path, $contents) = _slurp shift;
like($contents, $_, "$path matches $_") for @_;
}

sub _dump_file_not_like {
my $path = shift;
open(my $dumpfh, '<', $path) or die "Failed to open '$path': $!";
my $contents = do { local $/; <$dumpfh>; };
close($dumpfh);
my ($path, $contents) = _slurp shift;
unlike($contents, $_, "$path does not match $_") for @_;
}

Expand Down

1 comment on commit 160b07c

@wchristian
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the quick reaction! :D

Please sign in to comment.