Вопрос

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!

Это было полезно?

Решение

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

has foo => (
  is        => 'rw',
  lazy      => 1,
  predicate => 'has_foo',
);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top