Mercurial > pub > Impl
diff Lib/IMPL/Web/Application/ControllerUnit.pm @ 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 |
line wrap: on
line diff
--- 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__