1 package Test::Valgrind::Action;
8 Test::Valgrind::Action - Base class for Test::Valgrind actions.
16 our $VERSION = '1.00';
20 This class is the base for L<Test::Valgrind> actions.
22 Actions are called each time a tool encounter an error and decide what to do with it (for example passing or failing tests).
26 use base qw/Test::Valgrind::Carp/;
30 =head2 C<< new action => $action >>
32 Creates a new action object of type C<$action> by requiring and redispatching the method call to the module named C<$action> if it contains C<'::'> or to C<Test::Valgrind::Action::$action> otherwise.
33 The class represented by C<$action> must inherit this class.
39 $class = ref($class) || $class;
43 if ($class eq __PACKAGE__) {
44 my $action = delete $args{action} || 'Test';
45 $action =~ s/[^\w:]//g;
46 $action = __PACKAGE__ . "::$action" if $action !~ /::/;
47 $class->_croak("Couldn't load action $action: $@")
48 unless eval "require $action; 1";
49 return $action->new(%args);
52 my $self = bless { }, $class;
54 $self->started(undef);
59 =head2 C<do_suppressions>
61 Indicates if the action wants C<valgrind> to run in suppression-generating mode or in analysis mode.
65 sub do_suppressions { 0 }
69 Specifies whether the action is running (C<1>), stopped (C<0>) or was never started (C<undef>).
73 sub started { @_ <= 1 ? $_[0]->{started} : ($_[0]->{started} = $_[1]) }
75 =head2 C<start $session>
77 Called when the C<$session> starts.
79 Defaults to set L</started>.
86 $self->_croak('Action already started') if $self->started;
92 =head2 C<report $session, $report>
94 Invoked each time the C<valgrind> process attached to the C<$session> spots an error.
95 C<$report> is a L<Test::Valgrind::Report> object describing the error.
97 Defaults to check L</started>.
104 $self->_croak('Action isn\'t started') unless $self->started;
109 =head2 C<abort $session, $msg>
111 Triggered when the C<$session> has to interrupt the action.
117 sub abort { $_[0]->_croak($_[2]) }
119 =head2 C<finish $session>
121 Called when the C<$session> finishes.
123 Defaults to clear L</started>.
130 return unless $self->started;
136 =head2 C<status $session>
138 Returns the status code corresponding to the last run of the action.
143 my ($self, $sess) = @_;
145 my $started = $self->started;
147 $self->_croak("Action was never started") unless defined $started;
148 $self->_croak("Action is still running") if $started;
155 L<Test::Valgrind>, L<Test::Valgrind::Session>.
159 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
161 You can contact me by mail or on C<irc.perl.org> (vincent).
165 Please report any bugs or feature requests to C<bug-test-valgrind at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
166 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
170 You can find documentation for this module with the perldoc command.
172 perldoc Test::Valgrind::Action
174 =head1 COPYRIGHT & LICENSE
176 Copyright 2009 Vincent Pit, all rights reserved.
178 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
182 1; # End of Test::Valgrind::Action