annotate Lib/IMPL/Code/DirectPropertyImplementor.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::DirectPropertyImplementor;
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::require {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
5 Exception => 'IMPL::Exception',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
6 ArgException => '-IMPL::InvalidArgumentException'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
7 };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
8
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
9 use parent qw(IMPL::Code::BasePropertyImplementor);
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
10
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
11 use constant {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
12 CodeGetAccessor => 'return ($this->{$field});',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
13 CodeSetAccessor => 'return ($this->{$field} = $_[0])',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
14 CodeGetListAccessor => 'return(
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
15 wantarray ?
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
16 @{ $this->{$field} ?
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
17 $this->{$field} :
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
18 ( $this->{$field} = IMPL::Object::List->new() )
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
19 } :
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
20 ( $this->{$field} ?
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
21 $this->{$field} :
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
22 ( $this->{$field} = IMPL::Object::List->new() )
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
23 )
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
24 );',
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
25 CodeSetListAccessor => 'return(
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
26 wantarray ?
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
27 @{ $this->{$field} = IMPL::Object::List->new(
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
28 (@_ == 1 and UNIVERSAL::isa($_[0], \'ARRAY\') ) ? $_[0] : [@_]
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
29 )} :
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
30 ($this->{$field} = IMPL::Object::List->new(
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
31 (@_ == 1 and UNIVERSAL::isa($_[0], \'ARRAY\') ) ? $_[0] : [@_]
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
32 ))
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
33 );'
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
34 };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
35
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
36 sub factoryParams { qw($class $name $set $get $validator $field) };
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
37
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
38 my %cache;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
39
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
40 sub Implement {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
41 my ($self, $spec) = @_;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
42
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
43 my $name = $spec->{name}
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
44 or ArgException->new(name => "The name of the property is required");
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
45 my $class = $spec->{class}
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
46 or ArgException->new(name => "The onwer class must be specified");
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
47
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
48 $spec = $self->NormalizeSpecification($spec);
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
49
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
50 my $id = $self->CreateFactoryId($spec);
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
51 my $factory = $cache{$id};
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
52 unless($factory) {
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
53 $factory = $self->CreateFactory($spec);
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
54 $cache{$id} = $factory;
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
55 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
56
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
57
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
58
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
59
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
60 }
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
61
6585464c4664 sync (unstable)
sergey
parents:
diff changeset
62 1;