File Coverage

blib/lib/Test/Valgrind/Component.pm
Criterion Covered Total %
statement 25 29 86.2
branch 7 12 58.3
condition n/a
subroutine 8 8 100.0
pod 4 4 100.0
total 44 53 83.0


line stmt bran cond sub pod time code
1             package Test::Valgrind::Component;
2              
3 7     7   30 use strict;
  7         3  
  7         153  
4 7     7   22 use warnings;
  7         7  
  7         222  
5              
6             =head1 NAME
7              
8             Test::Valgrind::Component - Base class for Test::Valgrind components.
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 is the base for all others that act as components that can be started and stopped.
21              
22             =cut
23              
24 7     7   23 use Scalar::Util ();
  7         7  
  7         92  
25              
26 7     7   16 use base qw;
  7         7  
  7         2113  
27              
28             =head1 METHODS
29              
30             =head2 C
31              
32             my $tvc = Test::Valgrind::Component->new;
33              
34             Basic constructor.
35              
36             =cut
37              
38             sub new {
39 15     15 1 114 my $self = shift;
40              
41 15         20 my $class = $self;
42 15 50       72 if (Scalar::Util::blessed($self)) {
43 0         0 $class = ref $self;
44 0 0       0 if ($self->isa(__PACKAGE__)) {
45 0         0 $self->{started} = undef;
46 0         0 return $self;
47             }
48             }
49              
50             bless {
51 15         177 started => undef,
52             }, $class;
53             }
54              
55             =head2 C
56              
57             $tvc->started($bool);
58              
59             Specifies whether the component is running (C<1>), stopped (C<0>) or was never started (C).
60              
61             =cut
62              
63 38 100   38 1 187 sub started { @_ <= 1 ? $_[0]->{started} : ($_[0]->{started} = $_[1] ? 1 : 0) }
    100          
64              
65             =head2 C
66              
67             $tvc->start;
68              
69             Marks the component as started, and throws an exception if it was already.
70             Returns its self object.
71              
72             =cut
73              
74             sub start {
75 12     12 1 6232 my ($self) = @_;
76              
77 12 50       224 $self->_croak(ref($self) . ' component already started') if $self->started;
78 12         44 $self->started(1);
79              
80 12         26 $self;
81             }
82              
83             =head2 C
84              
85             $tvc->finish;
86              
87             Marks the component as stopped, and throws an exception if it wasn't started.
88             Returns its self object.
89              
90             =cut
91              
92             sub finish {
93 6     6 1 11 my ($self) = @_;
94              
95 6 50       22 $self->_croak(ref($self) . ' component is not started') unless $self->started;
96 6         16 $self->started(0);
97              
98 6         12 $self;
99             }
100              
101             =head1 SEE ALSO
102              
103             L.
104              
105             =head1 AUTHOR
106              
107             Vincent Pit, C<< >>, L.
108              
109             You can contact me by mail or on C (vincent).
110              
111             =head1 BUGS
112              
113             Please report any bugs or feature requests to C, or through the web interface at L.
114             I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
115              
116             =head1 SUPPORT
117              
118             You can find documentation for this module with the perldoc command.
119              
120             perldoc Test::Valgrind::Component
121              
122             =head1 COPYRIGHT & LICENSE
123              
124             Copyright 2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved.
125              
126             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
127              
128             =cut
129              
130             1; # End of Test::Valgrind::Component