ingydotnet/mo-pm

is ro

Closed this issue · 2 comments

better exception message would be helpful if trying to set a read-only accessor, currently, there is no custom exception message, should be Moose like

Mo currently has no exceptions. I would like to see a Mo::errors feature
that added various checks and exceptions, since runtime checking on
thoroughly tested perl only slows things down (assuming an error will never
occur).

I'm not against runtime checks but if I add one I need to add 1000. So I'd
like them to be completely opt-in, opt-out again.

On Mon, Oct 10, 2011 at 6:17 PM, forwardever <
reply@reply.github.com>wrote:

better exception message would be helpful if trying to set a read-only
accessor, currently, there is no custom exception message, should be Moose
like

Reply to this email directly or view it on GitHub:
#12

what I mean is: die "$name is read-only accessor" instead of just die

package Mo::is;$MoPKG = "Mo::";
$VERSION = 0.28;

*{$MoPKG.'is::e'} = sub {
    my ($caller_pkg, $exports, $options) = @_;
    $options->{is} = sub {
        my ($method, $name, %args) = @_;
        $args{is} or return $method;
        sub {
            $#_ && $args{is} eq 'ro' && caller ne 'Mo::coerce'
              ? die 
                : $method->(@_)
        };
    };
};