From: Dagfinn Ilmari Mannsåker Date: Tue, 26 Nov 2013 17:28:05 +0000 (+0000) Subject: Add accessor for the list of (re)generated classes X-Git-Tag: 0.07039~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9f98bd820b2634ba37e61054000e67199511e0cd;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Add accessor for the list of (re)generated classes --- diff --git a/Changes b/Changes index 8c05f85..d66a9d1 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader - Fix table listing with DBD::DB2 >= 1.85 (RT#91764) + - Add accessor for the list of (re)generated classes 0.07038 2013-11-20 - Allow coderef maps to call back into the hashref mapping code diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 0e5cea3..2c7cfb0 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -61,6 +61,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ use_moose only_autoclean overwrite_modifications + generated_classes relationship_attrs @@ -1123,6 +1124,7 @@ sub new { $self->{class_to_table} = {}; $self->{classes} = {}; $self->{_upgrading_classes} = {}; + $self->{generated_classes} = []; $self->{schema_class} ||= ( ref $self->{schema} || $self->{schema} ); $self->{schema} ||= $self->{schema_class}; @@ -1747,6 +1749,7 @@ sub _load_tables { # The relationship loader needs a working schema local $self->{quiet} = 1; local $self->{dump_directory} = $self->{temp_directory}; + local $self->{generated_classes} = []; $self->_reload_classes(\@tables); $self->_load_relationships(\@tables); @@ -2131,6 +2134,8 @@ sub _write_classfile { } } + push @{$self->generated_classes}, $class; + $text .= $self->_sig_comment( $self->version_to_dump, POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime) @@ -3104,6 +3109,11 @@ Returns a hashref of table to class mappings. In some cases it will contain multiple entries per table for the original and normalized table names, as above in L. +=head2 generated_classes + +Returns an arrayref of classes that were actually generated (i.e. not +skipped because there were no changes). + =head1 NON-ENGLISH DATABASES If you use the loader on a database with table and column names in a language diff --git a/t/22dump.t b/t/22dump.t index 6e55839..50a124c 100644 --- a/t/22dump.t +++ b/t/22dump.t @@ -34,6 +34,12 @@ lives_ok { [ qr|^Dumping manual schema|, qr|^Schema dump completed| ]; } 'no death with dump_directory set' or diag "Dump failed: $@"; +is_deeply( + [ sort @{ DBICTest::Schema::1->loader->generated_classes } ], + [ sort 'DBICTest::Schema::1', map "DBICTest::Schema::1::Result::$_", qw(Foo Bar) ], + 'generated_classes has schema and result classes' +); + DBICTest::Schema::1->_loader_invoked(undef); SKIP: { @@ -43,6 +49,12 @@ SKIP: { warnings_exist { DBICTest::Schema::1->connect($make_dbictest_db::dsn) } [ qr|^Dumping manual schema|, qr|^Schema dump completed| ]; + is_deeply( + [ sort @{ DBICTest::Schema::1->loader->generated_classes } ], + [ ], + 'no classes generated on second dump' + ); + rmtree($dump_path, 1, 1); } @@ -51,6 +63,12 @@ lives_ok { [ qr|^Dumping manual schema|, qr|^Schema dump completed| ]; } 'no death with dump_directory set (overwrite1)' or diag "Dump failed: $@"; +is_deeply( + [ sort @{ DBICTest::Schema::2->loader->generated_classes } ], + [ sort 'DBICTest::Schema::2', map "DBICTest::Schema::2::Result::$_", qw(Foo Bar) ], + 'generated_classes has schema and result classes' +); + DBICTest::Schema::2->_loader_invoked(undef); lives_ok { @@ -64,6 +82,12 @@ lives_ok { ]; } 'no death with dump_directory set (overwrite2)' or diag "Dump failed: $@"; +is_deeply( + [ sort @{ DBICTest::Schema::2->loader->generated_classes } ], + [ sort 'DBICTest::Schema::2', map "DBICTest::Schema::2::Result::$_", qw(Foo Bar) ], + 'all classes regenerated with really_erase_my_files', +); + done_testing(); END { rmtree($dump_path, 1, 1); }