in reply to Stringing method calls

This isn't very pretty, but first define a class:
package Undef; sub AUTOLOAD { undef; }
and then you can string at the cost of a few parens with:
$text = (( $elt->first_child( 'subelt') || 'Undef' )->first_child( 'subsubelt')||'Undef' )->text();
Don't like that? Well then you can just create a method to do the calls dynamically like this:
# Takes an array of anon arrays of method calls, and # chains them. Returns the first non-object of the end of # the call. sub chain_meth { my $obj = shift; my $last_call = pop; foreach my $call (@_) { my ($meth, @args) = @$call; $obj = $obj->$meth(@args); return $obj unless ref($obj); } # Make the last one respect context properly. my ($meth, @args) = @$last_call; return $obj->$meth(@args); }
and now you can:
$text = $elt->chain_meth( ["first_child", "subelt"], ["first_child", "subsubelt"], ["text"] );