Mercurial > pub > Impl
annotate Lib/IMPL/Object/Singleton.pm @ 158:a9f4ba4783eb
Minor changes
author | wizard |
---|---|
date | Tue, 02 Nov 2010 20:17:22 +0300 |
parents | b56ebc31bf18 |
children | 4267a2ac3d46 |
rev | line source |
---|---|
49 | 1 package IMPL::Object::Singleton; |
2 use strict; | |
3 use warnings; | |
4 | |
5 my %instances; | |
6 | |
143 | 7 sub CTOR { |
8 die new IMPL::InvalidOperationException("Only one instance of the singleton can be created",ref $_[0], $instances{ref $_[0]}) if $instances{ref $_[0]}; | |
9 $instances{ref $_[0]} = $_[0]; | |
10 } | |
11 | |
49 | 12 sub instance { |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
143
diff
changeset
|
13 $instances{$_[0]} |
49 | 14 } |
15 | |
16 1; | |
17 | |
18 __END__ | |
19 | |
20 =pod | |
21 | |
22 =head1 SYNOPSIS | |
23 | |
88 | 24 =begin code |
25 | |
49 | 26 package Foo; |
27 | |
28 use base qw(IMPL::Object IMPL::Object::Singleton); | |
29 | |
30 #.... | |
31 | |
32 Foo->isnatnce->some_work(); | |
33 | |
34 Foo->isnatnce->get_result(); | |
35 | |
88 | 36 =end code |
37 | |
49 | 38 =head1 DESCRIPTION |
39 | |
40 Реализует шаблон Singleton | |
41 | |
42 =head1 MEMBERS | |
43 | |
44 =head2 OPERATORS | |
45 | |
46 =list | |
47 | |
48 =item C<instance CLASS(@params)> | |
49 | |
50 Создает или возвращает экземпляр класса, если экземляр не существует, то он создается с параметрами C<@params>. | |
51 | |
52 =over | |
53 | |
54 =cut |