Indeed it is fun. I love the language and now with Inline::Perl5 the number of projects I'm willing to try it out on is greatly increased!
Thanks for all your research and link to proxys. Indeed, it looks like these can save us if we were to create a class with a publicly writable attribute which really should have been implemented as a method. And, indeed there do seem to be bugs lurking still. I can't quite get it to work now, but am sufficiently satisfied that something like this will eventually:
class Interval { has Real $.lb = die 'Lower bound is required'; has Real $.ub = die 'Upper bound is required'; method lb() is rw { return Proxy.new: FETCH => method () { return $!lb; }, STORE => method ($lb) { die "Require lb <= ub" unless $lb <= $!ub; $!lb = $lb; }; } method ub() is rw { return Proxy.new: FETCH => method () { return $!ub; }, STORE => method ($ub) { die "Require lb <= ub" unless $!lb <= $ub; $!ub = $ub; }; } }
Good Day,
Dean
In reply to Re^2: [perl6] Complex Attribute Validation and/or Triggers
by duelafn
in thread [perl6] Complex Attribute Validation and/or Triggers
by duelafn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |