Subject: | eq_predicates |
I'd really like to be able to define some predicates along these lines:
use Class::XSAccessor eq_predicates => {
is_pass => [ status => 'pass' ],
is_fail => [ status => 'fail' ],
};
Which would be equivalent to:
sub is_pass { $_[0]{status} eq 'pass' }
sub is_fail { $_[0]{status} eq 'fail' }
Why? Because currently the pure-Perl functions above are measurably slower than:
if ( $obj->status eq "pass" ) { ... }
And I'd really like to encourage a programming style of:
if ( $obj->is_pass ) { ... }
... which leads to fewer magic constants scattered around code, and fewer typos causing hard to detect errors.
Making these predicates faster using Class::XSAccessor would be a big selling point in their favour.