jozef has asked for the wisdom of the Perl Monks concerning the following question:
Hi, mostly with DBIx::Class I have to often write:
my $foo = $bar->related1->related2->foo;While any of the related objects may not exist and return undef so it's necessary to test first or do an easy bad solution and use eval:
my $foo = eval{ $bar->related1->related2->foo };Which also means that when ever there is a typoo (for example misspelled relation name) inside eval {}, it's silently ignored.
And here is my question: Is there a module or an easy way to say Perl that in this given scope when ever method is called on undef return undef instead of an exception? Here is how it would look like:
my $foo = undef_is_undef { undef->bar };Thanks!
Jozef
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: undef is undef
by Corion (Patriarch) on Aug 29, 2012 at 08:44 UTC | |
|
Re: undef is undef
by moritz (Cardinal) on Aug 29, 2012 at 08:52 UTC | |
by jozef (Sexton) on Aug 29, 2012 at 09:07 UTC | |
by moritz (Cardinal) on Aug 29, 2012 at 10:11 UTC | |
|
Re: undef is undef
by philiprbrenan (Monk) on Aug 29, 2012 at 13:00 UTC | |
|
Re: undef is undef
by andye (Curate) on Aug 29, 2012 at 13:42 UTC | |
|
Re: undef is undef
by locked_user sundialsvc4 (Abbot) on Aug 29, 2012 at 14:32 UTC |