From: Brandon L. Black Date: Sun, 19 Feb 2006 21:47:31 +0000 (+0000) Subject: release for 0.07, ->require and connect_info args stuff X-Git-Tag: v0.12~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Model-DBIC-Schema.git;a=commitdiff_plain;h=0b2a7108226ab74ef2c59ff369d160dd3659d5d7 release for 0.07, ->require and connect_info args stuff --- diff --git a/Changes b/Changes index d11d328..2b0f7bc 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,12 @@ Revision history for Perl extension Catalyst::Model::DBIC::Schema +0.07 Sun Feb 19 21:50:18 UTC 2006 + - bugfix for ::SchemaLoader::Foo password argument, and + switch to connect_info argument of new Schema::Loader + - Added ->require for source classes, so that you can + layer in lib/MyApp/Model/Foo/Bar.pm on top of the + generated MyApp::Model::Foo::Bar. + 0.06 Sat Feb 18 19:05:17 UTC 2006 - Fix simple pod-related bug introduced in last rev - Added optional test that uses the helpers diff --git a/META.yml b/META.yml index 4bf22d4..3b79811 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- name: Catalyst-Model-DBIC-Schema -version: 0.06 +version: 0.07 author: - 'Brandon L Black, C' abstract: DBIx::Class::Schema Model Class @@ -22,5 +22,5 @@ provides: file: lib/Catalyst/Helper/Model/DBIC/SchemaLoader.pm Catalyst::Model::DBIC::Schema: file: lib/Catalyst/Model/DBIC/Schema.pm - version: 0.06 + version: 0.07 generated_by: Module::Build version 0.2611 diff --git a/lib/Catalyst/Helper/Model/DBIC/Schema.pm b/lib/Catalyst/Helper/Model/DBIC/Schema.pm index 19ab06a..12d6cbd 100644 --- a/lib/Catalyst/Helper/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Helper/Model/DBIC/Schema.pm @@ -10,15 +10,23 @@ Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models =head1 SYNOPSIS - script/create.pl model Foo DBIC::Schema Foo::SchemaClass [ dsn user password ] + script/create.pl model Foo DBIC::Schema Foo::SchemaClass [ connect_info arguments ] - Where: - Foo is the short name for the Model class being generated - Foo::SchemaClass is the fully qualified classname of your Schema, - which isa DBIx::Class::Schema defined elsewhere. - dsn, user, and password are optional if connection info is already - defined in your Schema class (as it would be in the case of - DBIx::Class::Schema::Loader). + Where: + Foo is the short name for the Model class being generated + Foo::SchemaClass is the fully qualified classname of your Schema, + which isa DBIx::Class::Schema defined elsewhere. + connect_info 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. + +=head1 TYPICAL EXAMPLES + + script/myapp_create.pl model Foo DBIC::Schema FooSchema dbi:mysql:foodb myuname mypass '{ AutoCommit => 1 }' + + # -or, if the schema already has connection info and you want to re-use that: + script/myapp_create.pl model Foo DBIC::Schema FooSchema =head1 DESCRIPTION @@ -31,15 +39,16 @@ Helper for the DBIC Schema Models. =cut sub mk_compclass { - my ( $self, $helper, $schema_class, $dsn, $user, $pass ) = @_; + my ( $self, $helper, $schema_class, @connect_info) = @_; $helper->{schema_class} = $schema_class || ''; - if(defined($dsn)) { + if(@connect_info) { $helper->{setup_connect_info} = 1; - $helper->{dsn} = $dsn || ''; - $helper->{user} = $user || ''; - $helper->{pass} = $pass || ''; + for(@connect_info) { + $_ = qq{'$_'} if $_ !~ /^\s*[[{]/; + } + $helper->{connect_info} = \@connect_info; } my $file = $helper->{file}; @@ -84,19 +93,10 @@ use base 'Catalyst::Model::DBIC::Schema'; __PACKAGE__->config( schema_class => '[% schema_class %]', - [% IF setup_connect_info %] - connect_info => [ '[% dsn %]', - '[% user %]', - '[% pass %]', - { - RaiseError => 1, - PrintError => 0, - ShowErrorStatement => 1, - TraceLevel => 0, - AutoCommit => 1, - } - ], - [% END %] + [% IF setup_connect_info %]connect_info => [ + [% FOREACH arg = connect_info %][% arg %], + [% END %] + ],[% END %] ); =head1 NAME diff --git a/lib/Catalyst/Helper/Model/DBIC/SchemaLoader.pm b/lib/Catalyst/Helper/Model/DBIC/SchemaLoader.pm index 2086c04..9cf27ab 100644 --- a/lib/Catalyst/Helper/Model/DBIC/SchemaLoader.pm +++ b/lib/Catalyst/Helper/Model/DBIC/SchemaLoader.pm @@ -10,11 +10,18 @@ Catalyst::Helper::Model::DBIC::SchemaLoader - Helper for AutoLoaded DBIC Schema =head1 SYNOPSIS - script/myapp_create.pl model Foo DBIC::SchemaLoader dsn user password + script/myapp_create.pl model Foo DBIC::SchemaLoader [ connect info arguments ] - Where: - Foo is the short name for the Model class being generated - dsn, user, and password are the connection info + Where: + Foo is the short name for the Model class being generated + connect_info 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. + +=head1 TYPICAL EXAMPLE + + script/myapp_create.pl model Foo DBIC::SchemaLoader dbi:mysql:foodb myuname mypass '{ AutoCommit => 1 }' =head1 DESCRIPTION @@ -37,7 +44,11 @@ list for this package, but is not required for installation. =cut sub mk_compclass { - my ( $self, $helper, $dsn, $user, $pass ) = @_; + my ($self, $helper, @connect_info) = @_; + + for(@connect_info) { + $_ = qq{'$_'} if $_ !~ /^\s*[[{]/; + } $helper->{loader_class} = $helper->{class}; $helper->{loader_class} =~ s/\:\:M(?:odel)?\:\:/::SchemaLoader::/; @@ -48,10 +59,7 @@ sub mk_compclass { my $loader_file = File::Spec->catfile( $loader_dir, $loader_file_part . '.pm' ); $helper->mk_dir($loader_dir); - - $helper->{dsn} = $dsn || ''; - $helper->{user} = $user || ''; - $helper->{pass} = $pass || ''; + $helper->{connect_info} = \@connect_info; $helper->mk_dir( $loader_dir ); $helper->render_file( 'loaderclass', $loader_file ); @@ -98,16 +106,10 @@ use strict; use base qw/DBIx::Class::Schema::Loader/; __PACKAGE__->load_from_connection( - dsn => '[% dsn %]', - user => '[% user %]', - pass => '[% pass %]', - options => { - RaiseError => 1, - PrintError => 0, - ShowErrorStatement => 1, - TraceLevel => 0, - AutoCommit => 1, - }, + connect_info => [ + [% FOREACH arg = connect_info %][% arg %], + [% END %] + ], relationships => 1, # debug => 1, ); diff --git a/lib/Catalyst/Model/DBIC/Schema.pm b/lib/Catalyst/Model/DBIC/Schema.pm index baf2a72..e422e88 100644 --- a/lib/Catalyst/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Model/DBIC/Schema.pm @@ -6,7 +6,7 @@ use NEXT; use UNIVERSAL::require; use Carp; -our $VERSION = '0.06'; +our $VERSION = '0.07'; __PACKAGE__->mk_classaccessor('composed_schema'); __PACKAGE__->mk_accessors('schema'); @@ -184,7 +184,14 @@ sub new { no strict 'refs'; foreach my $moniker ($self->schema->sources) { - *{"${class}::${moniker}::ACCEPT_CONTEXT"} = sub { + my $classname = "${class}::$moniker"; + $classname->require; + if($@ && $@ !~ /^Can't locate /) { + croak "Failed to load external class definition" + . "for '$classname': $@"; + } + + *{"${classname}::ACCEPT_CONTEXT"} = sub { shift; shift->model($model_name)->resultset($moniker); } diff --git a/t/04testapp.t b/t/04testapp.t index aff0e23..c431372 100644 --- a/t/04testapp.t +++ b/t/04testapp.t @@ -9,8 +9,8 @@ plan skip_all => 'Enable this optional test with $ENV{C_M_DBIC_SCHEMA_TESTAPP}' my $test_params = [ [ 'TestSchema', 'DBIC::Schema', '' ], - [ 'TestSchemaDSN', 'DBIC::Schema', 'fakedsn fakeuser fakepass' ], - [ 'TestSchemaLoader', 'DBIC::SchemaLoader', 'fakedsn fakeuser fakepass' ], + [ 'TestSchemaDSN', 'DBIC::Schema', q{fakedsn fakeuser fakepass '{ AutoCommit => 1 }'} ], + [ 'TestSchemaLoader', 'DBIC::SchemaLoader', q{fakedsn fakeuser fakepass '{ AutoCommit => 1 }'} ], ]; plan tests => (2 * @$test_params); @@ -28,7 +28,11 @@ chdir($cat_dir); foreach my $tparam (@$test_params) { my ($model, $helper, $args) = @$tparam; - system("$^X -I$blib_dir $creator model $model $helper $model $args"); + my $model_two = $model; + if($helper =~ /Loader/) { + $model_two = ''; + } + system("$^X -I$blib_dir $creator model $model $helper $model_two $args"); my $model_path = File::Spec->catfile($model_dir, $model . '.pm'); ok( -f $model_path, "$model_path is a file" ); my $compile_rv = system("$^X -I$blib_dir -I$catlib_dir -c $model_path");