SPUG: can't die() from XML::Parser handlers?

Jason Lamport jason at strangelight.com
Sat Sep 15 19:20:17 CDT 2001


At 4:04 PM -0700 9/15/01, Colin Meyer wrote:
>
>Your guess is correct. Here's an excerpt of the XML::Parser code that
>shows it ignoring any error in your sub:
>
>###################################################################
>
>package XML::Parser::Subs;
>$XML::Parser::Built_In_Styles{Subs} = 1;
>
>sub Start {
>   no strict 'refs';
>   my $expat = shift;
>   my $tag = shift;
>   my $sub = $expat->{Pkg} . "::$tag";
>   eval { &$sub($expat, $tag, @_) };
>}
>
>###################################################################

Thanks for looking into it.  That's an annoying feature, but at least 
now that I know about it, I can get down to devising the 
least-kludgey work-around.

>
>I am not sure if there is a reasonable explanation of why the error
>is being trapped and ignored.

The only thing I can think of is if Perl's "subroutine not found" 
error messages aren't standard (or standard enough) across different 
platforms, making it difficult or impossible to recognize that 
particular error in all cases.  Ignoring the error when the 
subroutine simply doesn't exist makes sense, since you'll usually 
just want to ignore elements for which you haven't defined specific 
handlers.  But if possible, the code really ought to make sure that 
this is in fact why the subroutine call failed.

OTOH, if it's not possible to determine whether the call failed 
because of a non-defined subroutine, or for some other reason, then 
it seems like the Correct Thing To Do would be to let the error 
propagate: the user can always define an AUTOLOAD routine if they 
want to catch those subroutine calls.

-jason

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list