From: Justin Guenther Date: Mon, 27 Feb 2006 22:48:48 +0000 (+0000) Subject: Fixed txn_do to check that $coderef is actually a code ref, and wrote parameter check... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=171dadd7f598063c1a6913da80a7cdfe6e83199c;p=dbsrgits%2FDBIx-Class-Historic.git Fixed txn_do to check that $coderef is actually a code ref, and wrote parameter check tests --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 554a0a4..631d5aa 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -418,8 +418,10 @@ transaction will issue a txn_commit on the Schema's storage) sub txn_do { my ($self, $coderef, @args) = @_; - ref $self or $self->throw_exception('Cannot execute txn_do as a '. - 'class method'); + ref $self or $self->throw_exception + ('Cannot execute txn_do as a class method'); + ref $coderef eq 'CODE' or $self->throw_exception + ('$coderef must be a CODE reference'); my (@return_values, $return_value); diff --git a/t/run/21transactions.tl b/t/run/21transactions.tl index 798a76b..8589fe8 100644 --- a/t/run/21transactions.tl +++ b/t/run/21transactions.tl @@ -1,6 +1,6 @@ sub run_tests { my $schema = shift; -plan tests => 37; +plan tests => 39; my $code = sub { my ($artist, @cd_titles) = @_; @@ -13,6 +13,19 @@ my $code = sub { return $artist->cds->all; }; +# Test checking of parameters +{ + + eval { + (ref $schema)->txn_do(sub{}); + }; + like($@, qr/class method/, '$coderef parameter check ok'); + eval { + $schema->txn_do(''); + }; + like($@, qr/must be a CODE reference/, '$coderef parameter check ok'); +} + # Test successful txn_do() - scalar context { my @titles = map {'txn_do test CD ' . $_} (1..5);