Skip Menu |

This queue is for tickets about the XML-Twig CPAN distribution.

Report information
The Basics
Id: 168
Status: resolved
Worked: 15 min
Priority: 0/
Queue: XML-Twig

People
Owner: Nobody in particular
Requestors: jerry [...] matilda.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.02
Fixed in: 3.03



Subject: XML::Twig 3.0.2 problem with setTwigHandler
Never used this bug system, so if I don't hear something in a day or so, I'll repost to perl-xml mailing list. XML::Twig 3.0.2 perl, v5.6.1 built for i386-openbsd When I run "testscript.pl 1" or "testscript.pl 2" everything works as expected, but "testscript.pl 3" fails. Kinda expected test '3' to work as well. Am I missing something ? Do I have to specify at least one handler in the initalizer ? jerry@matilda.com
#!/usr/bin/perl use strict; use XML::Twig; my $twig; sub printit { $_[1]->print(); print "\n"; $_[0]->purge(); } my $test=shift; if ( $test eq "1" ) { print "Running test 1..\n"; $twig= new XML::Twig(TwigHandlers=>{ '/books/book/name' => \&printit}); } elsif ( $test eq "2" ) { print "Running test 2..\n"; $twig=new XML::Twig(); $twig->setTwigHandlers({'/books/book/name'=>\&printit}); } else { print "Running test 3..\n"; $twig=new XML::Twig(); $twig->setTwigHandler('/books/book/name', \&printit); } undef($/); $twig->parse(<DATA>); exit(0); __END__ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <!DOCTYPE books SYSTEM "books.dtd"> <books> <book id="21714"><name>Book Title1</name></book> <book id="21642"><name>Book Title2</name></book> </books>
[guest - Mon Jan 21 18:51:45 2002]: Show quoted text
> XML::Twig 3.0.2 > perl, v5.6.1 built for i386-openbsd > > When I run "testscript.pl 1" or "testscript.pl 2" everything works > as expected, but "testscript.pl 3" fails. > Kinda expected test '3' to work as well.
And you had every right to expect so! The twig_handlers field for the twig is not initialized by setTwigHandler but by setTwigHandlers (note the plural), which is quite an oversight on my part. The patch is to write: $twig=new XML::Twig(); $twig->{twig_handlers} ||={}; $twig->setTwigHandler('/books/book/name', \&printit); in test 3 or to add $t->{twig_handlers} ||={}; before line 912 in Twig.pm.slow This will be fixed in 3.03
[guest - Mon Jan 21 18:51:45 2002]: Show quoted text
> XML::Twig 3.0.2 > perl, v5.6.1 built for i386-openbsd > > When I run "testscript.pl 1" or "testscript.pl 2" everything works > as expected, but "testscript.pl 3" fails. > Kinda expected test '3' to work as well.
And you had every right to expect so! The twig_handlers field for the twig is not initialized by setTwigHandler but by setTwigHandlers (note the plural), which is quite an oversight on my part. The patch is to write: $twig=new XML::Twig(); $twig->{twig_handlers} ||={}; $twig->setTwigHandler('/books/book/name', \&printit); in test 3 or to add $t->{twig_handlers} ||={}; before line 912 in Twig.pm.slow This will be fixed in 3.03
[guest - Mon Jan 21 18:51:45 2002]: Show quoted text
> XML::Twig 3.0.2 > perl, v5.6.1 built for i386-openbsd > > When I run "testscript.pl 1" or "testscript.pl 2" everything works > as expected, but "testscript.pl 3" fails. > Kinda expected test '3' to work as well.
And you had every right to expect so! The twig_handlers field for the twig is not initialized by setTwigHandler but by setTwigHandlers (note the plural), which is quite an oversight on my part. The patch is to write: $twig=new XML::Twig(); $twig->{twig_handlers} ||={}; $twig->setTwigHandler('/books/book/name', \&printit); in test 3 or to add $t->{twig_handlers} ||={}; before line 912 in Twig.pm.slow This will be fixed in 3.03