release for 0.07, ->require and connect_info args stuff
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Model / DBIC / Schema.pm
index e7d7a83..e422e88 100644 (file)
@@ -1,14 +1,14 @@
 package Catalyst::Model::DBIC::Schema;
 
 use strict;
-use base qw/Catalyst::Base Class::Accessor::Fast Class::Data::Accessor/;
+use base qw/Catalyst::Model Class::Accessor::Fast Class::Data::Accessor/;
 use NEXT;
 use UNIVERSAL::require;
 use Carp;
 
-our $VERSION = '0.01';
+our $VERSION = '0.07';
 
-__PACKAGE__->mk_classdata('composed_schema');
+__PACKAGE__->mk_classaccessor('composed_schema');
 __PACKAGE__->mk_accessors('schema');
 
 =head1 NAME
@@ -55,16 +55,24 @@ Catalyst::Model::DBIC::Schema - DBIx::Class::Schema Model Class
     # or, if your schema works on different storage drivers:
     my $newconn = $c->model('Foo')->composed_schema->clone();
     $newconn->storage_type('::LDAP');
-    $newconn->connect(...);
+    $newconn->connection(...);
 
     # and again, a convenience shortcut
     my $newconn = $c->model('Foo')->clone();
     $newconn->storage_type('::LDAP');
-    $newconn->connect(...);
+    $newconn->connection(...);
 
 =head1 DESCRIPTION
 
-This is a Catalyst Model for L<DBIx::Class::Schema>-based Models.
+NOTE: This is the first public release, there's probably a higher than
+average chance of random bugs and shortcomings: you've been warned.
+
+This is a Catalyst Model for L<DBIx::Class::Schema>-based Models.  See
+the documentation for L<Catalyst::Helper::Model::DBIC::Schema> and
+L<Catalyst::Helper::Model::DBIC::SchemaLoader> for information
+on generating these Models via Helper scripts.  The latter of the two
+will also generated a L<DBIx::Class::Schema::Loader>-based Schema class
+for you.
 
 =head1 CONFIG PARAMETERS
 
@@ -145,8 +153,7 @@ Shortcut for ->schema->resultset
 =cut
 
 sub new {
-    my ( $self, $c ) = @_;
-    $self = $self->NEXT::new($c);
+    my $self = shift->NEXT::new(@_);
     
     my $class = ref($self);
     my $model_name = $class;
@@ -166,18 +173,25 @@ sub new {
         }
         else {
             croak "Either ->config->{connect_info} must be defined for $class"
-                  . " or $schema_class must have connection defined on it";
+                  . " or $schema_class must have connect info defined on it";
         }
     }
 
     $self->composed_schema($schema_class->compose_namespace($class));
     $self->schema($self->composed_schema->clone);
     $self->schema->storage_type($self->{storage_type}) if $self->{storage_type};
-    $self->schema->connect(@{$self->{connect_info}});
+    $self->schema->connection(@{$self->{connect_info}});
 
     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);
         }
@@ -192,8 +206,16 @@ sub connect { shift->composed_schema->connect(@_); }
 
 =head1 SEE ALSO
 
-L<Catalyst>, L<DBIx::Class>, L<DBIx::Class::Schema>,
-L<DBIx::Class::Schema::Loader>
+General Catalyst Stuff:
+
+L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
+L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
+
+Stuff related to DBIC and this Model style:
+
+L<DBIx::Class>, L<DBIx::Class::Schema>,
+L<DBIx::Class::Schema::Loader>, L<Catalyst::Helper::Model::DBIC::Schema>,
+L<Catalyst::Helper::Model::DBIC::SchemaLoader>
 
 =head1 AUTHOR