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