]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Command.pm
Put each POD sentence on its own line
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Command.pm
1 package Test::Valgrind::Command;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Test::Valgrind::Command - Base class for Test::Valgrind commands.
9
10 =head1 VERSION
11
12 Version 1.13
13
14 =cut
15
16 our $VERSION = '1.13';
17
18 =head1 DESCRIPTION
19
20 This class is the base for L<Test::Valgrind> commands.
21
22 Commands gather information about the target of the analysis.
23 They should also provide a default setup for generating suppressions.
24
25 =cut
26
27 use base qw<Test::Valgrind::Carp>;
28
29 =head1 METHODS
30
31 =head2 C<< new command => $command, args => \@args >>
32
33 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.
34 The class represented by C<$command> must inherit this class.
35
36 The C<args> key is used to initialize the L</args> accessor.
37
38 =cut
39
40 sub new {
41  my $class = shift;
42  $class = ref($class) || $class;
43
44  my %args = @_;
45
46  if ($class eq __PACKAGE__ and my $cmd = delete $args{command}) {
47   $cmd =~ s/[^\w:]//g;
48   $cmd = __PACKAGE__ . "::$cmd" if $cmd !~ /::/;
49   $class->_croak("Couldn't load command $cmd: $@") unless eval "require $cmd;1";
50   return $cmd->new(%args);
51  }
52
53  my $args = delete $args{args};
54  $class->_croak('Invalid argument list') if $args and ref $args ne 'ARRAY';
55
56  bless {
57   args => $args,
58  }, $class;
59 }
60
61 =head2 C<new_trainer>
62
63 Creates a new command object suitable for generating suppressions.
64
65 Defaults to return C<undef>, which skips suppression generation.
66
67 =cut
68
69 sub new_trainer { }
70
71 =head2 C<args $session>
72
73 Returns the list of command-specific arguments that are to be passed to C<valgrind>.
74
75 Defaults to return the contents of the C<args> option.
76
77 =cut
78
79 sub args { @{$_[0]->{args} || []} }
80
81 =head2 C<env $session>
82
83 This event is called in scalar context before the command is ran, and the returned value goes out of scope when the analysis ends.
84 It's useful for e.g. setting up C<%ENV> for the child process by returning an L<Env::Sanctify> object, hence the name.
85
86 Defaults to void.
87
88 =cut
89
90 sub env { }
91
92 =head2 C<suppressions_tag $session>
93
94 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.
95
96 This method must be implemented when subclassing.
97
98 =cut
99
100 sub suppressions_tag;
101
102 =head2 C<filter $session, $report>
103
104 The C<$session> calls this method after receiving a report from the tool and before forwarding it to the action.
105 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.
106
107 Defaults to the identity function.
108
109 =cut
110
111 sub filter { $_[2] }
112
113 =head1 SEE ALSO
114
115 L<Test::Valgrind>, L<Test::Valgrind::Session>.
116
117 =head1 AUTHOR
118
119 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
120
121 You can contact me by mail or on C<irc.perl.org> (vincent).
122
123 =head1 BUGS
124
125 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>.
126 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
127
128 =head1 SUPPORT
129
130 You can find documentation for this module with the perldoc command.
131
132     perldoc Test::Valgrind::Command
133
134 =head1 COPYRIGHT & LICENSE
135
136 Copyright 2009,2010,2011 Vincent Pit, all rights reserved.
137
138 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
139
140 =cut
141
142 1; # Test::Valgrind::Command