annotate Lib/IMPL/Object/Singleton.pm @ 353:feeb3bc4a818

corrected error handling while loading templates corrected variables lookup in controls updated handles to use the new view features
author cin
date Fri, 11 Oct 2013 15:49:04 +0400
parents 75a78cbf7dcf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
1 package IMPL::Object::Singleton;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
4
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
5 require IMPL::Exception;
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
6 use parent qw(
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
7 IMPL::Class::Meta
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
8 );
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
9
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
10 __PACKAGE__->static_accessor_own(_instance => undef);
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
11
312
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 263
diff changeset
12 sub InitInstance {
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 263
diff changeset
13 my $self = shift;
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 263
diff changeset
14 die IMPL::InvalidOperationException->new("Only one instance of the singleton can be created", $self)
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 263
diff changeset
15 if $self->_instance;
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 263
diff changeset
16
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 263
diff changeset
17 $self->_instance($self->new(@_));
143
d9dd3500ead3 Singleton behavior changed
wizard
parents: 88
diff changeset
18 }
d9dd3500ead3 Singleton behavior changed
wizard
parents: 88
diff changeset
19
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
20 sub instance {
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
21 my $this = shift;
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
22 return $this->_instance || $this->_instance($this->Activate());
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
23 }
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
24
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
25 sub Activate {
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
26 die IMPL::NotImplementedException->new("Activation isn't implemented", shift);
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
27 }
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
28
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
29 sub Release {
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
30 shift->_instance(undef);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
31 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
32
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
33 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
34
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
35 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
37 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
38
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
39 =head1 SYNOPSIS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
40
88
0d2337e203c0 minor changes
wizard
parents: 49
diff changeset
41 =begin code
0d2337e203c0 minor changes
wizard
parents: 49
diff changeset
42
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
43 package Foo;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
44
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 144
diff changeset
45 use parent qw(IMPL::Object IMPL::Object::Singleton);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
46
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
47 #....
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
48
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
49 Foo->isnatnce->some_work();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
50
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
51 Foo->isnatnce->get_result();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
52
88
0d2337e203c0 minor changes
wizard
parents: 49
diff changeset
53 =end code
0d2337e203c0 minor changes
wizard
parents: 49
diff changeset
54
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
55 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
56
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
57 Реализует шаблон Singleton. Наследники данного класса могут иметь только один
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
58 экземпляр. Создать этот экземпляр можно явно, используюя конструктор, либо
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
59 автоматически при обращении к свойству C<instance>, для этого нужно
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
60 переопределить метод C<Activate()>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
61
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
62 =head1 MEMBERS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
63
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
64 =head2 C<CTOR()>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
65
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
66 Проверяет на единственность экземпляра класса, запоминает созданный экземпляр.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
67
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
68 =head2 C<[static,get]instance>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
69
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
70 Текущий экземпляр класса, если он еще не создан, то вызывает метод C<Activate>.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
71
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
72 =head2 C<[static,abstract]Activate()>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
73
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
74 Вызывается автоматически при обращении к свойству C<instance>, если экземпляр
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
75 объекта еще не был создан.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
76
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
77 =head2 C<[static]Release()>
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
78
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 194
diff changeset
79 Освобождает текущий экземпляр.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
80
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 46
diff changeset
81 =cut