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