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
---
name: Catalyst-Model-DBIC-Schema
-version: 0.06
+version: 0.07
author:
- 'Brandon L Black, C<blblack@gmail.com>'
abstract: DBIx::Class::Schema Model Class
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
=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
=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};
__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
=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
=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::/;
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 );
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,
);
use UNIVERSAL::require;
use Carp;
-our $VERSION = '0.06';
+our $VERSION = '0.07';
__PACKAGE__->mk_classaccessor('composed_schema');
__PACKAGE__->mk_accessors('schema');
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);
}
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);
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");