]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Component.pm
This is 1.17
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Component.pm
1 package Test::Valgrind::Component;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Test::Valgrind::Component - Base class for Test::Valgrind components.
9
10 =head1 VERSION
11
12 Version 1.17
13
14 =cut
15
16 our $VERSION = '1.17';
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 use Scalar::Util ();
25
26 use base qw<Test::Valgrind::Carp>;
27
28 =head1 METHODS
29
30 =head2 C<new>
31
32     my $tvc = Test::Valgrind::Component->new;
33
34 Basic constructor.
35
36 =cut
37
38 sub new {
39  my $self = shift;
40
41  my $class = $self;
42  if (Scalar::Util::blessed($self)) {
43   $class = ref $self;
44   if ($self->isa(__PACKAGE__)) {
45    $self->{started} = undef;
46    return $self;
47   }
48  }
49
50  bless {
51   started => undef,
52  }, $class;
53 }
54
55 =head2 C<started>
56
57     $tvc->started($bool);
58
59 Specifies whether the component is running (C<1>), stopped (C<0>) or was never started (C<undef>).
60
61 =cut
62
63 sub started { @_ <= 1 ? $_[0]->{started} : ($_[0]->{started} = $_[1] ? 1 : 0) }
64
65 =head2 C<start>
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  my ($self) = @_;
76
77  $self->_croak(ref($self) . ' component already started') if $self->started;
78  $self->started(1);
79
80  $self;
81 }
82
83 =head2 C<finish>
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  my ($self) = @_;
94
95  $self->_croak(ref($self) . ' component is not started') unless $self->started;
96  $self->started(0);
97
98  $self;
99 }
100
101 =head1 SEE ALSO
102
103 L<Test::Valgrind>.
104
105 =head1 AUTHOR
106
107 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
108
109 You can contact me by mail or on C<irc.perl.org> (vincent).
110
111 =head1 BUGS
112
113 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>.
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 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