Revision history for Perl extension DBIx::Class::Schema::Loader
+ - add -I option to dbicdump
- 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 warnings;
use Test::More;
use String::CamelCase 'wordsplit';
+use Carp::Clan qw/^DBIx::Class/;
use namespace::clean;
use Exporter 'import';
use Data::Dumper ();
}
sub slurp_file($) {
- open my $fh, '<:encoding(UTF-8)', shift;
+ my $file_name = shift;
+
+ open my $fh, '<:encoding(UTF-8)', $file_name,
+ or croak "Can't open '$file_name' for reading: $!";
+
my $data = do { local $/; <$fh> };
+
close $fh;
$data =~ s/$CRLF|$LF/\n/g;
}
sub write_file($$) {
- open my $fh, '>:encoding(UTF-8)', shift;
+ my $file_name = shift;
+
+ open my $fh, '>:encoding(UTF-8)', $file_name,
+ or croak "Can't open '$file_name' for writing: $!";
+
print $fh shift;
close $fh;
}
=head1 SYNOPSIS
dbicdump <configuration_file>
- dbicdump [-o <loader_option>=<value> ] <schema_class> <connect_info>
+ dbicdump [-I <lib-path>] [-o <loader_option>=<value> ] \
+ <schema_class> <connect_info>
Examples:
-o components='["InflateColumn::DateTime"]' \
MyApp::Schema dbi:SQLite:./foo.db '{ quote_char => "\"" }'
- $ dbicdump -o dump_directory=./lib \
+ $ dbicdump -Ilib -o dump_directory=./lib \
-o components='["InflateColumn::DateTime"]' \
-o preserve_case=1 \
MyApp::Schema dbi:mysql:database=foo user pass '{ quote_char => "`" }'
an example of a general config file is as follows:
schema_class MyApp::Schema
+
+ lib /extra/perl/libs
# connection string
<connect_info>
Using a config file requires L<Config::Any> installed.
+The optional C<lib> key is equivalent to the C<-I> option.
+
=head1 DESCRIPTION
Dbicdump generates a L<DBIx::Class> schema using
Caelum: Rafael Kitover <rkitover@cpan.org>
+alnewkirk: Al Newkirk <awncorp@cpan.org>
+
=head1 LICENSE
This program is free software; you can redistribute it and/or modify it
use Getopt::Long;
use Pod::Usage;
use DBIx::Class::Schema::Loader 'make_schema_at';
+use namespace::clean;
use DBIx::Class::Schema::Loader::Base ();
use DBIx::Class::Schema::Loader::Optional::Dependencies ();
+require lib;
my $loader_options;
-GetOptions( 'loader-option|o=s%' => \&handle_option );
+Getopt::Long::Configure('gnu_getopt');
+
+GetOptions(
+ 'I=s' => sub { shift; lib->import(shift) },
+ 'loader-option|o=s%' => \&handle_option,
+);
+
$loader_options->{dump_directory} ||= '.';
if (@ARGV == 1) {
unless (keys %{$c->{connect_info}} && $c->{schema_class}) {
pod2usage(1);
}
+
+ my @libs;
+
+ if ($c->{lib}) {
+ if (ref $c->{lib}) {
+ @libs = @{ $c->{lib} };
+ }
+
+ @libs = ($c->{lib});
+ }
+
+ lib->import($_) for @libs;
my ($dsn, $user, $pass, $options) =
map { $c->{connect_info}->{$_} } qw/dsn user pass options/;
use Test::More;
use File::Path qw/make_path rmtree/;
-use DBIx::Class::Schema::Loader::Optional::Dependencies ();
use DBIx::Class::Schema::Loader::Utils 'slurp_file';
+use Try::Tiny;
+use namespace::clean;
+use DBIx::Class::Schema::Loader::Optional::Dependencies ();
use lib 't/lib';
use make_dbictest_db ();
use dbixcsl_test_dir '$tdir';
print $fh <<"EOF";
schema_class DBICTest::Schema
+lib t/lib
+
<connect_info>
dsn $make_dbictest_db::dsn
</connect_info>
<loader_options>
- dump_directory $dump_path
- components InflateColumn::DateTime
- quiet 1
+ dump_directory $dump_path
+ components InflateColumn::DateTime
+ schema_base_class TestSchemaBaseClass
+ quiet 1
</loader_options>
EOF
is $? >> 8, 0,
'dbicdump executed successfully';
-my $foo = slurp_file "$dump_path/DBICTest/Schema/Result/Foo.pm";
+my $foo = try { slurp_file "$dump_path/DBICTest/Schema/Result/Foo.pm" } || '';
like $foo, qr/InflateColumn::DateTime/,
'loader options read correctly from config_file';
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use DBIx::Class::Schema::Loader::Utils 'slurp_file';
+use lib 't/lib';
+use make_dbictest_db ();
+use dbixcsl_test_dir '$tdir';
+
+plan tests => 3;
+
+# Test the -I option
+
+dbicdump(
+ '-I', 't/lib', '-o', 'schema_base_class=TestSchemaBaseClass', 'DBICTest::Schema',
+ $make_dbictest_db::dsn
+);
+
+dbicdump(
+ '-It/lib', '-o', 'schema_base_class=TestSchemaBaseClass', 'DBICTest::Schema',
+ $make_dbictest_db::dsn
+);
+
+dbicdump(
+ '-I/dummy', '-It/lib', '-o', 'schema_base_class=TestSchemaBaseClass',
+ 'DBICTest::Schema',
+ $make_dbictest_db::dsn
+);
+
+done_testing;
+
+sub dbicdump {
+ system $^X, 'script/dbicdump',
+ '-o', "dump_directory=$tdir",
+ '-o', 'quiet=1',
+ @_;
+
+ is $? >> 8, 0,
+ 'dbicdump executed successfully';
+}