X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;h=c7a9856d2b148ee22050f6de245cd3ee2aae6789;hb=e344eed6c9cf62f2e5e78a31d8c499014a16c68c;hp=2a0e973b9df11bec3e91242fcfed3e26e2b91187;hpb=e7213f4f82f1b5f593ee9d6a96be818aa89165d3;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 2a0e973..c7a9856 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -14,7 +14,7 @@ use Cwd qw//; use Digest::MD5 qw//; require DBIx::Class; -our $VERSION = '0.04999_01'; +our $VERSION = '0.04999_02'; __PACKAGE__->mk_ro_accessors(qw/ schema @@ -35,6 +35,10 @@ __PACKAGE__->mk_ro_accessors(qw/ dump_directory dump_overwrite really_erase_my_files + use_namespaces + result_namespace + resultset_namespace + default_resultset_class db_schema _tables @@ -141,6 +145,15 @@ classes. A good example would be C. Component C will be automatically added to the above C list if this option is set. +=head2 use_namespaces + +Generate result class names suitable for +L and call that instead of +L. When using this option you can also +specify any of the options for C (i.e. C, +C, C), and they will be added +to the call (and the generated result class names adjusted appropriately). + =head2 dump_directory This option is designed to be a tool to help you transition from this @@ -440,8 +453,26 @@ sub _dump_to_dir { my $schema_text = qq|package $schema_class;\n\n| . qq|use strict;\nuse warnings;\n\n| - . qq|use base 'DBIx::Class::Schema';\n\n| - . qq|__PACKAGE__->load_classes;\n|; + . qq|use base 'DBIx::Class::Schema';\n\n|; + + + if ($self->use_namespaces) { + $schema_text .= qq|__PACKAGE__->load_namespaces|; + my $namespace_options; + for my $attr (qw(result_namespace + resultset_namespace + default_resultset_class)) { + if ($self->$attr) { + $namespace_options .= qq| $attr => '| . $self->$attr . qq|',\n| + } + } + $schema_text .= qq|(\n$namespace_options)| if $namespace_options; + $schema_text .= qq|;\n|; + } + else { + $schema_text .= qq|__PACKAGE__->load_classes;\n|; + + } $self->_write_classfile($schema_class, $schema_text); @@ -569,7 +600,19 @@ sub _make_src_class { my $schema_class = $self->schema_class; my $table_moniker = $self->_table2moniker($table); - my $table_class = $schema_class . q{::} . $table_moniker; + my @result_namespace = ($schema_class); + if ($self->use_namespaces) { + my $result_namespace = $self->result_namespace || 'Result'; + if ($result_namespace =~ /^\+(.*)/) { + # Fully qualified namespace + @result_namespace = ($1) + } + else { + # Relative namespace + push @result_namespace, $result_namespace; + } + } + my $table_class = join(q{::}, @result_namespace, $table_moniker); my $table_normalized = lc $table; $self->classes->{$table} = $table_class;