Object-InsideOut - Object::InsideOut v1.13 - Custom Type Checking

Posted on Mon Nov 21 18:33:28 2005 by jdhedden
Object::InsideOut v1.13 - Custom Type Checking
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.
Write a response