]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Action.pm
fbdffe639da60c1a0b1fba5fab8f7fab368a0c09
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Action.pm
1 package Test::Valgrind::Action;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Test::Valgrind::Action - Base class for Test::Valgrind actions.
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> actions.
21
22 Actions are called each time a tool encounter an error and decide what to do with it (for example passing or failing tests).
23
24 =cut
25
26 use base qw<Test::Valgrind::Component Test::Valgrind::Carp>;
27
28 =head1 METHODS
29
30 =head2 C<new>
31
32     my $tva = Test::Valgrind::Action->new(action => $action);
33
34 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.
35 The class represented by C<$action> must inherit this class.
36
37 =cut
38
39 sub new {
40  my $class = shift;
41  $class = ref($class) || $class;
42
43  my %args = @_;
44
45  if ($class eq __PACKAGE__) {
46   my $action = delete $args{action} || 'Test';
47   $action =~ s/[^\w:]//g;
48   $action = __PACKAGE__ . "::$action" if $action !~ /::/;
49   $class->_croak("Couldn't load action $action: $@")
50                                                unless eval "require $action; 1";
51   return $action->new(%args);
52  }
53
54  $class->SUPER::new(@_);
55 }
56
57 =head2 C<do_suppressions>
58
59 Indicates if the action wants C<valgrind> to run in suppression-generating mode or in analysis mode.
60
61 =cut
62
63 sub do_suppressions { 0 }
64
65 =head2 C<start>
66
67     $tva->start($session);
68
69 Called when the C<$session> starts.
70
71 Defaults to set L<Test::Valgrind::Component/started>.
72
73 =head2 C<report>
74
75     $tva->report($session, $report);
76
77 Invoked each time the C<valgrind> process attached to the C<$session> spots an error.
78 C<$report> is a L<Test::Valgrind::Report> object describing the error.
79
80 Defaults to check L<Test::Valgrind::Component/started>.
81
82 =cut
83
84 sub report {
85  my ($self) = @_;
86
87  $self->_croak('Action isn\'t started') unless $self->started;
88
89  return;
90 }
91
92 =head2 C<abort>
93
94     $tva->abort($session, $msg);
95
96 Triggered when the C<$session> has to interrupt the action.
97
98 Defaults to croak.
99
100 =cut
101
102 sub abort { $_[0]->_croak($_[2]) }
103
104 =head2 C<finish>
105
106     $tva->finish($session);
107
108 Called when the C<$session> finishes.
109
110 Defaults to clear L<Test::Valgrind::Component/started>.
111
112 =head2 C<status>
113
114     $tva->status($session);
115
116 Returns the status code corresponding to the last run of the action.
117
118 =cut
119
120 sub status {
121  my ($self, $sess) = @_;
122
123  my $started = $self->started;
124
125  $self->_croak("Action was never started") unless defined $started;
126  $self->_croak("Action is still running")  if $started;
127
128  return;
129 }
130
131 =head1 SEE ALSO
132
133 L<Test::Valgrind>, L<Test::Valgrind::Component>, L<Test::Valgrind::Session>.
134
135 =head1 AUTHOR
136
137 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
138
139 You can contact me by mail or on C<irc.perl.org> (vincent).
140
141 =head1 BUGS
142
143 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>.
144 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
145
146 =head1 SUPPORT
147
148 You can find documentation for this module with the perldoc command.
149
150     perldoc Test::Valgrind::Action
151
152 =head1 COPYRIGHT & LICENSE
153
154 Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
155
156 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
157
158 =cut
159
160 1; # End of Test::Valgrind::Action