Mercurial > pub > Impl
diff Lib/IMPL/Code/DirectPropertyImplementor.pm @ 277:6585464c4664
sync (unstable)
author | sergey |
---|---|
date | Fri, 01 Feb 2013 16:37:59 +0400 |
parents | |
children | 4ddb27ff4a0b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Code/DirectPropertyImplementor.pm Fri Feb 01 16:37:59 2013 +0400 @@ -0,0 +1,62 @@ +package IMPL::Code::DirectPropertyImplementor; +use strict; + +use IMPL::require { + Exception => 'IMPL::Exception', + ArgException => '-IMPL::InvalidArgumentException' +}; + +use parent qw(IMPL::Code::BasePropertyImplementor); + +use constant { + CodeGetAccessor => 'return ($this->{$field});', + CodeSetAccessor => 'return ($this->{$field} = $_[0])', + CodeGetListAccessor => 'return( + wantarray ? + @{ $this->{$field} ? + $this->{$field} : + ( $this->{$field} = IMPL::Object::List->new() ) + } : + ( $this->{$field} ? + $this->{$field} : + ( $this->{$field} = IMPL::Object::List->new() ) + ) + );', + CodeSetListAccessor => 'return( + wantarray ? + @{ $this->{$field} = IMPL::Object::List->new( + (@_ == 1 and UNIVERSAL::isa($_[0], \'ARRAY\') ) ? $_[0] : [@_] + )} : + ($this->{$field} = IMPL::Object::List->new( + (@_ == 1 and UNIVERSAL::isa($_[0], \'ARRAY\') ) ? $_[0] : [@_] + )) + );' +}; + +sub factoryParams { qw($class $name $set $get $validator $field) }; + +my %cache; + +sub Implement { + my ($self, $spec) = @_; + + my $name = $spec->{name} + or ArgException->new(name => "The name of the property is required"); + my $class = $spec->{class} + or ArgException->new(name => "The onwer class must be specified"); + + $spec = $self->NormalizeSpecification($spec); + + my $id = $self->CreateFactoryId($spec); + my $factory = $cache{$id}; + unless($factory) { + $factory = $self->CreateFactory($spec); + $cache{$id} = $factory; + } + + + + +} + +1; \ No newline at end of file