[Dbix-class] Got a problem using DBIC+Params::Validate
Oleg Kostyuk
cub.uanic at gmail.com
Mon Mar 29 11:06:58 GMT 2010
2010/3/29 Konstantin A. Pustovalov <lamoz at adriver.ru>:
> On 03/26/2010 07:20 PM, Oleg Kostyuk wrote:
>>
>> IIRC, evaluating ResultSet in scalar contex will issue count() call.
>>
>
> ResultSet is a blessed reference which is scalar.
> Can't i say $something = $rs ?
Yes, you can. I was not fully correct here. More correct will be
next:evaluating ResultSet in _numeric_ contex will issue count() call,
see http://search.cpan.org/~ribasushi/DBIx-Class-0.08120/lib/DBIx/Class/ResultSet.pm#OVERLOADING
. And so, at first comparsion with non-string, which will give you
boolean context (which in turn is one of possible numeric contexts),
you will get count() call.
I think, will be better to use something like this:
<cut>
package Test::Schema::ResultSet::User;
use strict;
use base 'DBIx::Class::ResultSet';
use Params::Validate qw/:all/;
sub touch {
my $self = shift;
validate_pos( ref($self), { regex => m/^__PACKAGE__$/ } );
}
1;
</cut>
Of course, this is not exactly what you wanted, because don't support
inheritance, roles and so on. Feel free to modify and implement your
own callback-validation.
--
Sincerely yours,
Oleg Kostyuk (CUB-UANIC)
More information about the DBIx-Class
mailing list