Question

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!

Was it helpful?

Solution

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

has foo => (
  is        => 'rw',
  lazy      => 1,
  predicate => 'has_foo',
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top