Mercurial > pub > Impl
annotate Lib/IMPL/Object/Singleton.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | d1676be8afcc |
children | 0f59b2de72af |
rev | line source |
---|---|
49 | 1 package IMPL::Object::Singleton; |
2 use strict; | |
3 use warnings; | |
4 | |
5 my %instances; | |
6 | |
143 | 7 sub CTOR { |
194 | 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]; | |
143 | 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 | |
166 | 28 use parent qw(IMPL::Object IMPL::Object::Singleton); |
49 | 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 | |
180 | 40 Реализует шаблон Singleton |
49 | 41 |
42 =head1 MEMBERS | |
43 | |
44 =head2 OPERATORS | |
45 | |
46 =list | |
47 | |
48 =item C<instance CLASS(@params)> | |
49 | |
180 | 50 Создает или возвращает экземпляр класса, если экземляр не существует, то он создается с параметрами C<@params>. |
49 | 51 |
52 =over | |
53 | |
54 =cut |