Mercurial > pub > Impl
comparison Lib/IMPL/Class/Property/Base.pm @ 275:6253872024a4
*refactoring IMPL::Class
| author | cin | 
|---|---|
| date | Thu, 31 Jan 2013 02:18:31 +0400 | 
| parents | 6d8092d8ce1b | 
| children | 8a5da17d7ef9 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 274:8d36073411b1 | 275:6253872024a4 | 
|---|---|
| 76 my $key = $self->MakeFactoryKey($propInfo); | 76 my $key = $self->MakeFactoryKey($propInfo); | 
| 77 | 77 | 
| 78 my $factoryInfo = $factoryCache{$key}; | 78 my $factoryInfo = $factoryCache{$key}; | 
| 79 | 79 | 
| 80 unless ($factoryInfo) { | 80 unless ($factoryInfo) { | 
| 81 my $mutators = $self->GenerateAccessors($propInfo->Mutators); | 81 my $mutators = $self->GenerateAccessors($propInfo->mutators); | 
| 82 $factoryInfo = { | 82 $factoryInfo = { | 
| 83 factory => $self->CreateFactory( | 83 factory => $self->CreateFactory( | 
| 84 $access_code{ $propInfo->Access }, | 84 $access_code{ $propInfo->access }, | 
| 85 $propInfo->Attributes->{validator} ? $validator_code : "", | 85 $propInfo->attributes->{validator} ? $validator_code : "", | 
| 86 $mutators->{owner}, | 86 $mutators->{owner}, | 
| 87 $mutators->{get} || $accessor_get_no, | 87 $mutators->{get} || $accessor_get_no, | 
| 88 $mutators->{set} || $accessor_set_no | 88 $mutators->{set} || $accessor_set_no | 
| 89 ), | 89 ), | 
| 90 mutators => $mutators | 90 mutators => $mutators | 
| 92 $factoryCache{$key} = $factoryInfo; | 92 $factoryCache{$key} = $factoryInfo; | 
| 93 } | 93 } | 
| 94 | 94 | 
| 95 { | 95 { | 
| 96 no strict 'refs'; | 96 no strict 'refs'; | 
| 97 *{ $propInfo->Class.'::'.$propInfo->Name } = $factoryInfo->{factory}->($self->RemapFactoryParams($propInfo)); | 97 *{ $propInfo->class.'::'.$propInfo->name } = $factoryInfo->{factory}->($self->RemapFactoryParams($propInfo)); | 
| 98 } | 98 } | 
| 99 | 99 | 
| 100 my $mutators = $factoryInfo->{mutators}; | 100 my $mutators = $factoryInfo->{mutators}; | 
| 101 | 101 | 
| 102 $propInfo->canGet( $mutators->{get} ? 1 : 0 ); | 102 $propInfo->canGet( $mutators->{get} ? 1 : 0 ); | 
| 112 | 112 | 
| 113 # extract from property info: class, name, get_accessor, set_accessor, validator | 113 # extract from property info: class, name, get_accessor, set_accessor, validator | 
| 114 sub RemapFactoryParams { | 114 sub RemapFactoryParams { | 
| 115 my ($self,$propInfo) = @_; | 115 my ($self,$propInfo) = @_; | 
| 116 | 116 | 
| 117 my $mutators = $propInfo->Mutators; | 117 my $mutators = $propInfo->mutators; | 
| 118 my $class = $propInfo->Class; | 118 my $class = $propInfo->class; | 
| 119 my $validator = $propInfo->Attributes->{validator}; | 119 my $validator = $propInfo->attributes->{validator}; | 
| 120 | 120 | 
| 121 die new IMPL::Exception('Can\'t find the specified validator',$class,$validator) if $validator and ref $validator ne 'CODE' and not $class->can($validator); | 121 die new IMPL::Exception('Can\'t find the specified validator',$class,$validator) if $validator and ref $validator ne 'CODE' and not $class->can($validator); | 
| 122 | 122 | 
| 123 return ( | 123 return ( | 
| 124 $propInfo->get(qw(Class Name)), | 124 $propInfo->get(qw(class name)), | 
| 125 (ref $mutators? | 125 (ref $mutators? | 
| 126 ($mutators->{set},$mutators->{get}) | 126 ($mutators->{set},$mutators->{get}) | 
| 127 : | 127 : | 
| 128 (undef,undef) | 128 (undef,undef) | 
| 129 ), | 129 ), | 
| 132 } | 132 } | 
| 133 | 133 | 
| 134 sub MakeFactoryKey { | 134 sub MakeFactoryKey { | 
| 135 my ($self,$propInfo) = @_; | 135 my ($self,$propInfo) = @_; | 
| 136 | 136 | 
| 137 my ($access,$mutators,$validator) = ($propInfo->get(qw(Access Mutators)),$propInfo->Attributes->{validator}); | 137 my ($access,$mutators,$validator) = ($propInfo->get(qw(access mutators)),$propInfo->attributes->{validator}); | 
| 138 | 138 | 
| 139 my $implementor = ref $self || $self; | 139 my $implementor = ref $self || $self; | 
| 140 | 140 | 
| 141 return join ('', | 141 return join ('', | 
| 142 $implementor, | 142 $implementor, | 
