X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;h=fe381701cf8aaf9b77bf1d377433bfbbc2d4bb5a;hb=7ffafa3740a2199a784a8799d8f885c955b4390a;hp=fd06499296ed90600ba6083e4ed3d01dc4d1693c;hpb=692193496082e4b69bcd80d02999371d20d874ba;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index fd06499..fe38170 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -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 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. 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 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 { @@ -1508,7 +1523,12 @@ sub _setup_src_meta { $table_name = \ $self->_quote_table_name($table_name); } - $self->_dbic_stmt($table_class, 'table', ($self->qualify_objects ? ($self->db_schema . '.') : '') . $table_name); + my $full_table_name = ($self->qualify_objects ? ($self->db_schema . '.') : '') . (ref $table_name ? $$table_name : $table_name); + + # be careful to not create refs Data::Dump can "optimize" + $full_table_name = \do {"".$full_table_name} if ref $table_name; + + $self->_dbic_stmt($table_class, 'table', $full_table_name); my $cols = $self->_table_columns($table); my $col_info = $self->__columns_info_for($table); @@ -1540,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', @@ -1553,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