1 package Test::Valgrind::Command;
8 Test::Valgrind::Command - Base class for Test::Valgrind commands.
16 our $VERSION = '1.17';
20 This class is the base for L<Test::Valgrind> commands.
22 Commands gather information about the target of the analysis.
23 They should also provide a default setup for generating suppressions.
27 use Test::Valgrind::Util;
29 use base qw<Test::Valgrind::Carp>;
35 my $tvc = Test::Valgrind::Command->new(
40 Creates a new command object of type C<$command> by requiring and redispatching the method call to the module named C<$command> if it contains C<'::'> or to C<Test::Valgrind::Command::$command> otherwise.
41 The class represented by C<$command> must inherit this class.
43 The C<args> key is used to initialize the L</args> accessor.
49 $class = ref($class) || $class;
53 my $cmd = delete $args{command};
54 if ($class eq __PACKAGE__ and defined $cmd) {
55 ($cmd, my $msg) = Test::Valgrind::Util::validate_subclass($cmd);
56 $class->_croak($msg) unless defined $cmd;
57 return $cmd->new(%args);
60 my $args = delete $args{args};
61 $class->_croak('Invalid argument list') if $args and ref $args ne 'ARRAY';
70 Creates a new command object suitable for generating suppressions.
72 Defaults to return C<undef>, which skips suppression generation.
80 my @args = $tvc->args($session);
82 Returns the list of command-specific arguments that are to be passed to C<valgrind>.
84 Defaults to return the contents of the C<args> option.
88 sub args { @{$_[0]->{args} || []} }
92 my $env = $tvc->env($session);
94 This event is called in scalar context before the command is ran, and the returned value goes out of scope when the analysis ends.
95 It's useful for e.g. setting up C<%ENV> for the child process by returning an L<Env::Sanctify> object, hence the name.
103 =head2 C<suppressions_tag>
105 my $tag = $tvc->suppressions_tag($session);
107 Returns a identifier that will be used to pick up the right suppressions for running the command, or C<undef> to indicate that no special suppressions are needed.
109 This method must be implemented when subclassing.
113 sub suppressions_tag;
115 =head2 C<check_suppressions_file>
117 my $supp_ok = $tvc->check_suppressions_file($file);
119 Returns a boolean indicating whether the suppressions contained in C<$file> are compatible with the command.
125 sub check_suppressions_file { 1 }
129 my $filtered_report = $tvc->filter($session, $report);
131 The C<$session> calls this method after receiving a report from the tool and before forwarding it to the action.
132 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.
134 Defaults to the identity function.
142 L<Test::Valgrind>, L<Test::Valgrind::Session>.
146 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
148 You can contact me by mail or on C<irc.perl.org> (vincent).
152 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>.
153 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
157 You can find documentation for this module with the perldoc command.
159 perldoc Test::Valgrind::Command
161 =head1 COPYRIGHT & LICENSE
163 Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
165 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
169 1; # Test::Valgrind::Command