Mercurial > pub > Impl
changeset 133:a07a66fd8d5c
Added IMPL::Class::MethodInfo
IMPL::Class::Property::Base optimizations
author | wizard |
---|---|
date | Fri, 18 Jun 2010 16:27:28 +0400 |
parents | 42fbb38d4a48 |
children | 44977efed303 |
files | Lib/IMPL/Class/MethodInfo.pm Lib/IMPL/Class/Property/Base.pm Lib/IMPL/Web/Application/ControllerUnit.pm |
diffstat | 3 files changed, 75 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Class/MethodInfo.pm Fri Jun 18 16:27:28 2010 +0400 @@ -0,0 +1,8 @@ +use strict; +package IMPL::Class::MethodInfo; + +use base qw(IMPL::Class::MemberInfo); + +__PACKAGE__->PassThroughArgs; + +1; \ No newline at end of file
--- a/Lib/IMPL/Class/Property/Base.pm Thu Jun 17 17:35:36 2010 +0400 +++ b/Lib/IMPL/Class/Property/Base.pm Fri Jun 18 16:27:28 2010 +0400 @@ -37,16 +37,16 @@ if (not ref $param) { if ($param & prop_list) { - $accessors{get} = ($param & prop_get) ? $self->GenerateGetList(@params) : $accessor_get_no; - $accessors{set} = ($param & prop_set) ? $self->GenerateSetList(@params) : $accessor_set_no; + $accessors{get} = ($param & prop_get) ? $self->GenerateGetList(@params) : undef; + $accessors{set} = ($param & prop_set) ? $self->GenerateSetList(@params) : undef; } else { - $accessors{get} = ($param & prop_get) ? $self->GenerateGet(@params) : $accessor_get_no; - $accessors{set} = ($param & prop_set) ? $self->GenerateSet(@params) : $accessor_set_no; + $accessors{get} = ($param & prop_get) ? $self->GenerateGet(@params) : undef; + $accessors{set} = ($param & prop_set) ? $self->GenerateSet(@params) : undef; } $accessors{owner} = (($param & owner_set) == owner_set) ? $owner_check : ""; } elsif (UNIVERSAL::isa($param,'HASH')) { - $accessors{get} = $param->{get} ? $custom_accessor_get : $accessor_get_no; - $accessors{set} = $param->{set} ? $custom_accessor_set : $accessor_set_no; + $accessors{get} = $param->{get} ? $custom_accessor_get : undef; + $accessors{set} = $param->{set} ? $custom_accessor_set : undef; $accessors{owner} = ""; } else { die new IMPL::Exception('The unsupported accessor/mutators supplied',$param); @@ -77,36 +77,35 @@ my $key = $self->MakeFactoryKey($propInfo); - my $factory = $factoryCache{$key}; + my $factoryInfo = $factoryCache{$key}; - unless ($factory) { + unless ($factoryInfo) { my $mutators = $self->GenerateAccessors($propInfo->Mutators); - $factory = $self->CreateFactory( - $access_code{ $propInfo->Access }, - $propInfo->Attributes->{validator} ? $validator_code : "", - $mutators->{owner}, - $mutators->{get}, - $mutators->{set} - ); - $factoryCache{$key} = $factory; + $factoryInfo = { + factory => $self->CreateFactory( + $access_code{ $propInfo->Access }, + $propInfo->Attributes->{validator} ? $validator_code : "", + $mutators->{owner}, + $mutators->{get} || $accessor_get_no, + $mutators->{set} || $accessor_set_no + ), + mutators => $mutators + }; + $factoryCache{$key} = $factoryInfo; } { no strict 'refs'; - *{ $propInfo->Class.'::'.$propInfo->Name } = &$factory($self->RemapFactoryParams($propInfo)); + *{ $propInfo->Class.'::'.$propInfo->Name } = $factoryInfo->{factory}->($self->RemapFactoryParams($propInfo)); } - my $mutators = $propInfo->Mutators; + my $mutators = $factoryInfo->{mutators}; - if (ref $mutators) { - $propInfo->canGet( $mutators->{get} ? 1 : 0 ); - $propInfo->canSet( $mutators->{set} ? 1 : 0 ); - $propInfo->ownerSet(0); - } else { - $propInfo->canGet( $mutators & prop_get ); - $propInfo->canSet( $mutators & prop_set ); - $propInfo->ownerSet( ($mutators & owner_set) == owner_set ); - } + $propInfo->canGet( $mutators->{get} ? 1 : 0 ); + $propInfo->canSet( $mutators->{set} ? 1 : 0 ); + $propInfo->ownerSet( $mutators->{owner} ); + + 1; } # extract from property info: class, name, get_accessor, set_accessor, validator
--- a/Lib/IMPL/Web/Application/ControllerUnit.pm Thu Jun 17 17:35:36 2010 +0400 +++ b/Lib/IMPL/Web/Application/ControllerUnit.pm Fri Jun 18 16:27:28 2010 +0400 @@ -1,5 +1,5 @@ +use strict; package IMPL::Web::Application::ControllerUnit; -use strict; use base qw(IMPL::Object); use IMPL::Class::Property; @@ -7,6 +7,7 @@ use IMPL::DOM::Schema; use Class::Inspector; use File::Spec; +use Sub::Name; use constant { CONTROLLER_METHODS => 'controller_methods', @@ -24,6 +25,8 @@ public property formErrors => prop_get | owner_set; } +my %publicProps = map {$_->Name , 1} __PACKAGE__->get_meta(typeof IMPL::Class::PropertyInfo); + __PACKAGE__->class_data(CONTROLLER_METHODS,{}); sub CTOR { @@ -59,18 +62,6 @@ } } -sub transactions { - my ($self,@names) = @_; - - $self->class_data(CONTROLLER_METHODS)->{$_} = {} foreach @names; -} - -sub transaction { - my ($self,$info) = @_; - - $info->{wrapper} = 'TransactionWrapper' unless $info->{wrapper}; -} - sub InvokeAction { my ($self,$method,$action) = @_; @@ -85,11 +76,31 @@ } } +sub MakeParams { + my ($this,$methodInfo) = @_; + + my $params; + if ($params = $methodInfo->{parameters} and ref $params eq 'ARRAY') { + return map $this->ResolveParam($_), @$params; + } + return(); +} + +sub ResolveParam { + my ($this,$param) = @_; + + if ( $param =~ /^::(\w+)$/ and $publicProps{$1}) { + return $this->$1(); + } else { + return $this->query->param($param); + } +} + sub TransactionWrapper { my ($self,$method,$action,$methodInfo) = @_; my $unit = $self->new($action); - return $unit->$method(); + return $unit->$method($unit->MakeParams($methodInfo)); } sub FormWrapper { @@ -124,7 +135,7 @@ my $unit = $self->new($action,\%result); eval { - $result{result} = $unit->$method(); + $result{result} = $unit->$method($unit->MakeParams($methodInfo)); }; if (my $err = $@) { $result{state} = STATE_INVALID; @@ -154,6 +165,21 @@ } } +sub webMethod($$;$$) { + my ($name,$args,$body,$options) = @_; + + my %info = %$options; + $info{parameters} = $args; + $info{name} = $name; + $info{module} = scalar caller; + + +} + +public webMethod discover => sub { + +}, { schema => 'some schema', returns => 'HASH' } ; + 1; __END__