change no sources error to warning, write connect_info to model with no create= option
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Model / DBIC / Schema.pm
index 6c1c67a..d9fc47d 100644 (file)
@@ -5,7 +5,7 @@ use mro 'c3';
 extends 'Catalyst::Model';
 with 'CatalystX::Component::Traits';
 
-our $VERSION = '0.28';
+our $VERSION = '0.30';
 $VERSION = eval $VERSION;
 
 use namespace::autoclean;
@@ -14,7 +14,7 @@ use Data::Dumper;
 use DBIx::Class ();
 
 use Catalyst::Model::DBIC::Schema::Types
-    qw/ConnectInfo LoadedClass/;
+    qw/ConnectInfo LoadedClass SchemaClass/;
 
 use MooseX::Types::Moose qw/ArrayRef Str ClassName Undef/;
 
@@ -445,7 +445,7 @@ Used often for debugging and controlling transactions.
 
 has schema_class => (
     is => 'ro',
-    isa => LoadedClass,
+    isa => SchemaClass,
     coerce => 1,
     required => 1
 );
@@ -546,8 +546,15 @@ sub _install_rs_models {
 
     my @sources = $self->schema->sources;
 
-    die "No sources found (did you forget to define your tables?)"
-        unless @sources;
+    unless (@sources) {
+        warn <<'EOF' unless $ENV{CMDS_NO_SOURCES};
+******************************* WARNING ***************************************
+* No sources found (did you forget to define your tables?)                    *
+*                                                                             *
+* To turn off this warning, set the CMDS_NO_SOURCES environment variable.     *
+*******************************************************************************
+EOF
+    }
 
     foreach my $moniker (@sources) {
         my $classname = "${class}::$moniker";
@@ -640,6 +647,17 @@ sub _pass_options_to_schema {
 
 __PACKAGE__->meta->make_immutable;
 
+=head1 ENVIRONMENT
+
+=over 4
+
+=item CMDS_NO_SOURCES
+
+Set this variable if you will be using schemas with no sources (tables) to
+disable the warning. The warning is there because this is usually a mistake.
+
+=back
+
 =head1 SEE ALSO
 
 General Catalyst Stuff:
@@ -668,6 +686,8 @@ caelum: Rafael Kitover C<rkitover at cpan.org>
 
 Dan Dascalescu C<dandv at cpan.org>
 
+Aran Deltac C<bluefeet@cpan.org>
+
 =head1 COPYRIGHT
 
 This program is free software. You can redistribute it and/or modify it