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