Revision history for Perl extension DBIx::Class::Schema::Loader
+ - support DOS line endings on *nix and *nix line ending on Win32
- add quiet option
- $schema->loader is now a public method
- add schema_components option
use Class::Unload;
use Class::Inspector ();
use Scalar::Util 'looks_like_number';
-use File::Slurp 'read_file';
-use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed eval_package_without_redefine_warnings class_path/;
+use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed eval_package_without_redefine_warnings class_path slurp_file/;
use DBIx::Class::Schema::Loader::Optional::Dependencies ();
use Try::Tiny;
use DBIx::Class ();
naming_set
/);
+my $CURRENT_V = 'v7';
+
+my @CLASS_ARGS = qw(
+ schema_components schema_base_class result_base_class
+ additional_base_classes left_base_classes additional_classes components
+ result_roles
+);
+
+my $LF = "\x0a";
+my $CRLF = "\x0d\x0a";
+
=head1 NAME
DBIx::Class::Schema::Loader::Base - Base DBIx::Class::Schema::Loader Implementation.
=cut
-my $CURRENT_V = 'v7';
-
-my @CLASS_ARGS = qw(
- schema_components schema_base_class result_base_class
- additional_base_classes left_base_classes additional_classes components
- result_roles
-);
-
# ensure that a peice of object data is a valid arrayref, creating
# an empty one or encapsulating whatever's there.
sub _ensure_arrayref {
warn qq/# Loaded external class definition for '$class'\n/
if $self->debug;
- my $code = $self->_rewrite_old_classnames(scalar read_file($real_inc_path, binmode => ':encoding(UTF-8)'));
+ my $code = $self->_rewrite_old_classnames(slurp_file $real_inc_path);
if ($self->dynamic) { # load the class too
eval_package_without_redefine_warnings($class, $code);
}
if ($old_real_inc_path) {
- my $code = read_file($old_real_inc_path, binmode => ':encoding(UTF-8)');
+ my $code = slurp_file $old_real_inc_path;
$self->_ext_stmt($class, <<"EOF");
eval_package_without_redefine_warnings ($class, "require $class");
}
catch {
- my $source = read_file($self->_get_dump_filename($class), binmode => ':encoding(UTF-8)');
+ my $source = slurp_file $self->_get_dump_filename($class);
die "Failed to reload class $class: $_.\n\nCLASS SOURCE:\n\n$source";
};
}
or croak "Cannot open '$fn' for reading: $!";
my $mark_re =
- qr{^(# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:)([A-Za-z0-9/+]{22})\n};
+ qr{^(# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:)([A-Za-z0-9/+]{22})\r?\n};
my ($md5, $ts, $ver, $gen);
while(<$fh>) {
$md5 = $2;
# Pull out the version and timestamp from the line above
- ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader v(.*?) @ (.*?)\Z/m;
+ ($ver, $ts) = $gen =~ m/^# Created by DBIx::Class::Schema::Loader v(.*?) @ (.*?)\r?\Z/m;
$gen .= $pre_md5;
croak "Checksum mismatch in '$fn', the auto-generated part of the file has been modified outside of this loader. Aborting.\nIf you want to overwrite these modifications, set the 'overwrite_modifications' loader option.\n"
my $custom = do { local $/; <$fh> }
if $md5;
- close ($fh);
+ $custom ||= '';
+ $custom =~ s/$CRLF|$LF/\n/g;
+
+ close $fh;
return ($gen, $md5, $ver, $ts, $custom);
}
use Scalar::Util 'weaken';
use Lingua::EN::Inflect::Phrase ();
use Lingua::EN::Tagger ();
-use DBIx::Class::Schema::Loader::Utils 'split_name';
-use File::Slurp 'read_file';
+use DBIx::Class::Schema::Loader::Utils qw/split_name slurp_file/;
use Try::Tiny;
use Class::Unload ();
use Class::Inspector ();
my $class = "${remote_class}Temporary";
if (not Class::Inspector->loaded($class)) {
- my $code = read_file($existing_remote_file, binmode => ':encoding(UTF-8)');
+ my $code = slurp_file $existing_remote_file;
$code =~ s/(?<=package $remote_class)/Temporary/g;
use warnings;
use Data::Dumper ();
use Test::More;
+use File::Slurp 'read_file';
use namespace::clean;
use Exporter 'import';
-our @EXPORT_OK = qw/split_name dumper dumper_squashed eval_package_without_redefine_warnings class_path no_warnings warnings_exist warnings_exist_silent/;
+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/;
use constant BY_CASE_TRANSITION =>
qr/(?<=[[:lower:]\d])[\W_]*(?=[[:upper:]])|[\W_]+/;
use constant BY_NON_ALPHANUM =>
qr/[\W_]+/;
+my $LF = "\x0a";
+my $CRLF = "\x0d\x0a";
+
sub split_name($) {
my $name = shift;
ok $matched, $test_name;
}
+sub slurp_file($) {
+ my $data = read_file(shift, binmode => ':encoding(UTF-8)');
+
+ $data =~ s/$CRLF|$LF/\n/g;
+
+ return $data;
+}
1;
# vim:et sts=4 sw=4 tw=0:
use strict;
-use lib qw(t/lib);
+use warnings;
+use utf8;
use DBIx::Class::Schema::Loader 'make_schema_at';
-use DBIx::Class::Schema::Loader::Utils 'no_warnings';
-use dbixcsl_common_tests;
+use DBIx::Class::Schema::Loader::Utils qw/no_warnings slurp_file/;
use Test::More;
use Test::Exception;
-use File::Slurp 'slurp';
-use utf8;
-use Encode 'decode';
use Try::Tiny;
+use namespace::clean;
+use lib qw(t/lib);
+use dbixcsl_common_tests ();
my $dsn = $ENV{DBICTEST_PG_DSN} || '';
my $user = $ENV{DBICTEST_PG_USER} || '';
my $class = $classes->{pg_loader_test1};
my $filename = $schema->_loader->get_dump_filename($class);
- my $code = decode('UTF-8', scalar slurp $filename);
+ my $code = slurp_file $filename;
like $code, qr/^=head1 NAME\n\n^$class - The\nTable ∑\n\n^=cut\n/m,
'table comment';
$class = $classes->{pg_loader_test2};
$filename = $schema->_loader->get_dump_filename($class);
- $code = decode('UTF-8', scalar slurp $filename);
+ $code = slurp_file $filename;
like $code, qr/^=head1 NAME\n\n^$class\n\n=head1 DESCRIPTION\n\n^very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long comment\n\n^=cut\n/m,
'long table comment is in DESCRIPTION';
use strict;
-use lib qw(t/lib);
-use dbixcsl_common_tests;
+use warnings;
use Test::More;
use Test::Exception;
-use File::Slurp ();
+use DBIx::Class::Schema::Loader::Utils 'slurp_file';
+use namespace::clean;
+use lib qw(t/lib);
+use dbixcsl_common_tests;
my $dsn = $ENV{DBICTEST_ORA_DSN} || '';
my $user = $ENV{DBICTEST_ORA_USER} || '';
my $class = $classes->{oracle_loader_test1};
my $filename = $schema->_loader->get_dump_filename($class);
- my $code = File::Slurp::slurp $filename;
+ my $code = slurp_file $filename;
like $code, qr/^=head1 NAME\n\n^$class - oracle_loader_test1 table comment\n\n^=cut\n/m,
'table comment';
use Digest::MD5;
use File::Find 'find';
use Class::Unload ();
-use DBIx::Class::Schema::Loader::Utils 'dumper_squashed';
+use DBIx::Class::Schema::Loader::Utils qw/dumper_squashed slurp_file/;
use List::MoreUtils 'apply';
use DBIx::Class::Schema::Loader::Optional::Dependencies ();
use Try::Tiny;
-use File::Slurp 'read_file';
use File::Spec::Functions 'catfile';
use File::Basename 'basename';
use namespace::clean;
'Result files dumped to first entry in result_namespace';
# parse out the resultset_namespace
- my $schema_code = read_file($conn->_loader->get_dump_filename(SCHEMA_CLASS), binmode => ':encoding(UTF-8)');
+ my $schema_code = slurp_file $conn->_loader->get_dump_filename(SCHEMA_CLASS);
my ($schema_resultset_namespace) = $schema_code =~ /\bresultset_namespace => (.*)/;
$schema_resultset_namespace = eval $schema_resultset_namespace;
$class6->column_info('Id2');
ok($id2_info->{is_foreign_key}, 'Foreign key detected');
- unlike read_file($conn->_loader->get_dump_filename($class6), binmode => ':encoding(UTF-8)'),
+ unlike slurp_file $conn->_loader->get_dump_filename($class6),
qr/\n__PACKAGE__->(?:belongs_to|has_many|might_have|has_one|many_to_many)\(
\s+ "(\w+?)"
.*?
\s+ "\1"/xs,
'did not create two relationships with the same name';
- unlike read_file($conn->_loader->get_dump_filename($class8), binmode => ':encoding(UTF-8)'),
+ unlike slurp_file $conn->_loader->get_dump_filename($class8),
qr/\n__PACKAGE__->(?:belongs_to|has_many|might_have|has_one|many_to_many)\(
\s+ "(\w+?)"
.*?