Just FYI, I suggest usingTry::Tiny instead of plain eval.



On Sep 8, 2009, at 8:07 PM, Yuri Shtil wrote:

Hans Dieter Pearcey wrote:
Excerpts from Yuri Shtil's message of Tue Sep 08 19:26:57 -0400 2009:

What is the right way to see if an object has certain attribute?


 if (Moose::Util::find_meta($obj)->find_attribute_by_name("foo")) {
   do some stuff
 }

I almost never find myself wanting this, though (except when writing MooseX modules, and then not often), so I'm curious what you're doing that needs it.

hdp.


In my case the access to an attribute may be attempted with a wrong name. I want to provide an error message more intelligent than standard Perl carp like Can't locate object method "foo" via package "Bar". I don't want to put each access code into an eval ...

There is more to it in the actual project of course.



--

Yuri


Reply via email to