line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Singleton; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Singleton.pm,v 1.4 2006/02/15 20:11:46 toni Exp $ |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
686
|
use strict 'vars'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
21
|
use Test::Builder; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
9
|
1
|
|
|
1
|
|
4
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
330
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
252
|
|
12
|
|
|
|
|
|
|
$VERSION = "1.02"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import { |
17
|
1
|
|
|
1
|
|
8
|
my $self = shift; |
18
|
1
|
|
|
|
|
2
|
my $caller = caller; |
19
|
1
|
|
|
|
|
2
|
*{$caller.'::is_singleton'} = \&is_singleton; |
|
1
|
|
|
|
|
5
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
5
|
$Test->exported_to($caller); |
22
|
1
|
|
|
|
|
8
|
$Test->plan(@_); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub is_singleton { |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# get the args |
28
|
1
|
|
|
1
|
0
|
577
|
my ($class, $method1, $method2, $text) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# load the class |
31
|
1
|
|
|
|
|
5
|
require_ok( $class ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# set a default test name |
34
|
1
|
|
50
|
|
|
1629
|
$text ||= "is singleton"; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
1
|
my ( $instance1, $instance2 ); |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
6
|
like ( $instance1 = $class->$method1(), |
39
|
|
|
|
|
|
|
qr/$class/, |
40
|
|
|
|
|
|
|
"instance of object created" ); |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
229
|
like ( $instance2 = $class->$method2(), |
43
|
|
|
|
|
|
|
qr/$class/, |
44
|
|
|
|
|
|
|
"instance of object created" ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# are two instaces identical? i.e. is $class a Singleton? |
47
|
1
|
|
|
|
|
267
|
cmp_ok ( $instance1, "==", $instance2, $text); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Test::Singleton - Test for Singleton classes |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SYNOPSIS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use Test::More tests => 1; |
58
|
|
|
|
|
|
|
use Test::Singleton; |
59
|
|
|
|
|
|
|
is_singleton( "Some::Class", "new", "instance" ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DESCRIPTION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
** If you are unfamiliar with testing B first! ** |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This is asimple, basic module for checking whether a class is a |
66
|
|
|
|
|
|
|
Singleton. A Singleton describes an object class that can have only |
67
|
|
|
|
|
|
|
one instance in any system. An example of a Singleton might be a |
68
|
|
|
|
|
|
|
print spooler or system registry, or any kind of central dispatcher. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
For a description and discussion of the Singleton class, see |
71
|
|
|
|
|
|
|
"Design Patterns", Gamma et al, Addison-Wesley, 1995, ISBN 0-201-63361-2. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=over 4 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SEE ALSO |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over 4 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item L |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Implementation of a "Singleton" class. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item L |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Interprets the output of your test program. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Toni Prug |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 COPYRIGHT |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Copyright (c) 2006. Toni Prug. All rights reserved. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
100
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
101
|
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or (at |
102
|
|
|
|
|
|
|
your option) any later version. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but |
105
|
|
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
106
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
107
|
|
|
|
|
|
|
General Public License for more details. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
110
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software |
111
|
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
112
|
|
|
|
|
|
|
USA |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
See L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |