|
Object::InsideOut v1.13 adds support for custom type checking for initializers
(i.e., :InitArgs) and accessors. This allow you to you define your own type
checking routines using either named subroutines or anonymous subroutines:
package My::Class; {
use Object::InsideOut;
sub is_int {
my $arg = $_[0];
return (Scalar::Util::looks_like_number($arg) &&
(int($arg) == $arg));
}
my @level :Field('Accessor' => 'level', 'Type' => \&My::Class::is_int);
my @comment :Field('Accessor' => 'comment', 'Type' => sub { $_[0] ne '' });
my %init_args :InitArgs = (
'LEVEL' => {
'Field' => \@level,
'Type' => \&My::Class::is_int,
},
'COMMENT' => {
'Field' => \@comment,
'Type' => sub { $_[0] ne '' }
},
);
}
See the POD
for further details.
|