X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper%2FModel%2FDBIC%2FSchema.pm;h=2b9d8c2933e73a76c4227d6559149aca9bc4b24b;hb=726daa55ab1a08d8faffa58a4350359d9a8126db;hp=ba45485c86988afd5610d6df777222fe7af55bb0;hpb=ed895a51859b307356da293510776445b4ac41b4;p=catagits%2FCatalyst-Model-DBIC-Schema.git diff --git a/lib/Catalyst/Helper/Model/DBIC/Schema.pm b/lib/Catalyst/Helper/Model/DBIC/Schema.pm index ba45485..2b9d8c2 100644 --- a/lib/Catalyst/Helper/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Helper/Model/DBIC/Schema.pm @@ -4,7 +4,7 @@ use namespace::autoclean; use Moose; no warnings 'uninitialized'; -our $VERSION = '0.47'; +our $VERSION = '0.53'; $VERSION = eval $VERSION; use Carp; @@ -61,14 +61,15 @@ the generated classes by hand to refine them. C is the list of traits to apply to the model, see L for details. -C are described in L below. +C are documented in L +and some examples are given in L below. -C arguments are the same as what -DBIx::Class::Schema::connect expects, and are storage_type-specific. -For DBI-based storage, these arguments are the dsn, username, -password, and connect options, respectively. These are optional for -existing Schemas, but required if you use either of the C -options. +C arguments are the same as what L +expects, and are storage_type-specific. They are documented in +L. For DBI-based storage, these +arguments are the dsn, username, password, and connect options, respectively. +These are optional for existing Schemas, but required if you use either of the +C options. username and password can be omitted for C dsns. @@ -88,11 +89,7 @@ user and pass can be omitted for sqlite, since they are always empty script/myapp_create.pl model CatalystModelName DBIC::Schema \ MyApp::SchemaClass create=static dbi:SQLite:foo.db \ AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \ - on_connect_do='["select 1", "select 2"]' quote_char='"' - -If using a 2 character quote_char: - - script/myapp_create.pl ... quote_char='[]' + on_connect_do='["select 1", "select 2"]' quote_names=1 B @@ -101,7 +98,7 @@ In C the above example would be: script/myapp_create.pl model CatalystModelName DBIC::Schema \ MyApp::SchemaClass create=static dbi:SQLite:foo.db \ AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \ - on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\"" + on_connect_do="[\"select 1\", \"select 2\"]" quote_names=1 Same, but with extra Schema::Loader args (separate multiple values by commas): @@ -303,6 +300,47 @@ sub _read_loader_args { } } + # Use args after connect_info as loader args as well, because people always + # get the order confused. + my $i = 1; + if ($args->[0] =~ /sqlite/i) { + $i++ if $args->[$i] eq ''; + $i++ if $args->[$i] eq ''; + } + else { + $i += 2; + } + + my $have_loader = try { + Class::MOP::load_class('DBIx::Class::Schema::Loader::Base'); + 1; + }; + + if ($have_loader) { + while (defined $args->[$i]) { + $i++ while $self->_is_struct($args->[$i]); + + last if not defined $args->[$i]; + + my ($key, $val) = split /=/, $args->[$i], 2; + + if (not DBIx::Class::Schema::Loader::Base->can($key)) { + $i++; + next; + } + + if ($self->_is_struct($val)) { + $loader_args{$key} = $val; + } elsif ((my @vals = split /,/ => $val) > 1) { + $loader_args{$key} = \@vals; + } else { + $loader_args{$key} = $val; + } + + splice @$args, $i, 1; + } + } + wantarray ? %loader_args : \%loader_args; } @@ -452,16 +490,11 @@ sub _build_result_namespace { my ($result_namespace) = $code =~ /result_namespace => '([^']+)'/; - if (not $result_namespace) { - if ($code =~ /->load_classes/) { - $result_namespace = ''; - } - else { - $result_namespace = 'Result'; - } - } + return $result_namespace if $result_namespace; + + return '' if $code =~ /->load_classes/; - return $result_namespace; + return 'Result'; } sub _data_struct_to_string { @@ -604,6 +637,19 @@ sub _gen_static_schema { $self->loader_args, [$self->connect_info] ); + + require lib; + lib->import($schema_dir); + + Class::MOP::load_class($self->schema_class); + + my @sources = $self->schema_class->sources; + + if (not @sources) { + warn <<'EOF'; +WARNING: No tables found, did you forget to specify db_schema? +EOF + } } sub _gen_model {