Fix =head level for some constructor options.
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Base.pm
index 28d2bac..fe38170 100644 (file)
@@ -23,7 +23,7 @@ use File::Slurp 'slurp';
 use DBIx::Class::Schema::Loader::Utils 'split_name';
 require DBIx::Class;
 
-our $VERSION = '0.07000';
+our $VERSION = '0.07001';
 
 __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 schema
@@ -50,6 +50,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 default_resultset_class
                                 schema_base_class
                                 result_base_class
+                                use_moose
                                overwrite_modifications
 
                                 relationship_attrs
@@ -450,12 +451,12 @@ columns with the DATE/DATETIME/TIMESTAMP data_types.
 Sets the locale attribute for L<DBIx::Class::InflateColumn::DateTime> for all
 columns with the DATE/DATETIME/TIMESTAMP data_types.
 
-=head1 config_file
+=head2 config_file
 
 File in Perl format, which should return a HASH reference, from which to read
 loader options.
 
-=head1 preserve_case
+=head2 preserve_case
 
 Usually column names are lowercased, to make them easier to work with in
 L<DBIx::Class>. This option lets you turn this behavior off, if the driver
@@ -467,7 +468,7 @@ case-sensitive collation will turn this option on unconditionally.
 Currently the drivers for SQLite, mysql, MSSQL and Firebird/InterBase support
 setting this option.
 
-=head1 qualify_objects
+=head2 qualify_objects
 
 Set to true to prepend the L</db_schema> to table names for C<<
 __PACKAGE__->table >> calls, and to some other things like Oracle sequences.
@@ -1163,8 +1164,13 @@ sub _dump_to_dir {
           qq|package $schema_class;\n\n|
         . qq|# Created by DBIx::Class::Schema::Loader\n|
         . qq|# DO NOT MODIFY THE FIRST PART OF THIS FILE\n\n|
-        . qq|use strict;\nuse warnings;\n\n|
-        . qq|use base '$schema_base_class';\n\n|;
+        . qq|use strict;\nuse warnings;\n\n|;
+    if ($self->use_moose) {
+        $schema_text.= qq|use Moose;\nuse MooseX::NonMoose;\nextends '$schema_base_class';\n\n|;
+    }
+    else {
+        $schema_text .= qq|use base '$schema_base_class';\n\n|;
+    }
 
     if ($self->use_namespaces) {
         $schema_text .= qq|__PACKAGE__->load_namespaces|;
@@ -1198,9 +1204,13 @@ sub _dump_to_dir {
               qq|package $src_class;\n\n|
             . qq|# Created by DBIx::Class::Schema::Loader\n|
             . qq|# DO NOT MODIFY THE FIRST PART OF THIS FILE\n\n|
-            . qq|use strict;\nuse warnings;\n\n|
-            . qq|use base '$result_base_class';\n\n|;
-
+            . qq|use strict;\nuse warnings;\n\n|;
+        if ($self->use_moose) {
+            $src_text.= qq|use Moose;\nuse MooseX::NonMoose;\nextends '$result_base_class';\n\n|;
+        }
+        else {
+             $src_text .= qq|use base '$result_base_class';\n\n|;
+        }
         $self->_write_classfile($src_class, $src_text);
     }
 
@@ -1304,9 +1314,14 @@ sub _write_classfile {
 }
 
 sub _default_custom_content {
-    return qq|\n\n# You can replace this text with custom|
-         . qq| content, and it will be preserved on regeneration|
-         . qq|\n1;\n|;
+    my $self = shift;
+    my $default = qq|\n\n# You can replace this text with custom|
+         . qq| content, and it will be preserved on regeneration|;
+    if ($self->use_moose) {
+        $default .= qq|\nno Moose;\n__PACKAGE__->meta->make_immutable( inline_constructor => 0 );\n1;\n|;
+    }
+    $default .= qq|\n1;\n|;
+    return $default;
 }
 
 sub _get_custom_content {
@@ -1545,11 +1560,18 @@ sub _setup_src_meta {
 
     my $fks = $self->_table_fk_info($table);
 
-    for my $fkdef (@$fks) {
+    foreach my $fkdef (@$fks) {
         for my $col (@{ $fkdef->{local_columns} }) {
             $col_info->{$col}{is_foreign_key} = 1;
         }
     }
+
+    my $pks = $self->_table_pk_info($table) || [];
+
+    foreach my $pkcol (@$pks) {
+        $col_info->{$pkcol}{is_nullable} = 0;
+    }
+
     $self->_dbic_stmt(
         $table_class,
         'add_columns',
@@ -1558,7 +1580,6 @@ sub _setup_src_meta {
 
     my %uniq_tag; # used to eliminate duplicate uniqs
 
-    my $pks = $self->_table_pk_info($table) || [];
     @$pks ? $self->_dbic_stmt($table_class,'set_primary_key',@$pks)
           : carp("$table has no primary key");
     $uniq_tag{ join("\0", @$pks) }++ if @$pks; # pk is a uniq