1 package Test::Valgrind::Parser::XML::Twig;
10 use base qw/XML::Twig Test::Valgrind::Carp/;
12 BEGIN { XML::Twig->add_options('Stash'); }
15 '/valgrindoutput/error' => \&handle_error,
20 $class = ref($class) || $class;
23 my $stash = delete $args{stash} || { };
25 my $tool = delete $args{tool};
26 $class->_croak('Invalid tool') unless Scalar::Util::blessed($tool)
27 and $tool->isa('Test::Valgrind::Tool');
28 $stash->{tool} = $tool;
30 bless $class->XML::Twig::new(
31 elt_class => __PACKAGE__ . '::Elt',
33 twig_roots => { map { $_ => 1 } keys %handlers },
34 twig_handlers => { map { $_ => $handlers{$_} } keys %handlers },
38 sub stash { shift->{Stash} }
41 my ($twig, $node) = @_;
43 my $id = $node->kid('unique')->text;
44 my $kind = $node->kid('kind')->text;
48 $data->{what} = $node->kid('what')->text;
49 $data->{stack} = [ map $_->listify_frame,
50 $node->kid('stack')->children('frame') ];
52 for (qw/leakedbytes leakedblocks/) {
53 my $kid = $node->first_child($_);
55 $data->{$_} = int $kid->text;
58 if (my $auxwhat = $node->first_child('auxwhat')) {
59 if (my $stack = $auxwhat->next_sibling('stack')) {
60 $data->{auxstack} = [ map $_->listify_frame, $stack->children('frame') ];
62 $data->{auxwhat} = $auxwhat->text;
65 if (my $origin = $node->first_child('origin')) {
66 $data->{origwhat} = $origin->kid('what')->text;
67 $data->{origstack} = [ map $_->listify_frame,
68 $origin->kid('stack')->children('frame') ];
71 my $tool = $twig->stash->{tool};
72 my $sess = $tool->_session;
74 $sess->report($tool->report_class($sess)->new(
83 # End of Test::Valgrind::Parser::XML::Twig
85 package Test::Valgrind::Parser::XML::Twig::Elt;
87 our $VERSION = '1.02';
89 BEGIN { require XML::Twig; }
91 use base qw/XML::Twig::Elt Test::Valgrind::Carp/;
94 my ($self, $what) = @_;
95 my $node = $self->first_child($what);
96 $self->_croak("Couldn't get first $what child node") unless $node;
103 return unless $frame->tag eq 'frame';
107 my $x = $frame->first_child($_);
108 $x ? $x->text : undef
109 } qw/ip obj fn dir file line/
113 1; # End of Test::Valgrind::Parser::XML::Twig::Elt