1 package Test::Valgrind::Tool;
8 Test::Valgrind::Tool - Base class for Test::Valgrind tools.
16 our $VERSION = '1.02';
20 This class is the base for L<Test::Valgrind> tools.
22 They wrap around C<valgrind> tools by parsing its output and sending reports to the parent session whenever an error occurs.
23 They are expected to function both in suppressions generation and in analysis mode.
27 use base qw/Test::Valgrind::Component Test::Valgrind::Carp/;
31 =head2 C<requires_version>
33 The minimum C<valgrind> version needed to run this tool.
38 sub requires_version { '3.1.0' }
40 =head2 C<< new tool => $tool >>
42 Creates a new tool object of type C<$tool> by requiring and redispatching the method call to the module named C<$tool> if it contains C<'::'> or to C<Test::Valgrind::Tool::$tool> otherwise.
43 The class represented by C<$tool> must inherit this class.
49 $class = ref($class) || $class;
53 if ($class eq __PACKAGE__) {
54 my $tool = delete $args{tool} || 'memcheck';
56 $tool = __PACKAGE__ . "::$tool" if $tool !~ /::/;
57 $class->_croak("Couldn't load tool $tool: $@") unless eval "require $tool; 1";
58 return $tool->new(%args);
61 $class->SUPER::new(@_);
66 Creates a new tool object suitable for generating suppressions.
68 Defaults to return C<undef>, which skips suppression generation.
74 =head2 C<report_class $session>
76 Wraps around either L</report_class_suppressions> or L</report_class_analysis> depending on the running mode of the C<$session>.
81 my ($self, $sess) = @_;
83 if ($sess->do_suppressions) {
84 $self->report_class_suppressions($sess);
86 $self->report_class_analysis($sess);
90 =head2 C<report_class_suppressions $session>
92 Returns the class in which suppression reports generated by this tool will be blessed.
94 This method must be implemented when subclassing.
98 sub report_class_suppression;
100 =head2 C<report_class_analysis $session>
102 Returns the class in which error reports generated by this tool will be blessed.
104 This method must be implemented when subclassing.
108 sub report_class_analysis;
110 =head2 C<args $session>
112 Returns the list of tool-specific arguments that are to be passed to C<valgrind>.
113 All the suppression arguments are already handled by the session.
115 Defaults to the empty list.
121 =head2 C<suppressions_tag $session>
123 Returns a identifier that will be used to pick up the right suppressions for running the tool, or C<undef> to indicate that no special suppressions are needed.
125 This method must be implemented when subclassing.
129 sub suppressions_tag;
131 =head2 C<start $session>
133 Called when the C<$session> starts.
135 Defaults to set L<Test::Valgrind::Component/started>.
137 =head2 C<parse $session, $fh>
139 Wraps around either L</parse_suppressions> or L</parse_analysis> depending on the running mode of the C<$session>.
140 Croaks if the tool isn't started.
145 my ($self, $sess, $fh) = @_;
147 $self->_croak('Tool isn\'t started') unless $self->started;
149 if ($sess->do_suppressions) {
150 $self->parse_suppressions($sess, $fh);
152 $self->parse_analysis($sess, $fh);
156 =head2 C<parse_suppressions $sesssion, $fh>
158 Parse the suppression reports that the C<valgrind> process attached to the session C<$session> send through the filehandle C<$fh>.
160 This method must be implemented when subclassing.
164 sub parse_suppressions;
166 =head2 C<parse_analysis $sesssion, $fh>
168 Parse the error reports sent by the C<valgrind> process attached to the session C<$session> through the filehandle C<$fh>.
170 This method must be implemented when subclassing.
176 =head2 C<finish $session>
178 Called when the C<$session> finishes.
180 Defaults to clear L<Test::Valgrind::Component/started>.
184 L<Test::Valgrind>, L<Test::Valgrind::Component>, L<Test::Valgrind::Session>.
188 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
190 You can contact me by mail or on C<irc.perl.org> (vincent).
194 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>.
195 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
199 You can find documentation for this module with the perldoc command.
201 perldoc Test::Valgrind::Tool
203 =head1 COPYRIGHT & LICENSE
205 Copyright 2009 Vincent Pit, all rights reserved.
207 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
211 1; # End of Test::Valgrind::Tool