]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Report.pm
This is 1.13
[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.13
13
14 =cut
15
16 our $VERSION = '1.13';
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 kind => $kind, id => $id, data => $data >>
31
32 Your usual constructor.
33
34 All options are mandatory :
35
36 =over 4
37
38 =item *
39
40 C<kind> is the category of the report.
41
42 =item *
43
44 C<id> is an unique identifier for the report.
45
46 =item *
47
48 C<data> is the content.
49
50 =back
51
52 =cut
53
54 sub new {
55  my $class = shift;
56  $class = ref($class) || $class;
57
58  my %args = @_;
59
60  my $kind = delete $args{kind};
61  $class->_croak("Invalid kind $kind for $class")
62                                                unless $class->valid_kind($kind);
63
64  my $id = delete $args{id};
65  $class->_croak("Invalid identifier $id") unless defined $id and not ref $id;
66
67  my $data = delete $args{data};
68
69  bless {
70   kind => $kind,
71   id   => $id,
72   data => $data,
73  }, $class;
74 }
75
76 =head2 C<< new_diag $data >>
77
78 Constructs a report with kind C<'Diag'>, an auto-incremented identifier and the given C<$data>.
79
80 =cut
81
82 my $diag_id = 0;
83
84 sub new_diag { shift->new(kind => 'Diag', id => ++$diag_id, data => $_[0]) }
85
86 =head2 C<kind>
87
88 Read-only accessor for the C<kind> option.
89
90 =cut
91
92 sub kind { $_[0]->{kind} }
93
94 =head2 C<id>
95
96 Read-only accessor for the C<id> option.
97
98 =cut
99
100 sub id { $_[0]->{id} }
101
102 =head2 C<data>
103
104 Read-only accessor for the C<data> option.
105
106 =cut
107
108 sub data { $_[0]->{data} }
109
110 =head2 C<is_diag>
111
112 Tells if a report has the C<'Diag'> kind, i.e. is a diagnostic.
113
114 =cut
115
116 sub is_diag { $_[0]->kind eq 'Diag' }
117
118 =head2 C<kinds>
119
120 Returns the list of valid kinds for this report class.
121
122 Defaults to C<'Diag'>.
123
124 =cut
125
126 sub kinds { 'Diag' }
127
128 =head2 C<valid_kind $kind>
129
130 Tells whether C<$kind> is a valid kind for this report class.
131
132 Defaults to true iff C<$kind eq 'Diag'>.
133
134 =cut
135
136 sub valid_kind { $_[1] eq 'Diag' }
137
138 =head1 SEE ALSO
139
140 L<Test::Valgrind>.
141
142 =head1 AUTHOR
143
144 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
145
146 You can contact me by mail or on C<irc.perl.org> (vincent).
147
148 =head1 BUGS
149
150 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>.
151 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
152
153 =head1 SUPPORT
154
155 You can find documentation for this module with the perldoc command.
156
157     perldoc Test::Valgrind::Report
158
159 =head1 COPYRIGHT & LICENSE
160
161 Copyright 2009,2010,2011 Vincent Pit, all rights reserved.
162
163 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
164
165 =cut
166
167 1; # End of Test::Valgrind::Report