annotate Lib/IMPL/Code/BasePropertyImplementor.pm @ 277:6585464c4664

sync (unstable)
author sergey
date Fri, 01 Feb 2013 16:37:59 +0400
parents
children 4ddb27ff4a0b
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);
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
5
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
6 use constant {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
7 CodeNoGetAccessor => 'die new IMPL::Exception(\'The property is write only\',$name,$class) unless $get;',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
8 CodeNoSetAccessor => 'die new IMPL::Exception(\'The property is read only\',$name,$class) unless $set;',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
9 CodeCustomGetAccessor => 'unshift @_, $this and goto &$get;',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
10 CodeCustomSetAccessor => 'unshift @_, $this and goto &$set;',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
11 CodeValidator => '$this->$validator(@_);',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
12 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
13 };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
14
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
15 sub CodeSetAccessor {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
16 die new IMPL::Exception("Standard accessors not supported",'Set');
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
17 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
18
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
19 sub CodeGetAccessor {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
20 die new IMPL::Exception("Standard accessors not supported",'Get');
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
21 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
22
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
23 sub CodeGetListAccessor {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
24 die new IMPL::Exception("Standard accessors not supported",'GetList');
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
25 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
26
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
27 sub CodeSetListAccessor {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
28 die new IMPL::Exception("Standard accessors not supported",'SetList');
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
29 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
30
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
31 sub factoryParams { qw($class $name $set $get $validator) };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
32
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
33 our %ACCESS_CODE = (
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
34 ACCESS_PUBLIC , "",
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
35 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
36 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
37 );
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
38
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
39 sub NormalizeSpecification {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
40 my ($this,$spec) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
41
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
42 return ref $spec
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
43 ? $spec
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
44 : {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
45 get => $spec & PROP_GET,
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
46 set => $spec & PROP_SET,
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
47 isList => $spec & PROP_LIST,
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
48 ownerSet => $spec & PROP_OWNERSET
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
49 };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
50 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
51
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
52 sub CreateFactoryId {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
53 my ($self, $spec) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
54
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
55 join( '',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
56 map(
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
57 $_
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
58 ? ref $_ eq 'CODE'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
59 ? 'x'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
60 : 's'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
61 : '_',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
62 @$spec{qw(get set)}
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
63 ),
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
64 $spec->{access},
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
65 $spec->{validator} ? 'v' : '_',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
66 $spec->{isList} ? 'l' : '_',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
67 $spec->{ownerSet} ? 'o' : '_'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
68 );
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
69 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
70
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
71 sub CreateFactory {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
72 my ($self,$spec) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
73
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
74 return $self->CreateFactoryImpl(
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
75 $spec->{get}
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
76 ? ref $spec->{get} eq 'CODE'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
77 ? $self->CodeCustomGetAccessor
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
78 : $spec->{isList}
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
79 ? $spec->CodeGetListAccessor
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
80 : $spec->CodeGetAccessor
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
81 : $spec->CodeNoGetAccessor,
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
82 $spec->{set}
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
83 ? ref $spec->{set} eq 'CODE'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
84 ? $self->CodeCustomSetAccessor
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
85 : $spec->{isList}
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
86 ? $spec->CodeSetListAccessor
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
87 : $spec->CodeSetAccessor
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
88 : $spec->CodeNoSetAccessor,
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
89 $ACCESS_CODE{$spec->{access} || ACCESS_PUBLIC} || '',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
90 $spec->{validator} ? $self->CodeValidator : '',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
91 $spec->{ownerSet} ? $self->CodeOwnerCheck : ''
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
92 );
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
93 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
94
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
95 sub CreateFactoryImpl {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
96 my ($self,$codeGet,$codeSet,$codeAccessCheck,$codeValidator,$codeOwnerCheck) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
97
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
98 my $strParams = join(',',$self->factoryParams);
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
99
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
100 my $factory = <<FACTORY;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
101
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
102 sub {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
103 my ($strParams) = \@_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
104 my \$accessor;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
105 \$accessor = sub {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
106 my \$this = shift;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
107 $codeAccessCheck
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
108 if (\@_) {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
109 $codeOwnerCheck
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
110 $codeValidator
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
111 $codeSet
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
112 } else {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
113 $codeGet
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
114 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
115 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
116 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
117 FACTORY
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
118
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
119 return ( eval $factory or die new IMPL::Exception("Syntax error due compiling the factory","$@") );
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
120 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
121
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
122
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
123 1;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
124
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
125 __END__
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
126
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
127 =pod
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
128
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
129 =head1 NAME
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
130
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
131 C<IMPL::Code::BasePropertyImplementor> набор впомогательныйх статических методов
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
132 для генерации свойств.
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
133
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
134 =cut