Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moose - Determine if Lazy Attribute has been set

Tags:

perl

moose

I'm trying to figure out a way to see if one of my lazily built attributes has been set or not. I've scoured the docs for both Moose::Meta::Attribute and and Class::MOP::Attribute, and saw the get_value and has_value methods, but they don't seem to be working for me.

The documentation for get_value says:

$attr->has_value($instance)

But what is $instance? I tried using my object, but that just returns the error:

"You must pass a package name and it cannot be blessed.."

Any help is appreciated!

like image 349
Ryan Avatar asked Mar 07 '14 07:03

Ryan


1 Answers

What you probably want is a predicate on your attribute. E.g.

has foo => (
  is        => 'rw',
  lazy      => 1,
  predicate => 'has_foo',
);
like image 164
Leon Timmermans Avatar answered Nov 11 '22 08:11

Leon Timmermans