0.04999_06 Not Yet Released
- Singularise table monikers by default
- Strip trailing _id from single-column belongs_to relationships
+ - Add "dbicdump" script for easy commandline dumping
0.04999_05 Mon Apr 14, 2008
- Fix limiting table list to the specified schema for DB2
test_requires 'DBD::SQLite' => '1.12';
test_requires 'File::Path' => 0;
test_requires 'Class::Unload' => 0;
+test_requires 'IPC::Open3' => 0;
requires 'File::Spec' => 0;
requires 'Scalar::Util' => 0;
requires 'Class::Inspector' => 0;
requires 'DBIx::Class' => '0.07006';
+install_script 'script/dbicdump';
+
# This is my manual hack for better feature control
# If you want to change the default answer for a feature,
# set the appropriate environment variable, like
--- /dev/null
+#!/usr/bin/perl
+
+=head1 NAME
+
+dbicdump - Dump a schema using DBIx::Class::Schema::Loader
+
+=head1 SYNOPSIS
+
+ dbicdump [-o <loader_option>=<value> ] <schema_class> <connect_info>
+
+=head1 DESCRIPTION
+
+Dbicdump generates a L<DBIx::Class> schema using
+L<DBIx::Class::Schema::Loader/make_schema_at> and dumps it to disk.
+
+You can pass any L<DBIx::Class::Loader::Base> constructor option using
+C<< -o <option>=<value> >>. For convenience, option names will have C<->
+replaced with C<_> and values that look like references or quote-like
+operators will be C<eval>-ed before being passed to the constructor.
+
+The C<dump_directory> option defaults to the current directory if not
+specified.
+
+=head1 SEE ALSO
+
+L<DBIx::Class::Schema::Loader>, L<DBIx::Class>.
+
+=head1 AUTHOR
+
+Dagfinn Ilmari Mannsåker C<< <ilmari@ilmari.org> >>
+
+=head1 LICENSE
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+use strict;
+use warnings;
+use Getopt::Long;
+use DBIx::Class::Schema::Loader qw/ make_schema_at /;
+require DBIx::Class::Schema::Loader::Base;
+
+my $loader_options;
+
+GetOptions( 'loader-option|o=s%' => \&handle_option );
+$loader_options->{dump_directory} ||= '.';
+
+my ($schema_class, @loader_connect_info) = @ARGV;
+
+sub handle_option {
+ my ($self, $key, $value) = @_;
+
+ $key =~ tr/-/_/;
+ die "Unknown option: $key\n"
+ unless DBIx::Class::Schema::Loader::Base->can($key);
+
+ $value = eval $value if $value =~ /^\s*(?:sub\s*\{|q\w?\s*[^\w\s]|[[{])/;
+
+ $loader_options->{$key} = $value;
+}
+
+make_schema_at(
+ $schema_class,
+ $loader_options,
+ \@loader_connect_info,
+);
use Test::More;
use lib qw(t/lib);
use File::Path;
+use IPC::Open3;
use make_dbictest_db;
require DBIx::Class::Schema::Loader;
$^O eq 'MSWin32'
? plan(skip_all => "ActiveState perl produces additional warnings, and this test uses unix paths")
- : plan(tests => 82);
+ : plan(tests => 140);
my $DUMP_PATH = './t/_dump';
-sub do_dump_test {
+sub dump_directly {
my %tdata = @_;
my $schema_class = $tdata{classname};
no strict 'refs';
@{$schema_class . '::ISA'} = ('DBIx::Class::Schema::Loader');
- $schema_class->loader_options(dump_directory => $DUMP_PATH, %{$tdata{options}});
+ $schema_class->loader_options(%{$tdata{options}});
my @warns;
eval {
is($err, $tdata{error});
+ return @warns;
+}
+
+sub dump_dbicdump {
+ my %tdata = @_;
+
+ my @cmd = qw(./script/dbicdump);
+
+ while (my ($opt, $val) = each(%{ $tdata{options} })) {
+ push @cmd, '-o', "$opt=$val";
+ }
+
+ push @cmd, $tdata{classname}, $make_dbictest_db::dsn;
+
+ my ($in, $out, $err);
+ my $pid = open3($in, $out, $err, @cmd);
+
+ my @warns = <$out>;
+ waitpid($pid, 0);
+
+ return @warns;
+}
+
+sub do_dump_test {
+ my %tdata = @_;
+
+ $tdata{options}{dump_directory} = $DUMP_PATH;
+
+ for my $dumper (\&dump_directly, \&dump_dbicdump) {
+ test_dumps(\%tdata, $dumper->(%tdata));
+ }
+}
+
+sub test_dumps {
+ my ($tdata, @warns) = @_;
+
+ my %tdata = %{$tdata};
+
+ my $schema_class = $tdata{classname};
my $check_warns = $tdata{warnings};
- is(@warns, @$check_warns);
+ is(@warns, @$check_warns, "$schema_class warning count");
for(my $i = 0; $i <= $#$check_warns; $i++) {
- like($warns[$i], $check_warns->[$i]);
+ like($warns[$i], $check_warns->[$i], "$schema_class warning $i");
}
my $file_regexes = $tdata{regexes};
open(my $dumpfh, '<', $path) or die "Failed to open '$path': $!";
my $contents = do { local $/; <$dumpfh>; };
close($dumpfh);
- like($contents, $_) for @_;
+ my $num = 1;
+ like($contents, $_, "like $path " . $num++) for @_;
}
sub dump_file_not_like {
open(my $dumpfh, '<', $path) or die "Failed to open '$path': $!";
my $contents = do { local $/; <$dumpfh>; };
close($dumpfh);
- unlike($contents, $_) for @_;
+ my $num = 1;
+ unlike($contents, $_, "unlike $path ". $num++) for @_;
}
sub append_to_class {