Thanks for the feedback. I don't mean to be argumentative but if you write a Perl subroutine expecting a certain type of data (say a hashref), how do you handle the case where the routine is called with something else (say an integer).
As far as I can tell you only have two options: i.e. yolo! and let it crash, or try to do some simple sanity checking. The simple sanity checking is defensive programming (and you're forced to do it (or at the very least, coerced)).
The most recent release of Venus, v1.30, ships with a simple type assertion framework that all standard library classes utilize via the "make" method. The new method still allows value classes to accept bad values, intentionally. The idea is that "make" is useful in situations where you're unsure about the data being submitted. Obvisouly "make" (e.g. new w/type checking) is not as performant as "new".
Venus::Number->make;
# Exception!
Venus::Number->make(0,0);
# bless(..., "Venus::Number")
Venus::Number->make(1);
# bless(..., "Venus::Number")
Venus::Number->make('abc');
# Exception!
Venus::Number->new([3,2,1]);
# Exception!
Venus::Number->new([3,2,1])->abs;
# Exception!
"I am inevitable." - Thanos
|