Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
The code in XML::Parser::Style::Subs seems to be quite slow in some
situations, and also it silently eats any errors that might occur in
the call backs.

sub Start {
  no strict 'refs';
  my $expat = shift;
  my $tag = shift;
  my $sub = $expat-> . "::$tag";
  eval { &$sub($expat, $tag, @_) };

I've replaced it for my purposes with:

sub Start {
  no strict 'refs';
  my $sub = $_[0]-> . "::$_[1]";
  return unless defined &$sub;

The sub End was also modified analogously.)

This is faster and propagates errors as expected.  But it probably doesn't
work for AutoLoaded callbacks.  I don't care about that for my current
purposes, but for the sake of general improvement, is there a way to
arrange for the code to be faster and propagate errors while still working
for AutoLoad?



-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Re: XML::Parser::Style::Subs

Quoth xhoster@gmail.com:
Quoted text here. Click to load it

You ought to be able to use $_[0]->->can($_[1]) instead of defined
&$sub: packages which use AUTOLOAD ought to provide a corresponding
->can. Any that actually use AutoLoader will.

Of course, now you've replaced an eval BLOCK with a method call, which
is probably slower :). TBH, I don't think AutoLoader is much used now
(the benefits are arguable), and a package using AUTOLOAD for clever
tricks would be better off using the XML::Parser interface directly.

The right answer is to stop grubbing around in the symbol table and
write XML::Parser::Style::Hashref, which takes a hashref with the same
keys as the subs in ::Subs.


Site Timeline