On Sep 26, 2008, at 19:21, David E. Wheeler wrote:
On Sep 26, 2008, at 18:48, Eric Wilhelm wrote:I would rather it just be a hash. The ({}) thing is redundant.You mean you'd rather it be a list. I agree, but it needs to be a hashref in order to disambiguate it from the original calling syntax, in order to maintain backward compatibility.So, $name is required, and if what's left is an even number, it's a hash. If it's odd, $default = shift(@_).Hrm. Okay, that works, too.
And here it is. This patch makes the following changes:* Default values passed to `add_property()` may now be code references, in which case the return value of the code ref will be used as the default.
* Add property now has the above-discussed interface. The `default` argument or parameter can be a code reference, as just described. The `check` parameter is an optional code reference that must return true if a new value is valid, and false it is invalid. If the property is a hash, the entire hash will be verified once new values have been assigned. I've also more tightly scoped the use of `no strict 'refs';` in the method, so that accessors still work when called as class methods (Huh?).
* Added `property_error()`. This method should be called by check code refs that detect invalid values. Right now it just calls `die`. Let me know if it should do something different.
* Made use of the new functionality when defining the "installdirs" property, per Schwern's example. What other properties should we check?
* Added tests for this stuff.* Documented `add_property()` and `property_error()`. I had no idea that `add_property()` was never documented before! Check those docs for more details on how `add_property()` works.
Best, David
add_property.patch
Description: Binary data