File Coverage

blib/lib/Test/Valgrind/Command.pm
Criterion Covered Total %
statement 25 27 92.5
branch 5 8 62.5
condition 4 9 44.4
subroutine 6 10 60.0
pod 6 6 100.0
total 46 60 76.6


line stmt bran cond sub pod time code
1             package Test::Valgrind::Command;
2              
3 4     4   95336 use strict;
  4         8  
  4         126  
4 4     4   24 use warnings;
  4         6  
  4         288  
5              
6             =head1 NAME
7              
8             Test::Valgrind::Command - Base class for Test::Valgrind commands.
9              
10             =head1 VERSION
11              
12             Version 1.18
13              
14             =cut
15              
16             our $VERSION = '1.18';
17              
18             =head1 DESCRIPTION
19              
20             This class is the base for L commands.
21              
22             Commands gather information about the target of the analysis.
23             They should also provide a default setup for generating suppressions.
24              
25             =cut
26              
27 4     4   2366 use Test::Valgrind::Util;
  4         14  
  4         138  
28              
29 4     4   26 use base qw;
  4         10  
  4         2800  
30              
31             =head1 METHODS
32              
33             =head2 C
34              
35             my $tvc = Test::Valgrind::Command->new(
36             command => $command,
37             args => \@args,
38             );
39              
40             Creates a new command object of type C<$command> by requiring and redispatching the method call to the module named C<$command> if it contains C<'::'> or to C otherwise.
41             The class represented by C<$command> must inherit this class.
42              
43             The C key is used to initialize the L accessor.
44              
45             =cut
46              
47             sub new {
48 8     8 1 72 my $class = shift;
49 8   33     232 $class = ref($class) || $class;
50              
51 8         38 my %args = @_;
52              
53 8         16 my $cmd = delete $args{command};
54 8 100 66     50 if ($class eq __PACKAGE__ and defined $cmd) {
55 4         26 ($cmd, my $msg) = Test::Valgrind::Util::validate_subclass($cmd);
56 4 50       18 $class->_croak($msg) unless defined $cmd;
57 4         50 return $cmd->new(%args);
58             }
59              
60 4         14 my $args = delete $args{args};
61 4 50 33     50 $class->_croak('Invalid argument list') if $args and ref $args ne 'ARRAY';
62              
63 4         24 bless {
64             args => $args,
65             }, $class;
66             }
67              
68             =head2 C
69              
70             Creates a new command object suitable for generating suppressions.
71              
72             Defaults to return C, which skips suppression generation.
73              
74             =cut
75              
76       0 1   sub new_trainer { }
77              
78             =head2 C
79              
80             my @args = $tvc->args($session);
81              
82             Returns the list of command-specific arguments that are to be passed to C.
83              
84             Defaults to return the contents of the C option.
85              
86             =cut
87              
88 2 50   2 1 5 sub args { @{$_[0]->{args} || []} }
  2         79  
89              
90             =head2 C
91              
92             my $env = $tvc->env($session);
93              
94             This event is called in scalar context before the command is ran, and the returned value goes out of scope when the analysis ends.
95             It's useful for e.g. setting up C<%ENV> for the child process by returning an L object, hence the name.
96              
97             Defaults to void.
98              
99             =cut
100              
101       0 1   sub env { }
102              
103             =head2 C
104              
105             my $tag = $tvc->suppressions_tag($session);
106              
107             Returns a identifier that will be used to pick up the right suppressions for running the command, or C to indicate that no special suppressions are needed.
108              
109             This method must be implemented when subclassing.
110              
111             =cut
112              
113             sub suppressions_tag;
114              
115             =head2 C
116              
117             my $supp_ok = $tvc->check_suppressions_file($file);
118              
119             Returns a boolean indicating whether the suppressions contained in C<$file> are compatible with the command.
120              
121             Defaults to true.
122              
123             =cut
124              
125 0     0 1   sub check_suppressions_file { 1 }
126              
127             =head2 C
128              
129             my $filtered_report = $tvc->filter($session, $report);
130              
131             The C<$session> calls this method after receiving a report from the tool and before forwarding it to the action.
132             You can either return a mangled C<$report> (which does not need to be a clone of the original) or C if you want the action to ignore it completely.
133              
134             Defaults to the identity function.
135              
136             =cut
137              
138 0     0 1   sub filter { $_[2] }
139              
140             =head1 SEE ALSO
141              
142             L, L.
143              
144             =head1 AUTHOR
145              
146             Vincent Pit, C<< >>, L.
147              
148             You can contact me by mail or on C (vincent).
149              
150             =head1 BUGS
151              
152             Please report any bugs or feature requests to C, or through the web interface at L.
153             I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
154              
155             =head1 SUPPORT
156              
157             You can find documentation for this module with the perldoc command.
158              
159             perldoc Test::Valgrind::Command
160              
161             =head1 COPYRIGHT & LICENSE
162              
163             Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
164              
165             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
166              
167             =cut
168              
169             1; # Test::Valgrind::Command