Re: testing if an object has an attribute?

2009-10-14 Thread Yuri Shtil
Jesse Luehrs wrote: On Tue, Sep 08, 2009 at 04:26:57PM -0700, Yuri Shtil wrote: What is the right way to see if an object has certain attribute? I tried if $obj-can('foo') {} but got burned when something like 'import/export' gets in a way. Do I have to maintain the list of attributes

Re: testing if an object has an attribute?

2009-09-08 Thread Chris Prather
On Tue, Sep 8, 2009 at 7:46 PM, mega...@gmail.com wrote: Yuri Are you doing this in order to effect duck-typing? If so, you may want to consider applying the attributes with a Role, and using this idiom: if ($obj-does('fooer')) {} Or there is the duck_type helper in

Re: testing if an object has an attribute?

2009-09-08 Thread Hans Dieter Pearcey
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

Re: testing if an object has an attribute?

2009-09-08 Thread Jesse Luehrs
On Tue, Sep 08, 2009 at 04:26:57PM -0700, Yuri Shtil wrote: What is the right way to see if an object has certain attribute? I tried if $obj-can('foo') {} but got burned when something like 'import/export' gets in a way. Do I have to maintain the list of attributes (an another attribute

testing if an object has an attribute?

2009-09-08 Thread Yuri Shtil
What is the right way to see if an object has certain attribute? I tried if $obj-can('foo') {} but got burned when something like 'import/export' gets in a way. Do I have to maintain the list of attributes (an another attribute !!!) as I create them? -- Yuri

Re: testing if an object has an attribute?

2009-09-08 Thread Stevan Little
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

Re: testing if an object has an attribute?

2009-09-08 Thread Yuri Shtil
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