Checking if a Moose object has a value

[email protected] (Ben Edwards) Thu, 06 Feb 2014 12:30:12 +0000
Newsgroups perl.moose
Message-ID <[email protected]>
Hi,

I was wondering if there is a way to use moose to check if an attribute 
has a value;

As background, I am writing a function that, given an object, will loop 
over that objects attribute, and print (for the sake of simplicity) the 
value of that attribute, but will not invoke any lazy builders. ( but 
will print the value of a lazy attribute the builder has been called 
already )

The following code fulfills this requirement:

for my $attr ($object->meta->get_all_attributes) {
     my $name = $attr->name;

     # Lazy attributes that have not already been generated will not
     # exist in the object hash.
     next unless exists $object->{$name}

     my $value = $object->$name;
     print $value;
}

I guess what I am looking for is a more elegant and "Moosey" alternative 
to the "exists $object->{$name}" statement in the code above.

Thanks in advance for any help,

Ben

P.S. I have not actually asked a question on a mailing list before, any 
feedback regarding how I could better phrase this, or extra information 
to be included, would be greatly appreciated