1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
use FindBin;
use Test::More;
use utf8;
use strict;
use warnings;
{
package TestClass::DotNoation;
use Validation::Class;
has update => 0;
field 'public.fullname' => {
mixin => [':str', ':full_name'],
filters => ['autocase'],
required => 1,
};
field 'private.fullname' => {
mixin => ':str',
required => 1,
};
field 'private.emailaddress' => {
mixin => ':str',
required => 1,
email => 1
};
method 'dienice' => {
input => ['private.emailaddress', 'private.fullname'],
using => sub {
my $self = shift;
$self->update(1);
}
};
package main;
my $class = "TestClass::DotNoation";
my $self = $class->new(
params => {
'public.fullname' => 'Al Newkirk',
'private.fullname' => 'Al Newkirk',
'private.emailaddress' => 'awncorp@cpan.org',
}
);
ok $class eq ref $self, "$class instantiated";
ok $self->can('public_fullname'), "$class has public_fullname";
ok $self->can('private_emailaddress'), "$class has private_emailaddress";
ok $self->can('private_fullname'), "$class has private_fullname";
ok $self->can('dienice'), "$class has method dienice";
ok $self->validate('private.emailaddress', 'private.fullname'),
"$class validated private.emailaddress and private.fullname directly"
;
ok $self->dienice,
"$class validated private.emailaddress and private.fullname via dienice"
;
ok $self->update,
"$class set the 'updated' attr from the dienice self-validating method"
;
}
done_testing;
|