# $Id$ package Dwarfs; use strict; use warnings; use version; our $VERSION = qv('0.0.1'); use Carp; use English qw( -no_match_vars ); use base 'Items'; use Date::Simple; use Params::Validate; __PACKAGE__->inflater(birthday => sub { my $self = shift; return Date::Simple->new( $self->birthday ); }); sub new { my $class = shift; return if !@_; # buzz off ;-) return $class->retrieve(@_) if @_ == 1; return $class->create(validate(@_, { name => 1, birthday => { callbacks => { 'well formed date' => sub { $_[0] && $_[0] =~ /^ \d{4} - \d\d - \d\d $/xms }, 'well grown' => sub { $_[0] =~ /^ (\d{4}) - (\d\d) - (\d\d) $/xms or return; my ( $y, $m, $d ) = ( $1, $2, $3 ); my $year = (localtime)[5] + 1900; return $year - $y > 17 && $m > 0 && $m < 13 && $d > 0 && $d < 32 } } }, height => { callbacks => { 'visible in plain sight' => sub { $_[0] && $_[0] =~ /^\d+$/ }, 'well grown' => sub { $_[0] > 49 }, 'not a dwarf' => sub { $_[0] < 121 }, } }, })); } 1;