mirod wrote: If I use a Null Object I cannot write if( $elt->first_child) {...} anymore.
Ovid begs to differ :)
package Null::Object; use overload 'bool' => \&bool; my $self; sub new { $self ||= bless {}, shift } sub AUTOLOAD { $self } sub bool { return; } package main; my $null = Null::Object->new; $null->foo->bar->baz; if ($null) { print "We shouldn't be here!"; } else { print "We are false!"; }
That might need a bit of tuning, but you get the idea.
Update: I just noticed that you mentioned overload, so my bit of code is not news to you :) On the other hand, if clean null objects is the only benefit of autoboxing, then I again can't see much of a benefit to them. I might also add that null objects should be the exception rather than the rule, thus the performance impact should be minimal (I hope).
Cheers,
Ovid
New address of my CGI Course.
In reply to Re(6): Null objects in boolean context
by Ovid
in thread Autoboxing: Yes or No?
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |