I have a Moose object with a non-required attribute:
has 'optional_attr' => (
is => 'ro',
isa => 'MyCoolType',
required => 0,
);
How can I confess if I ever try to read this attribute while it’s not set?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
How about:
You might want to throw in a predicate, too:
so you can find out if it’s set without dying.
There’s also MooseX::LazyRequire, which lets you say just:
Under the hood, it uses the same trick I suggested, but it looks more elegant in your class.