# This is NOT a good way to validate for this use case. # But this code works in my current Rakudo. class Interval { has $.lb = die 'Lower bound is required'; has $.ub = die 'Upper bound is required'; method lb() is rw { return Proxy.new: # note `sub` declarator and ignored arg: FETCH => sub ($) { return $!lb; }, # note `sub` declarator and ignored (first) arg STORE => sub ($, $lb) { die "Require lb <= ub" unless $lb <= $!ub; $!lb = $lb; }; } method ub() is rw { return Proxy.new: FETCH => sub ($) { return $!ub; }, STORE => sub ($, $ub) { die "Require lb <= ub" unless $!lb <= $ub; $!ub = $ub; }; } }