2 use DBIx::Class::Schema::Loader;
3 use DBIx::Class::Schema::Loader::Utils 'slurp_file';
5 use Test::More tests => 19;
9 use dbixcsl_test_dir qw/$tdir/;
11 my $dump_path = "$tdir/dump";
13 my %original_class_data;
15 my ($schema_file_count, $result_file_count);
18 package DBICTest::Schema::1;
20 use base 'DBIx::Class::Schema::Loader';
21 __PACKAGE__->loader_options(
22 dump_directory => $dump_path,
24 filter_generated_code => sub {
25 my ($type, $class, $text) = @_;
27 like $type, qr/^(?:schema|result)\z/,
28 'got correct file type';
30 if ($type eq 'schema') {
32 is $class, 'DBICTest::Schema::1',
33 'correct class for schema type file passed to filter';
35 elsif ($type eq 'result') {
37 like $class, qr/^DBICTest::Schema::1::Result::(?:Foo|Bar)\z/,
38 'correct class for result type file passed to filter';
41 die 'invalid file type passed to filter';
44 $original_class_data{$class} = $text;
45 if ($class =~ /::1$/) {
49 $text .= q{my $foo = "Kilroy was here";};
57 package DBICTest::Schema::2;
58 use base 'DBIx::Class::Schema::Loader';
59 __PACKAGE__->loader_options(
60 dump_directory => $dump_path,
62 filter_generated_code => "$^X t/bin/simple_filter",
66 DBICTest::Schema::1->connect($make_dbictest_db::dsn);
68 # schema is generated in 2 passes
70 is $schema_file_count, 2,
71 'correct number of schema files passed to filter';
73 is $result_file_count, 4,
74 'correct number of result files passed to filter';
76 my $foo = slurp_file "$dump_path/DBICTest/Schema/1/Result/Foo.pm";
77 ok(! -e "$dump_path/DBICTest/Schema/1.pm",
78 "No package means no file written");
79 ok($original_class_data{"DBICTest::Schema::1"},
80 "Even though we processed the missing class");
81 like($foo, qr/# Created by .* THE FIRST PART/s,
82 "We get the whole autogenerated text");
83 like($foo, qr/Kilroy was here/, "Can insert text");
85 DBICTest::Schema::2->connect($make_dbictest_db::dsn);
87 $foo = slurp_file "$dump_path/DBICTest/Schema/2/Result/Foo.pm";
89 like $foo, qr/Kilroy was here/,
90 "Can insert text via command filter";
92 END { rmtree($dump_path, 1, 1); }