]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Report.pm
This is 1.19
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Report.pm
1 package Test::Valgrind::Report;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Test::Valgrind::Report - Base class for Test::Valgrind error reports.
9
10 =head1 VERSION
11
12 Version 1.19
13
14 =cut
15
16 our $VERSION = '1.19';
17
18 =head1 DESCRIPTION
19
20 This class provides a generic API for messages (the so-called I<reports>) generated by the parser, filtered by the tool and the command, and handled by the action.
21 The tool has authority for deciding in which subclass of this one reports should be blessed.
22
23 Reports are classified by I<kinds>.
24 The C<Diag> kind is reserved for diagnostics.
25
26 =cut
27
28 use base qw<Test::Valgrind::Carp>;
29
30 =head2 C<new>
31
32    my $tvr = Test::Valgrind::Report->new(
33     kind => $kind,
34     id   => $id,
35     data => $data,
36    );
37
38 Your usual constructor.
39
40 All options are mandatory :
41
42 =over 4
43
44 =item *
45
46 C<kind> is the category of the report.
47
48 =item *
49
50 C<id> is an unique identifier for the report.
51
52 =item *
53
54 C<data> is the content.
55
56 =back
57
58 =cut
59
60 sub new {
61  my $class = shift;
62  $class = ref($class) || $class;
63
64  my %args = @_;
65
66  my $kind = delete $args{kind};
67  $class->_croak("Invalid kind $kind for $class")
68                                                unless $class->valid_kind($kind);
69
70  my $id = delete $args{id};
71  $class->_croak("Invalid identifier $id") unless defined $id and not ref $id;
72
73  my $data = delete $args{data};
74
75  bless {
76   kind => $kind,
77   id   => $id,
78   data => $data,
79  }, $class;
80 }
81
82 =head2 C<new_diag>
83
84     my $diag_report = Test::Valgrind::Report->new_diag($data);
85
86 Constructs a report with kind C<'Diag'>, an auto-incremented identifier and the given C<$data>.
87
88 =cut
89
90 my $diag_id = 0;
91
92 sub new_diag { shift->new(kind => 'Diag', id => ++$diag_id, data => $_[0]) }
93
94 =head2 C<kind>
95
96     my $kind = $tvr->kind;
97
98 Read-only accessor for the C<kind> option.
99
100 =cut
101
102 sub kind { $_[0]->{kind} }
103
104 =head2 C<id>
105
106     my $id = $tvr->id;
107
108 Read-only accessor for the C<id> option.
109
110 =cut
111
112 sub id { $_[0]->{id} }
113
114 =head2 C<data>
115
116     my $data = $tvr->data;
117
118 Read-only accessor for the C<data> option.
119
120 =cut
121
122 sub data { $_[0]->{data} }
123
124 =head2 C<is_diag>
125
126     $tvr->is_diag;
127
128 Tells if a report has the C<'Diag'> kind, i.e. is a diagnostic.
129
130 =cut
131
132 sub is_diag { $_[0]->kind eq 'Diag' }
133
134 =head2 C<kinds>
135
136     my @kinds = $tvr->kinds;
137
138 Returns the list of valid kinds for this report class.
139
140 Defaults to C<'Diag'>.
141
142 =cut
143
144 sub kinds { 'Diag' }
145
146 =head2 C<valid_kind>
147
148     $tvr->valid_kind($kind);
149
150 Tells whether C<$kind> is a valid kind for this report class.
151
152 Defaults to true iff C<$kind eq 'Diag'>.
153
154 =cut
155
156 sub valid_kind { $_[1] eq 'Diag' }
157
158 =head1 SEE ALSO
159
160 L<Test::Valgrind>.
161
162 =head1 AUTHOR
163
164 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
165
166 You can contact me by mail or on C<irc.perl.org> (vincent).
167
168 =head1 BUGS
169
170 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>.
171 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
172
173 =head1 SUPPORT
174
175 You can find documentation for this module with the perldoc command.
176
177     perldoc Test::Valgrind::Report
178
179 =head1 COPYRIGHT & LICENSE
180
181 Copyright 2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved.
182
183 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
184
185 =cut
186
187 1; # End of Test::Valgrind::Report