3 use DBIx::Class::Schema::Loader;
4 use DBIx::Class::Schema::Loader::Utils 'slurp_file';
6 use Test::More tests => 19;
10 use dbixcsl_test_dir qw/$tdir/;
12 my $dump_path = "$tdir/dump";
14 my %original_class_data;
16 my ($schema_file_count, $result_file_count);
19 package DBICTest::Schema::1;
21 use base 'DBIx::Class::Schema::Loader';
22 __PACKAGE__->loader_options(
23 dump_directory => $dump_path,
25 filter_generated_code => sub {
26 my ($type, $class, $text) = @_;
28 like $type, qr/^(?:schema|result)\z/,
29 'got correct file type';
31 if ($type eq 'schema') {
33 is $class, 'DBICTest::Schema::1',
34 'correct class for schema type file passed to filter';
36 elsif ($type eq 'result') {
38 like $class, qr/^DBICTest::Schema::1::Result::(?:Foo|Bar)\z/,
39 'correct class for result type file passed to filter';
42 die 'invalid file type passed to filter';
45 $original_class_data{$class} = $text;
46 if ($class =~ /::1$/) {
50 $text .= q{my $foo = "Kilroy was here";};
58 package DBICTest::Schema::2;
59 use base 'DBIx::Class::Schema::Loader';
60 __PACKAGE__->loader_options(
61 dump_directory => $dump_path,
63 filter_generated_code => "$^X t/bin/simple_filter",
67 DBICTest::Schema::1->connect($make_dbictest_db::dsn);
69 # schema is generated in 2 passes
71 is $schema_file_count, 2,
72 'correct number of schema files passed to filter';
74 is $result_file_count, 4,
75 'correct number of result files passed to filter';
77 my $foo = slurp_file "$dump_path/DBICTest/Schema/1/Result/Foo.pm";
78 ok ! -e "$dump_path/DBICTest/Schema/1.pm",
79 "No package means no file written";
80 ok $original_class_data{"DBICTest::Schema::1"},
81 "Even though we processed the missing class";
82 like $foo, qr/# Created by .* THE FIRST PART/s,
83 "We get the whole autogenerated text";
84 like $foo, qr/Kilroy was here/, "Can insert text";
86 DBICTest::Schema::2->connect($make_dbictest_db::dsn);
88 $foo = slurp_file "$dump_path/DBICTest/Schema/2/Result/Foo.pm";
90 like $foo, qr/Kilroy was here/,
91 "Can insert text via command filter";
93 END { rmtree($dump_path, 1, 1); }