> So if all I want to do is make sure that certain attributes are positive
> integers, I have to do this:
>
> [ admittedly ungainly solutions snipped ]
>
> I'd much prefer a solution where the positive-only logic was in a method
> belonging to the class, rather than being attached to afflicted attributes.
> The only ways I can see of doing this are like Gnat or Andy's RFCs.
TMTTWTDO! ;-)
What you really want is a postcondition or class invariant.
One that asserts that x is always positive:
sub new { bless {}, $_[0] }
sub x { lreturn $_[0]->{x} }
# and one of...
post x { $_[0]->{x} >= 0 } # post condition on x attribute
ensure { $_[0]->{x} >= 0 } # class invariant
Damian
- Re: RFC 118 (v1) lvalue subs: parameters, explicit assig... Johan Vromans
- Re: RFC 118 (v1) lvalue subs: parameters, explicit ... Graham Barr
- Re: RFC 118 (v1) lvalue subs: parameters, expli... Johan Vromans
- Re: RFC 118 (v1) lvalue subs: parameters, explicit ... Buddha Buck
- Re: RFC 118 (v1) lvalue subs: parameters, expli... Johan Vromans
- Re: RFC 118 (v1) lvalue subs: parameters, explicit ... Chaim Frenkel
- Re: RFC 118 (v1) lvalue subs: parameters, expli... Graham Barr
- Re: RFC 118 (v1) lvalue subs: parameters, e... Chaim Frenkel
- Re: RFC 118 (v1) lvalue subs: parameters, e... Damian Conway
- Re: RFC 118 (v1) lvalue subs: parameters, e... perl6
- Re: RFC 118 (v1) lvalue subs: parameters, e... Damian Conway
- Re: RFC 118 (v1) lvalue subs: parameters, e... Chaim Frenkel
- Re: RFC 118 (v1) lvalue subs: parameters, e... Damian Conway
- Re: RFC 118 (v1) lvalue subs: parameters, e... Chaim Frenkel
- Re: RFC 118 (v1) lvalue subs: parameters, e... Damian Conway
- Re: RFC 118 (v1) lvalue subs: parameters, e... Chaim Frenkel
- Re: RFC 118 (v1) lvalue subs: parameters, e... Damian Conway
- Re: RFC 118 (v1) lvalue subs: parameters, e... Chaim Frenkel
- Re: RFC 118 (v1) lvalue subs: parameters, e... Nathan Torkington
- Re: RFC 118 (v1) lvalue subs: parameters, e... Chaim Frenkel
- Re: RFC 118 (v1) lvalue subs: parameters, e... Damian Conway
