I think this is a problem best left unaddressed. In general OO the Law of Demeter forbids such deep hierarchy navigation constructs.
Now, manipulating XML (or other document) structures is a very specific case, and not all the common OO rules necessarily apply. However, I'd argue that this means you should rather be using a language addressed at this specific problem domain. Which in this case does exist and should be obvious: XPath. Indeed, something like this behaves exactly the way you specified:
# LibXML lingo; XPath expr is off the cuff, untested $doc->findvalue('/section[last()]/title[1]/@num');
All that said, even methods on undef would not really solve the issue, just sweep it under the rug. Doing this well and cleanly in Perl would require something along the lines of
$doc->root(sub { $_->last_child( 'section', sub { $_->first_child( 'title', sub { $_->att( 'num') }) }) });
In summary, you will not be able to solve this satisfactorily and concisely in a language without continuations. Which isn't so bad, because this particular problem is likely better left unsolved.
Makeshifts last the longest.
In reply to Re^4: Autoboxing: Yes or No?
by Aristotle
in thread Autoboxing: Yes or No?
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |