generate POD for unique constraints, set_primary_key and table
Rafael Kitover [Mon, 30 May 2011 14:08:11 +0000 (10:08 -0400)]
Changes
lib/DBIx/Class/Schema/Loader/Base.pm
t/23dumpmore.t

diff --git a/Changes b/Changes
index 9e993cd..1771410 100644 (file)
--- a/Changes
+++ b/Changes
@@ -13,7 +13,8 @@ Revision history for Perl extension DBIx::Class::Schema::Loader
         - fix a bug in Sybase ASE foreign key detection
         - generate POD for result_base_class, additional_classes,
           additional_base_classes, left_base_classes, components,
-          result_components_map, result_roles and result_roles_map
+          result_components_map, result_roles, result_roles_map, unique
+          constraints, set_primary_key and table
         - rename result_component_map to result_components_map (old name still
           works)
         - fix accessor collision detection for methods from
index 5a50691..275efae 100644 (file)
@@ -2175,7 +2175,12 @@ sub _make_pod {
     my $class  = shift;
     my $method = shift;
 
-    if ( $method eq 'add_columns' ) {
+    if ($method eq 'table') {
+        my $table = $_[0];
+        $self->_pod($class, "=head1 TABLE: C<$table>");
+        $self->_pod_cut($class);
+    }
+    elsif ( $method eq 'add_columns' ) {
         $self->_pod( $class, "=head1 ACCESSORS" );
         my $col_counter = 0;
         my @cols = @_;
@@ -2208,6 +2213,35 @@ sub _make_pod {
         $self->_pod_cut( $class );
         $self->{_relations_started} { $class } = 1;
     }
+    elsif ($method eq 'add_unique_constraint') {
+        $self->_pod($class, '=head1 UNIQUE CONSTRAINTS')
+            unless $self->{_uniqs_started}{$class};
+        
+        my ($name, $cols) = @_;
+
+        $self->_pod($class, "=head2 C<$name>");
+        $self->_pod($class, '=over 4');
+        
+        foreach my $col (@$cols) {
+            $self->_pod($class, "=item \* L</$col>");
+        }
+
+        $self->_pod($class, '=back');
+        $self->_pod_cut($class);
+
+        $self->{_uniqs_started}{$class} = 1;
+    }
+    elsif ($method eq 'set_primary_key') {
+        $self->_pod($class, "=head1 PRIMARY KEY");
+        $self->_pod($class, '=over 4');
+        
+        foreach my $col (@_) {
+            $self->_pod($class, "=item \* L</$col>");
+        }
+
+        $self->_pod($class, '=back');
+        $self->_pod_cut($class);
+    }
 }
 
 sub _pod_class_list {
index 2091871..747aa9a 100644 (file)
@@ -75,6 +75,7 @@ $t->dump_test(
 $t->cleanup;
 
 # test naming => { column_accessors => 'preserve' }
+# also test POD for unique constraint
 $t->dump_test(
     classname => 'DBICTest::Schema::_preserve_column_accessors',
     test_db_class => 'make_dbictest_db_with_unique',
@@ -88,6 +89,11 @@ $t->dump_test(
             qr/\baccessor\b/,
         ],
     },
+    regexes => {
+        Baz => [
+            qr/\n\n=head1 UNIQUE CONSTRAINTS\n\n=head2 C<baz_num_unique>\n\n=over 4\n\n=item \* L<\/baz_num>\n\n=back\n\n=cut\n\n__PACKAGE__->add_unique_constraint\("baz_num_unique"\, \["baz_num"\]\);\n\n/,
+        ],
+    }
 );
 
 $t->cleanup;
@@ -185,10 +191,11 @@ $t->dump_test(
       qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
       qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
       qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item \* L<DBIx::Class::TestComponent>\n\n=item \* L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 TABLE: C<foo>\n\n=cut\n\n__PACKAGE__->table\("foo"\);\n\n/,
       qr/\n=head1 ACCESSORS\n\n/,
       qr/\n=head2 fooid\n\n  data_type: 'integer'\n  is_auto_increment: 1\n  is_nullable: 0\n\n/,
       qr/\n=head2 footext\n\n  data_type: 'text'\n  default_value: 'footext'\n  extra: {is_footext => 1}\n  is_nullable: 1\n\n/,
-      qr/->set_primary_key/,
+      qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/fooid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("fooid"\);\n/,
       qr/\n=head1 RELATIONS\n\n/,
       qr/\n=head2 bars\n\nType: has_many\n\nRelated object: L<DBICTest::DumpMore::1::Bar>\n\n=cut\n\n/,
       qr/1;\n$/,
@@ -201,10 +208,11 @@ $t->dump_test(
       qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
       qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
       qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item \* L<DBIx::Class::TestComponent>\n\n=item \* L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 TABLE: C<bar>\n\n=cut\n\n__PACKAGE__->table\("bar"\);\n\n/,
       qr/\n=head1 ACCESSORS\n\n/,
       qr/\n=head2 barid\n\n  data_type: 'integer'\n  is_auto_increment: 1\n  is_nullable: 0\n\n/,
       qr/\n=head2 fooref\n\n  data_type: 'integer'\n  is_foreign_key: 1\n  is_nullable: 1\n\n/,
-      qr/->set_primary_key/,
+      qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/barid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("barid"\);\n/,
       qr/\n=head1 RELATIONS\n\n/,
       qr/\n=head2 fooref\n\nType: belongs_to\n\nRelated object: L<DBICTest::DumpMore::1::Foo>\n\n=cut\n\n/,
       qr/\n1;\n$/,