File Coverage

blib/lib/Test/Valgrind/Report.pm
Criterion Covered Total %
statement 23 25 92.0
branch 2 4 50.0
condition 2 6 33.3
subroutine 9 11 81.8
pod 8 8 100.0
total 44 54 81.4


line stmt bran cond sub pod time code
1             package Test::Valgrind::Report;
2              
3 7     7   36 use strict;
  7         12  
  7         163  
4 7     7   24 use warnings;
  7         9  
  7         272  
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) 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.
24             The C kind is reserved for diagnostics.
25              
26             =cut
27              
28 7     7   24 use base qw;
  7         8  
  7         2204  
29              
30             =head2 C
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 is the category of the report.
47              
48             =item *
49              
50             C is an unique identifier for the report.
51              
52             =item *
53              
54             C is the content.
55              
56             =back
57              
58             =cut
59              
60             sub new {
61 10     10 1 16 my $class = shift;
62 10   33     56 $class = ref($class) || $class;
63              
64 10         60 my %args = @_;
65              
66 10         20 my $kind = delete $args{kind};
67 10 50       58 $class->_croak("Invalid kind $kind for $class")
68             unless $class->valid_kind($kind);
69              
70 10         22 my $id = delete $args{id};
71 10 50 33     90 $class->_croak("Invalid identifier $id") unless defined $id and not ref $id;
72              
73 10         20 my $data = delete $args{data};
74              
75 10         78 bless {
76             kind => $kind,
77             id => $id,
78             data => $data,
79             }, $class;
80             }
81              
82             =head2 C
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 10     10 1 58 sub new_diag { shift->new(kind => 'Diag', id => ++$diag_id, data => $_[0]) }
93              
94             =head2 C
95              
96             my $kind = $tvr->kind;
97              
98             Read-only accessor for the C option.
99              
100             =cut
101              
102 20     20 1 162 sub kind { $_[0]->{kind} }
103              
104             =head2 C
105              
106             my $id = $tvr->id;
107              
108             Read-only accessor for the C option.
109              
110             =cut
111              
112 0     0 1 0 sub id { $_[0]->{id} }
113              
114             =head2 C
115              
116             my $data = $tvr->data;
117              
118             Read-only accessor for the C option.
119              
120             =cut
121              
122 10     10 1 60 sub data { $_[0]->{data} }
123              
124             =head2 C
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 20     20 1 74 sub is_diag { $_[0]->kind eq 'Diag' }
133              
134             =head2 C
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 7     7 1 21 sub kinds { 'Diag' }
145              
146             =head2 C
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 0     0 1   sub valid_kind { $_[1] eq 'Diag' }
157              
158             =head1 SEE ALSO
159              
160             L.
161              
162             =head1 AUTHOR
163              
164             Vincent Pit, C<< >>, L.
165              
166             You can contact me by mail or on C (vincent).
167              
168             =head1 BUGS
169              
170             Please report any bugs or feature requests to C, or through the web interface at L.
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