#### use strict; use warnings; use XML::Parser::Lite; my $doc = "\n"; print "'$doc'\n"; my $parser = XML::Parser::Lite->new( Handlers => { Start => sub { shift; print "Start: @_\n"; }, Char => sub { shift; print "Char: @_\n"; }, End => sub { shift; print "End: @_\n"; }, }, ); $parser->parse($doc); print "Finally done\n"; -------- ' ' Start: foo End: foo Finally done #### Foo/Bar.pm package Foo::Bar; sub new { bless {} } 1; __END__ ---- main.pl use strict; use warnings; use XML::Parser::Lite; my $doc = "\n"; print "'$doc'\n"; my %Names = ( foo => 'Foo::Bar', ); my @stack; my $parser = XML::Parser::Lite->new( Handlers => { Start => sub { shift; print "Start: @_\n"; my $pkg = shift; (my $name = $Names{$pkg}) =~ s!::!/!g; $name .= '.pm'; eval { require $name; }; if ($@) { die "Cannot require '$name' ($pkg)\n"; } my $x = $Names{$pkg}->new(@_); push @stack, $x; }, End => sub { shift; print "End: @_\n"; pop @stack if @stack; }, }, ); $parser->parse($doc); print "Finally done\n"; #### ' ' Start: foo 50356: terminated with signal 4 -- core dumped #### ' ' Start: foo 13000: terminated with signal 11 -- core dumped #### ' ' Start: foo End: foo corrupted regexp pointers at (eval 1) line 1.