Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > XML::Parser::Style::Subs

Reply
Thread Tools

XML::Parser::Style::Subs

 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-14-2008
The code in XML:arser::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->{Pkg} . "::$tag";
eval { &$sub($expat, $tag, @_) };
}

I've replaced it for my purposes with:

sub Start {
no strict 'refs';
my $sub = $_[0]->{Pkg} . "::$_[1]";
return unless defined &$sub;
&$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?

Thanks,

Xho

--
-------------------- 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.
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      03-14-2008

Quoth http://www.velocityreviews.com/forums/(E-Mail Removed):
> The code in XML:arser::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->{Pkg} . "::$tag";
> eval { &$sub($expat, $tag, @_) };
> }
>
> I've replaced it for my purposes with:
>
> sub Start {
> no strict 'refs';
> my $sub = $_[0]->{Pkg} . "::$_[1]";
> return unless defined &$sub;
> &$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?


You ought to be able to use $_[0]->{Pkg}->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:arser interface directly.

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

Ben

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments