annotate Lib/IMPL/Code/BasePropertyImplementor.pm @ 383:2f16f13b000c

DOM localization
author cin
date Thu, 23 Jan 2014 17:26:34 +0400
parents ced5937ff21a
children 0d63f5273307
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
1 package IMPL::Code::BasePropertyImplementor;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
2 use strict;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
3
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
4 use IMPL::Const qw(:prop :access);
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
5 use Scalar::Util qw(looks_like_number);
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
6
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
7 use constant {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
8 CodeNoGetAccessor => 'die new IMPL::Exception(\'The property is write only\',$name,$class) unless $get;',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
9 CodeNoSetAccessor => 'die new IMPL::Exception(\'The property is read only\',$name,$class) unless $set;',
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
10 CodeCustomGetAccessor => '$this->$get(@_);',
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
11 CodeCustomSetAccessor => '$this->$set(@_);',
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
12 CodeValidator => '$this->$validator(@_);',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
13 CodeOwnerCheck => "die new IMPL::Exception('Set accessor is restricted to the owner',\$name,\$class,scalar caller) unless caller eq \$class;"
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
14 };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
15
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
16 sub CodeSetAccessor {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
17 die new IMPL::Exception("Standard accessors not supported",'Set');
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
18 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
19
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
20 sub CodeGetAccessor {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
21 die new IMPL::Exception("Standard accessors not supported",'Get');
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
22 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
23
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
24 sub CodeGetListAccessor {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
25 die new IMPL::Exception("Standard accessors not supported",'GetList');
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
26 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
27
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
28 sub CodeSetListAccessor {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
29 die new IMPL::Exception("Standard accessors not supported",'SetList');
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
30 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
31
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
32 sub factoryParams { qw($class $name $set $get $validator) };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
33
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
34 our %ACCESS_CODE = (
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
35 ACCESS_PUBLIC , "",
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
36 ACCESS_PROTECTED, "die new IMPL::Exception('Can\\'t access the protected member',\$name,\$class,scalar caller) unless UNIVERSAL::isa(scalar caller,\$class);",
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
37 ACCESS_PRIVATE, "die new IMPL::Exception('Can\\'t access the private member',\$name,\$class,scalar caller) unless caller eq \$class;"
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
38 );
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
39
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
40 sub NormalizeSpecification {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
41 my ($this,$spec) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
42
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
43 return ref $spec
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
44 ? $spec
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
45 : {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
46 get => $spec & PROP_GET,
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
47 set => $spec & PROP_SET,
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
48 isList => $spec & PROP_LIST,
278
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
49 ownerSet => (($spec & PROP_OWNERSET) == PROP_OWNERSET),
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
50 direct => $spec & PROP_DIRECT
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
51 };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
52 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
53
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
54 sub CreateFactoryId {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
55 my ($self, $spec) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
56
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
57 join( '',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
58 map(
278
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
59 ($_
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
60 ? ( _isCustom($_)
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
61 ? 'x'
278
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
62 : 's')
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
63 : '_'),
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
64 @$spec{qw(get set)}
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
65 ),
278
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
66 $spec->{access} || ACCESS_PUBLIC,
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
67 $spec->{validator} ? 'v' : '_',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
68 $spec->{isList} ? 'l' : '_',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
69 $spec->{ownerSet} ? 'o' : '_'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
70 );
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
71 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
72
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
73 sub _isCustom {
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
74 ref($_[0]) eq 'CODE' || not(ref($_[0]) || looks_like_number($_[0]));
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
75 }
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
76
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
77 sub CreateFactory {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
78 my ($self,$spec) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
79
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
80 return $self->CreateFactoryImpl(
278
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
81 ($spec->{get}
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
82 ? ( _isCustom($spec->{get})
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
83 ? $self->CodeCustomGetAccessor
278
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
84 : ($spec->{isList}
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
85 ? $self->CodeGetListAccessor
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
86 : $self->CodeGetAccessor
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
87 )
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
88 )
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
89 : $self->CodeNoGetAccessor
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
90 ),
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
91 ($spec->{set}
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
92 ? ( _isCustom($spec->{set})
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
93 ? $self->CodeCustomSetAccessor
278
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
94 : ($spec->{isList}
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
95 ? $self->CodeSetListAccessor
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
96 : $self->CodeSetAccessor
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
97 )
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
98 )
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
99 : $self->CodeNoSetAccessor
4ddb27ff4a0b core refactoring
cin
parents: 277
diff changeset
100 ),
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
101 $ACCESS_CODE{$spec->{access} || ACCESS_PUBLIC} || '',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
102 $spec->{validator} ? $self->CodeValidator : '',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
103 $spec->{ownerSet} ? $self->CodeOwnerCheck : ''
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
104 );
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
105 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
106
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
107 sub CreateFactoryImpl {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
108 my ($self,$codeGet,$codeSet,$codeAccessCheck,$codeValidator,$codeOwnerCheck) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
109
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
110 my $strParams = join(',',$self->factoryParams);
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
111
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
112 my $factory = <<FACTORY;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
113
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
114 sub {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
115 my ($strParams) = \@_;
381
ced5937ff21a Custom getters/setters support method names in theirs definitions
cin
parents: 278
diff changeset
116 return sub {
277
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
117 my \$this = shift;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
118 $codeAccessCheck
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
119 if (\@_) {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
120 $codeOwnerCheck
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
121 $codeValidator
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
122 $codeSet
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
123 } else {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
124 $codeGet
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
125 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
126 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
127 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
128 FACTORY
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
129
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
130 return ( eval $factory or die new IMPL::Exception("Syntax error due compiling the factory","$@") );
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
131 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
132
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
133
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
134 1;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
135
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
136 __END__
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
137
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
138 =pod
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
139
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
140 =head1 NAME
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
141
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
142 C<IMPL::Code::BasePropertyImplementor> набор впомогательныйх статических методов
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
143 для генерации свойств.
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
144
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
145 =cut