# 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); }