From: Vincent Pit Date: Mon, 24 Aug 2009 22:55:28 +0000 (+0200) Subject: Tools can only be run in one session at a time by default X-Git-Tag: v1.10~25 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=8a51ed6220d0fb2e29c669011bdf733c347b60f4;p=perl%2Fmodules%2FTest-Valgrind.git Tools can only be run in one session at a time by default So that Tool::memcheck doesn't have to check if its private ->_session accessor is set --- diff --git a/lib/Test/Valgrind/Tool.pm b/lib/Test/Valgrind/Tool.pm index 9bd530f..a1211af 100644 --- a/lib/Test/Valgrind/Tool.pm +++ b/lib/Test/Valgrind/Tool.pm @@ -58,7 +58,11 @@ sub new { return $tool->new(%args); } - bless { }, $class; + my $self = bless { }, $class; + + $self->started(undef); + + $self; } =head2 C @@ -116,7 +120,7 @@ Defaults to the empty list. =cut -sub args { } +sub args { } =head2 C @@ -128,25 +132,43 @@ This method must be implemented when subclassing. sub suppressions_tag; +=head2 C + +Specifies whether the tool is running (C<1>), stopped (C<0>) or was never started (C). + +=cut + +sub started { @_ <= 1 ? $_[0]->{started} : ($_[0]->{started} = $_[1]) } + =head2 C Called when the C<$session> starts. -Defaults to void. +Defaults to set L. =cut -sub start { } +sub start { + my ($self) = @_; + + $self->_croak('Tool already started') if $self->started; + $self->started(1); + + return; +} =head2 C Wraps around either L or L depending on the running mode of the C<$session>. +Croaks if the tool isn't started. =cut sub parse { my ($self, $sess, $fh) = @_; + $self->_croak('Tool isn\'t started') unless $self->started; + if ($sess->do_suppressions) { $self->parse_suppressions($sess, $fh); } else { @@ -178,11 +200,18 @@ sub parse_analysis; Called when the C<$session> finishes. -Defaults to void. +Defaults to clear L. =cut -sub finish { } +sub finish { + my ($self) = @_; + + return unless $self->started; + $self->started(0); + + return; +} =head1 SEE ALSO diff --git a/lib/Test/Valgrind/Tool/memcheck.pm b/lib/Test/Valgrind/Tool/memcheck.pm index c32b2ae..15b6587 100644 --- a/lib/Test/Valgrind/Tool/memcheck.pm +++ b/lib/Test/Valgrind/Tool/memcheck.pm @@ -121,9 +121,6 @@ sub _session { @_ <= 1 ? $_[0]->{_session} : ($_[0]->{_session} = $_[1]) } sub start { my ($self, $sess) = @_; - $self->_croak('This memcheck tool can\'t be run in two sessions at once') - if $self->_session; - $self->SUPER::start($sess); $self->_session($sess);