Adam,
On Nov 23, 2004, at 9:30 PM, Adam Kennedy wrote:
For similar situations, I've solved this problem for most of my code with method naming. Any capitalized method guarantees to return the object (or die) and any lowercase one doesn't.
So this is safe.
$object->Parent->Metadata->Property('Foo');
while this is not
$object->parent->metadata->property('Foo');
For some classes, you just make one or the other, for some classes you might actually want to define both.
sub parent { my $self = shift ... or return undef; $self; }
sub Parent { shift->parent(@_) or die "Failed to find parent node" }
This means that the code can make a judgment on how "safe" it needs to be on a case by case basis.
For things that should never fail and you would justifiably want to throw an error/exception, you use ucfirst version, for more "tentative" code you stick to the normal ones.
I like that ... very nice :)
Of course it's too late now to go back and change thousands of lines of code, but I think i will consider that technique in the future.
Steve
_______________________________________________ sw-design mailing list [EMAIL PROTECTED] http://metaperl.com/cgi-bin/mailman/listinfo/sw-design
