]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Component.pm
This is 1.10
[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.10
13
14 =cut
15
16 our $VERSION = '1.10';
17
18 use Scalar::Util ();
19
20 use base qw/Test::Valgrind::Carp/;
21
22 =head1 METHODS
23
24 =head2 C<new>
25
26 Basic constructor.
27
28 =cut
29
30 sub new {
31  my $self = shift;
32
33  my $class = $self;
34  if (Scalar::Util::blessed($self)) {
35   $class = ref $self;
36   if ($self->isa(__PACKAGE__)) {
37    $self->{started} = undef;
38    return $self;
39   }
40  }
41
42  bless {
43   started => undef,
44  }, $class;
45 }
46
47 =head2 C<started [ $bool ]>
48
49 Specifies whether the component is running (C<1>), stopped (C<0>) or was never started (C<undef>).
50
51 =cut
52
53 sub started { @_ <= 1 ? $_[0]->{started} : ($_[0]->{started} = $_[1] ? 1 : 0) }
54
55 =head2 C<start>
56
57 Marks the component as started, and throws an exception if it was already.
58 Returns its self object.
59
60 =cut
61
62 sub start {
63  my ($self) = @_;
64
65  $self->_croak(ref($self) . ' component already started') if $self->started;
66  $self->started(1);
67
68  $self;
69 }
70
71 =head2 C<finish>
72
73 Marks the component as stopped, and throws an exception if it wasn't started.
74 Returns its self object.
75
76 =cut
77
78 sub finish {
79  my ($self) = @_;
80
81  $self->_croak(ref($self) . ' component is not started') unless $self->started;
82  $self->started(0);
83
84  $self;
85 }
86
87 =head1 SEE ALSO
88
89 L<Test::Valgrind>.
90
91 =head1 AUTHOR
92
93 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
94
95 You can contact me by mail or on C<irc.perl.org> (vincent).
96
97 =head1 BUGS
98
99 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>.
100 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
101
102 =head1 SUPPORT
103
104 You can find documentation for this module with the perldoc command.
105
106     perldoc Test::Valgrind::Component
107
108 =head1 COPYRIGHT & LICENSE
109
110 Copyright 2009 Vincent Pit, all rights reserved.
111
112 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
113
114 =cut
115
116 1; # End of Test::Valgrind::Component