in reply to Class variables in Moose?

Moose has a special syntax for this, if you don't use it, you are not really using Moose. In your case you could say e.g. (I left use strict / warnings out for brevity):

test.pl

use Person; my $p = Person->new(age => 10); print "Person has age ", $p->age();
Person.pm
package Person; use Moose; use Types; has 'age' => (is => 'rw', isa => 'AdmissibleAge'); 1;
Types.pm
package Types; use Moose::Util::TypeConstraints; subtype 'AdmissibleAge' => as 'Num' => where {$_ >= 0 and $_ <= 99}; 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:

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
    I think your solution will take care of the assumed semantics of maximum_age but that's a constraint rather than a class variable.

    I don't know if there's a different way in Moose to do that, but How do I create static class variables (class data)? may be what the OP is looking for.

      skirnir, you are right, I missed the point this time, I completely overlooked the word Class, sorry :-(
        Well, if the above is a real life example, chances are that you solved an XY Problem for the OP.