|
|
| Just another Perl shrine | |
| PerlMonks |
[perl6] Complex Attribute Validation and/or Triggersby duelafn (Parson) |
| on Mar 06, 2015 at 15:03 UTC ( [id://1119046]=perlquestion: print w/replies, xml ) | Need Help?? |
|
duelafn has asked for the wisdom of the Perl Monks concerning the following question: Are there ways in perl6 to write more complex attribute validators and/or before/after/around modifiers on attribute access? I can't seem to find anything that would let me, say, implement an interval class with a lower and upper bound, or call some code every time an attribute is changed. Did I miss it somewhere?
Update: Thanks all, tye makes a great point about the folly of such a design and raiph hunted down some additional options — though implemented as lvalue methods, we can not distinguish reading from writing. To me, it looks like the is rw trait on attributes should, in most cases, be avoided. Using it does limit what you are able to validate (fundamentally, not due to language shortcomings). Thus a recommended alternate implementation:
And if one really wants independent validating setters or distinct
read/write triggers,
Good Day,
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||