1 package Test::Valgrind::Action::Suppressions;
8 Test::Valgrind::Action::Suppressions - Generate suppressions for a given tool.
16 our $VERSION = '1.01';
20 This action just writes the contents of the suppressions reports received into the suppression file.
24 use base qw/Test::Valgrind::Action Test::Valgrind::Action::Captor/;
28 This class inherits L<Test::Valgrind::Action>.
30 =head2 C<< new name => $name, target => $target, ... >>
32 Your usual constructor.
34 You need to specify the suppression prefix as the value of C<name>, and the target file as C<target>.
36 Other arguments are passed straight to C<< Test::Valgrind::Action->new >>.
42 $class = ref($class) || $class;
48 for (qw/name target/) {
49 my $arg = delete $args{$_};
50 $class->_croak("'$_' is expected to be a plain scalar")
51 unless $arg and not ref $arg;
52 $validated{$_} = $arg;
55 my $self = $class->SUPER::new(%args);
57 $self->{$_} = $validated{$_} for qw/name target/;
62 sub do_suppressions { 1 }
66 Read-only accessor for the C<name> option.
70 sub name { $_[0]->{name} }
74 Read-only accessor for the C<target> option.
78 sub target { $_[0]->{target} }
81 my ($self, $sess) = @_;
83 $self->SUPER::start($sess);
85 $self->{status} = undef;
87 delete $self->{diagnostics};
90 close $self->{fh} or $self->_croak("close(\$self->{fh}): $!");
93 my $target = $self->target;
96 my ($vol, $dir, $file) = File::Spec->splitpath($target);
97 my $base = File::Spec->catpath($vol, $dir, '');
100 File::Path::mkpath([ $base ]);
102 1 while unlink $target;
105 open $self->{fh}, '>', $target
106 or $self->_croak("open(\$self->{fh}, '>', \$self->target): $!");
108 $self->save_fh(\*STDOUT => '>' => undef);
109 $self->save_fh(\*STDERR => '>' => undef);
117 $self->restore_all_fh;
119 print $self->{diagnostics} if defined $self->{diagnostics};
120 delete $self->{diagnostics};
122 $self->{status} = 255;
124 $self->SUPER::abort(@_);
128 my ($self, $sess, $report) = @_;
130 if ($report->is_diag) {
131 my $data = $report->data;
133 $self->{diagnostics} .= "$data\n";
137 $self->SUPER::report($sess, $report);
141 print { $self->{fh} } "{\n"
142 . $self->name . $report->id . "\n"
150 my ($self, $sess) = @_;
152 $self->SUPER::finish($sess);
154 $self->restore_all_fh;
156 close $self->{fh} or $self->_croak("close(\$self->{fh}): $!");
158 print $self->{diagnostics} if defined $self->{diagnostics};
159 delete $self->{diagnostics};
160 print "Found $self->{total} distinct suppressions\n";
167 sub status { $_[0]->{status} }
171 L<Test::Valgrind>, L<Test::Valgrind::Action>.
175 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
177 You can contact me by mail or on C<irc.perl.org> (vincent).
181 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>.
182 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
186 You can find documentation for this module with the perldoc command.
188 perldoc Test::Valgrind::Action::Suppressions
190 =head1 COPYRIGHT & LICENSE
192 Copyright 2009 Vincent Pit, all rights reserved.
194 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
198 1; # End of Test::Valgrind::Action::Supressions