in reply to Class variables in Moose?
test.pl
Person.pmuse Person; my $p = Person->new(age => 10); print "Person has age ", $p->age();
Types.pmpackage Person; use Moose; use Types; has 'age' => (is => 'rw', isa => 'AdmissibleAge'); 1;
I like to separate the type constraints in a separate module Types.pm. What I just told you is no news, of course, you can find very good introductions on the Moose homepage, the first aricles I read and which should give you a good start are the ones cited there by Randal L. Schwartz:package Types; use Moose::Util::TypeConstraints; subtype 'AdmissibleAge' => as 'Num' => where {$_ >= 0 and $_ <= 99}; 1;
http://www.stonehenge.com/merlyn/LinuxMag/col94.html
and
http://www.stonehenge.com/merlyn/LinuxMag/col95.html
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Class variables in Moose?
by skirnir (Monk) on Jun 05, 2008 at 08:33 UTC | |
by jds17 (Pilgrim) on Jun 05, 2008 at 10:11 UTC | |
by skirnir (Monk) on Jun 05, 2008 at 10:31 UTC |