http://www.perlmonks.org?node_id=990411


in reply to Re: undef is undef
in thread undef is undef

Well, even for one level it is necessary to check first. here's real world example:

my $avatar = $usr->person->avatar;

usr and person (extended information about user) are two tables. not every user has to have extended information and the code snipped just wants to find out if user has avatar.

Adding accessor to usr sounds like a wise solution to hide test ifs, but it will mask the fact that avatar is accessor of person.

Replies are listed 'Best First'.
Re^3: undef is undef
by moritz (Cardinal) on Aug 29, 2012 at 10:11 UTC
    Adding accessor to usr sounds like a wise solution to hide test ifs, but it will mask the fact that avatar is accessor of person.

    Hiding unneeded facts is what abstraction is all about. Why should a user of your backend model care about which table the avatar comes from? If the user doesn't have to care, it means you can change that stuff later on the in the database and only adapt your model, not your code that generates the HTML.