From: Maik Hentsche Date: Mon, 14 Jun 2010 08:32:20 +0000 (+0200) Subject: Cleaner error message for using source() without required argument X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f5f2af8f28482296108000dd7f1fc906d9a7530e;hp=f213e483e07530f0c6d6cac5411fc8a6dc3d605f;p=dbsrgits%2FDBIx-Class-Historic.git Cleaner error message for using source() without required argument --- diff --git a/Changes b/Changes index 18ed595..c4256b9 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for DBIx::Class + * Fixes + - Throw comprehensible exception on erroneous $schema->source() + invocation + 0.08126_01 2011-01-14 14:00 (UTC) * New Features / Changes - Schema/resultsource instances are now crossreferenced via a new diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 20e38a3..acf2959 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -266,6 +266,8 @@ brunov: Bruno Vecchi caelum: Rafael Kitover +caldrin: Maik Hentsche + castaway: Jess Robinson claco: Christopher H. Laco diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 8270c27..4abd9dd 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -587,7 +587,13 @@ source name. =cut sub source { - my ($self, $moniker) = @_; + my $self = shift; + + $self->throw_exception("source() expects a source name") + unless @_; + + my $moniker = shift; + my $sreg = $self->source_registrations; return $sreg->{$moniker} if exists $sreg->{$moniker}; diff --git a/t/101source.t b/t/101source.t new file mode 100644 index 0000000..477a4dd --- /dev/null +++ b/t/101source.t @@ -0,0 +1,14 @@ +use warnings; +use strict; + +use Test::More; +use Test::Exception; + +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema; + +throws_ok {$schema->source()} qr/\Qsource() expects a source name/, 'Empty args for source caught'; + +done_testing();