X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FTest-Valgrind.git;a=blobdiff_plain;f=lib%2FTest%2FValgrind%2FParser%2FXML%2FTwig.pm;h=d290fa555bd0c51cfb789894ba2e9c2c629ccdb8;hp=318e2dbb7ae20799027e9337e3abc6aec7ae62c4;hb=f2071d95aaaa4817e91cc33530deedc8d701d44d;hpb=c449f79f31a73c4389c3f9ea5cf99c62e68b47ac diff --git a/lib/Test/Valgrind/Parser/XML/Twig.pm b/lib/Test/Valgrind/Parser/XML/Twig.pm index 318e2db..d290fa5 100644 --- a/lib/Test/Valgrind/Parser/XML/Twig.pm +++ b/lib/Test/Valgrind/Parser/XML/Twig.pm @@ -3,11 +3,28 @@ package Test::Valgrind::Parser::XML::Twig; use strict; use warnings; -our $VERSION = '1.02'; +=head1 NAME + +Test::Valgrind::Parser::XML::Twig - Parse valgrind XML output with XML::Twig. + +=head1 VERSION + +Version 1.19 + +=cut + +our $VERSION = '1.19'; + +=head1 DESCRIPTION + +This subclass of L and L encapsulates an L parser inside the L framework. +It is able to parse the XML output from C up to protocol version 4 and to generate the appropriate reports accordingly. + +=cut use Scalar::Util (); -use base qw/Test::Valgrind::Parser::XML Test::Valgrind::Carp XML::Twig/; +use base qw; BEGIN { XML::Twig->add_options('Stash'); } @@ -16,6 +33,10 @@ my %handlers = ( '/valgrindoutput/error' => \&handle_error, ); +=head1 METHODS + +=cut + sub new { my $class = shift; $class = ref($class) || $class; @@ -33,8 +54,15 @@ sub new { sub stash { shift->{Stash} } +=head2 C + +The version of the protocol that the current stream is conforming to. +It is reset before and after the parsing phase, so it's effectively only available from inside C. + +=cut + eval "sub $_ { \@_ <= 1 ? \$_[0]->{$_} : (\$_[0]->{$_} = \$_[1]) }" - for qw/_session protocol_version/; + for qw<_session protocol_version>; # We must store the session in ourselves because it's only possible to pass # arguments to XML::Twig objects by a global stash. @@ -51,10 +79,14 @@ sub start { sub parse { my ($self, $sess, $fh) = @_; + $self->protocol_version(undef); + $self->XML::Twig::parse($fh); $self->purge; - return; + $self->protocol_version(undef); + + return 0; } sub finish { @@ -93,8 +125,8 @@ sub handle_error { $data->{stack} = [ map $_->listify_frame, $node->kid('stack')->children('frame') ]; - for (qw/leakedbytes leakedblocks/) { - my $kid = $node->first_child($_); + for (qw) { + my $kid = ($xwhat || $node)->first_child($_); next unless $kid; $data->{$_} = int $kid->text; } @@ -123,15 +155,46 @@ sub handle_error { $twig->purge; } +=head1 SEE ALSO + +L, L, L. + +L. + +=head1 AUTHOR + +Vincent Pit, C<< >>, L. + +You can contact me by mail or on C (vincent). + +=head1 BUGS + +Please report any bugs or feature requests to C, or through the web interface at L. +I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc Test::Valgrind::Parser::XML::Twig + +=head1 COPYRIGHT & LICENSE + +Copyright 2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved. + +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +=cut + # End of Test::Valgrind::Parser::XML::Twig package Test::Valgrind::Parser::XML::Twig::Elt; -our $VERSION = '1.02'; +our $VERSION = '1.19'; BEGIN { require XML::Twig; } -use base qw/XML::Twig::Elt Test::Valgrind::Carp/; +use base qw; sub kid { my ($self, $what) = @_; @@ -149,7 +212,7 @@ sub listify_frame { map { my $x = $frame->first_child($_); $x ? $x->text : undef - } qw/ip obj fn dir file line/ + } qw ]; }