From: Vincent Pit Date: Sat, 19 Sep 2009 22:21:33 +0000 (+0200) Subject: Add support for ->parser_class() in tools X-Git-Tag: v1.10~14 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=270aacc7f116b97928f9d70ce7936dd9d0a78ce0;p=perl%2Fmodules%2FTest-Valgrind.git Add support for ->parser_class() in tools --- diff --git a/lib/Test/Valgrind/Session.pm b/lib/Test/Valgrind/Session.pm index c7485f1..fe521a0 100644 --- a/lib/Test/Valgrind/Session.pm +++ b/lib/Test/Valgrind/Session.pm @@ -388,7 +388,7 @@ sub start { delete @{$self}{qw/last_status exit_code/}; $self->tool->start($self); - $self->parser($self->tool->parser_class->new)->start($self); + $self->parser($self->tool->parser_class($self)->new)->start($self); $self->action->start($self); return; diff --git a/lib/Test/Valgrind/Tool.pm b/lib/Test/Valgrind/Tool.pm index 147ee11..077fc09 100644 --- a/lib/Test/Valgrind/Tool.pm +++ b/lib/Test/Valgrind/Tool.pm @@ -71,6 +71,16 @@ Defaults to return C, which skips suppression generation. sub new_trainer { } +=head2 C + +Returns the class from which the parser for this tool output will be instanciated. + +This method must be implemented when subclassing. + +=cut + +sub parser_class; + =head2 C Returns the class in which suppression reports generated by this tool will be blessed. diff --git a/lib/Test/Valgrind/Tool/memcheck.pm b/lib/Test/Valgrind/Tool/memcheck.pm index 1302efe..7869f56 100644 --- a/lib/Test/Valgrind/Tool/memcheck.pm +++ b/lib/Test/Valgrind/Tool/memcheck.pm @@ -73,6 +73,25 @@ sub callers { $_[0]->{callers} } sub suppressions_tag { 'memcheck-' . $_[1]->version } +=head2 C + +This tool uses a C parser in analysis mode, and a C parser in suppressions mode. + +=cut + +sub parser_class { + my ($self, $session) = @_; + + my $class = $session->do_suppressions + ? 'Test::Valgrind::Parser::Suppressions::Text' + : 'Test::Valgrind::Parser::XML::Twig'; + + local $@; + eval "require $class"; + + return $class; +} + =head2 C This tool emits C object reports in analysis mode.