XML::Parser::Style::Subs

Discussion in 'Perl Misc' started by xhoster@gmail.com, Mar 14, 2008.

  1. Guest

    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->{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.
    , Mar 14, 2008
    #1
    1. Advertising

  2. Ben Morrow Guest

    Quoth :
    > 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->{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::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.

    Ben
    Ben Morrow, Mar 14, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    0
    Views:
    439
    Ken Varn
    Apr 26, 2004
  2. arne
    Replies:
    0
    Views:
    351
  3. Erik Wasser
    Replies:
    5
    Views:
    445
    Peter J. Holzer
    Mar 5, 2006
  4. Sean
    Replies:
    3
    Views:
    267
    robic0
    Oct 3, 2006
  5. Sean
    Replies:
    0
    Views:
    365
Loading...

Share This Page