bump to 0.03, added new helper to support automatic inline ::Schema::Loader
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Model / DBIC / Schema.pm
index a83084c..201ac29 100644 (file)
@@ -4,9 +4,10 @@ use strict;
 use base qw/Catalyst::Model Class::Accessor::Fast Class::Data::Accessor/;
 use NEXT;
 use UNIVERSAL::require;
+use UNIVERSAL qw/ can /;
 use Carp;
 
-our $VERSION = '0.01';
+our $VERSION = '0.03';
 
 __PACKAGE__->mk_classaccessor('composed_schema');
 __PACKAGE__->mk_accessors('schema');
@@ -55,16 +56,19 @@ 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.
+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::SchemaInlineLoader> for information
+on generating these Models via Helper scripts.
 
 =head1 CONFIG PARAMETERS
 
@@ -145,8 +149,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;
@@ -157,8 +160,11 @@ sub new {
 
     my $schema_class = $self->{schema_class};
 
-    $schema_class->require
-        or croak "Cannot load schema class '$schema_class': $@";
+    # don't require if the class is already loaded...
+    if( !can($schema_class, 'source') ) {
+        $schema_class->require
+            or croak "Cannot load schema class '$schema_class': $@";
+    }
 
     if( !$self->{connect_info} ) {
         if($schema_class->storage && $schema_class->storage->connect_info) {
@@ -173,7 +179,7 @@ sub new {
     $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) {
@@ -192,8 +198,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::SchemaInlineLoader>
 
 =head1 AUTHOR