]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Tool.pm
bb7adda0fa9e4d3013cf7b958dbb25bb0c39bd20
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Tool.pm
1 package Test::Valgrind::Tool;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Test::Valgrind::Tool - Base class for Test::Valgrind tools.
9
10 =head1 VERSION
11
12 Version 1.15
13
14 =cut
15
16 our $VERSION = '1.15';
17
18 =head1 DESCRIPTION
19
20 This class is the base for L<Test::Valgrind> tools.
21
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.
24
25 =cut
26
27 use base qw<Test::Valgrind::Component Test::Valgrind::Carp>;
28
29 =head1 METHODS
30
31 =head2 C<requires_version>
32
33     my $required_version = $tvt->requires_version;
34
35 The minimum C<valgrind> version needed to run this tool.
36 Defaults to C<3.1.0>.
37
38 =cut
39
40 sub requires_version { '3.1.0' }
41
42 =head2 C<new>
43
44     my $tvt = Test::Valgrind::Tool->new(tool => $tool);
45
46 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.
47 The class represented by C<$tool> must inherit this class.
48
49 =cut
50
51 sub new {
52  my $class = shift;
53  $class = ref($class) || $class;
54
55  my %args = @_;
56
57  if ($class eq __PACKAGE__) {
58   my $tool = delete $args{tool} || 'memcheck';
59   $tool =~ s/[^\w:]//g;
60   $tool = __PACKAGE__ . "::$tool" if $tool !~ /::/;
61   $class->_croak("Couldn't load tool $tool: $@") unless eval "require $tool; 1";
62   return $tool->new(%args);
63  }
64
65  $class->SUPER::new(@_);
66 }
67
68 =head2 C<new_trainer>
69
70     my $tvt_train = Test::Valgrind::Tool->new_trainer;
71
72 Creates a new tool object suitable for generating suppressions.
73
74 Defaults to return C<undef>, which skips suppression generation.
75
76 =cut
77
78 sub new_trainer { }
79
80 =head2 C<parser_class>
81
82     my $parser_class = $tvt->parser_class($session);
83
84 Returns the class from which the parser for this tool output will be instanciated.
85
86 This method must be implemented when subclassing.
87
88 =cut
89
90 sub parser_class;
91
92 =head2 C<report_class>
93
94     my $report_class = $tvt->report_class($session);
95
96 Returns the class in which suppression reports generated by this tool will be blessed.
97
98 This method must be implemented when subclassing.
99
100 =cut
101
102 sub report_class;
103
104 =head2 C<args>
105
106     my @args = $tvt->args($session);
107
108 Returns the list of tool-specific arguments that are to be passed to C<valgrind>.
109 All the suppression arguments are already handled by the session.
110
111 Defaults to the empty list.
112
113 =cut
114
115 sub args { }
116
117 =head2 C<suppressions_tag>
118
119     my $tag = $tvt->suppressions_tag($session);
120
121 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.
122
123 This method must be implemented when subclassing.
124
125 =cut
126
127 sub suppressions_tag;
128
129 =head2 C<start>
130
131     $tvt->start($session);
132
133 Called when the C<$session> starts.
134
135 Defaults to set L<Test::Valgrind::Component/started>.
136
137 =head2 C<filter>
138
139     my $filtered_report = $tvt->filter($session, $report);
140
141 The C<$session> calls this method after receiving a report from the parser and before letting the command filter it.
142 You can either return a mangled C<$report> (which does not need to be a clone of the original) or C<undef> if you want the action to ignore it completely.
143
144 Defaults to the identity function.
145
146 =cut
147
148 sub filter { $_[2] }
149
150 =head2 C<finish>
151
152     $tvt->finish($session);
153
154 Called when the C<$session> finishes.
155
156 Defaults to clear L<Test::Valgrind::Component/started>.
157
158 =head1 SEE ALSO
159
160 L<Test::Valgrind>, L<Test::Valgrind::Component>, L<Test::Valgrind::Session>.
161
162 =head1 AUTHOR
163
164 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
165
166 You can contact me by mail or on C<irc.perl.org> (vincent).
167
168 =head1 BUGS
169
170 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>.
171 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
172
173 =head1 SUPPORT
174
175 You can find documentation for this module with the perldoc command.
176
177     perldoc Test::Valgrind::Tool
178
179 =head1 COPYRIGHT & LICENSE
180
181 Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
182
183 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
184
185 =cut
186
187 1; # End of Test::Valgrind::Tool