Mercurial > pub > Impl
diff Lib/IMPL/Web/Application/Action.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | d1676be8afcc |
children | c8fe3f84feba |
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application/Action.pm Tue Apr 10 08:13:22 2012 +0400 +++ b/Lib/IMPL/Web/Application/Action.pm Tue Apr 10 20:08:29 2012 +0400 @@ -8,108 +8,108 @@ use IMPL::Class::Property; BEGIN { - public property application => prop_get | owner_set; - public property query => prop_get | owner_set; - public property response => prop_get | owner_set; - public property responseFactory => prop_get | owner_set; - public property context => prop_get | owner_set; - private property _entryPoint => prop_all; + public property application => prop_get | owner_set; + public property query => prop_get | owner_set; + public property response => prop_get | owner_set; + public property responseFactory => prop_get | owner_set; + public property context => prop_get | owner_set; + private property _entryPoint => prop_all; } sub CTOR { - my ($this) = @_; - - $this->responseFactory('IMPL::Web::Application::Response') unless $this->responseFactory; - $this->response( $this->responseFactory->new(query => $this->query) ); - $this->context({}); + my ($this) = @_; + + $this->responseFactory('IMPL::Web::Application::Response') unless $this->responseFactory; + $this->response( $this->responseFactory->new(query => $this->query) ); + $this->context({}); } sub Invoke { - my ($this) = @_; - - if ($this->_entryPoint) { - $this->_entryPoint->(); - } else { - die new IMPL::InvalidOperationException("At least one handler is required"); - } + my ($this) = @_; + + if ($this->_entryPoint) { + $this->_entryPoint->(); + } else { + die new IMPL::InvalidOperationException("At least one handler is required"); + } } sub ReinitResponse { - my ($this) = @_; - - die new IMPL::InvalidOperationException("Response already sent") if $this->response->isHeaderPrinted; - - $this->response->Discard; - $this->response($this->responseFactory->new(query => $this->query)); + my ($this) = @_; + + die new IMPL::InvalidOperationException("Response already sent") if $this->response->isHeaderPrinted; + + $this->response->Discard; + $this->response($this->responseFactory->new(query => $this->query)); } sub ChainHandler { - my ($this,$handler) = @_; - - my $delegateNext = $this->_entryPoint(); - - if (ref $handler eq 'CODE') { - $this->_entryPoint( sub { - $handler->($this,$delegateNext); - } ); - } elsif (ref $handler and UNIVERSAL::isa($handler,'IMPL::Web::QueryHandler')) { - $this->_entryPoint( sub { - $handler->Invoke($this,$delegateNext); - } ); - } elsif ($handler and not ref $handler) { - - if (my $method = $this->can($handler) ) { - $this->_entryPoint( sub { - $method->($this,$delegateNext); - } ); - } else { - { - no strict 'refs'; - eval "require $handler; 1;" or die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler,"Failed to load module") unless keys %{"${handler}::"}; - } - - if (UNIVERSAL::isa($handler,'IMPL::Web::QueryHandler')) { - $this->_entryPoint( sub { - $handler->Invoke($this,$delegateNext); - } ); - } else { - die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler); - } - } - } else { - die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler); - } - + my ($this,$handler) = @_; + + my $delegateNext = $this->_entryPoint(); + + if (ref $handler eq 'CODE') { + $this->_entryPoint( sub { + $handler->($this,$delegateNext); + } ); + } elsif (ref $handler and UNIVERSAL::isa($handler,'IMPL::Web::QueryHandler')) { + $this->_entryPoint( sub { + $handler->Invoke($this,$delegateNext); + } ); + } elsif ($handler and not ref $handler) { + + if (my $method = $this->can($handler) ) { + $this->_entryPoint( sub { + $method->($this,$delegateNext); + } ); + } else { + { + no strict 'refs'; + eval "require $handler; 1;" or die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler,"Failed to load module") unless keys %{"${handler}::"}; + } + + if (UNIVERSAL::isa($handler,'IMPL::Web::QueryHandler')) { + $this->_entryPoint( sub { + $handler->Invoke($this,$delegateNext); + } ); + } else { + die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler); + } + } + } else { + die new IMPL::InvalidArgumentException("An invalid handler supplied",$handler); + } + } sub cookie { - my ($this,$name,$rx) = @_; - - $this->_launder(scalar( $this->query->cookie($name) ), $rx ); + my ($this,$name,$rx) = @_; + + $this->_launder(scalar( $this->query->cookie($name) ), $rx ); } sub param { - my ($this,$name,$rx) = @_; - - $this->_launder(scalar( $this->query->param($name) ), $rx ); + my ($this,$name,$rx) = @_; + + $this->_launder(scalar( $this->query->param($name) ), $rx ); } sub _launder { - my ($this,$value,$rx) = @_; - - if ( $value ) { - if ($rx) { - if ( my @result = ($value =~ m/$rx/) ) { - return @result > 1 ? \@result : $result[0]; - } else { - return undef; - } - } else { - return $value; - } - } else { - return undef; - } + my ($this,$value,$rx) = @_; + + if ( $value ) { + if ($rx) { + if ( my @result = ($value =~ m/$rx/) ) { + return @result > 1 ? \@result : $result[0]; + } else { + return undef; + } + } else { + return $value; + } + } else { + return undef; + } } 1; @@ -147,62 +147,62 @@ # the application creates a new Action object my $action = $application->actionFactory->new( - action => $application, # the application passes self - query => $query # current CGI query + action => $application, # the application passes self + query => $query # current CGI query ); # forms query handlers stack $action->ChainHandler($_) foreach qw ( - IMPL::Web::QueryHandler::SecCallToMethod - IMPL::Web::QueryHandler::AuthenticateCookie - IMPL::Web::QueryHandler::PageFormat + IMPL::Web::QueryHandler::SecCallToMethod + IMPL::Web::QueryHandler::AuthenticateCookie + IMPL::Web::QueryHandler::PageFormat ); # and finally invokes the action $action->Invoke() { - - # some internals - - IMPL::Web::QueryHandler::PageFormat->Invoke($action,$nextHandlerIsAuthHandler) { - - #some internals - - my $result = $nextHandlerIsAuthHandler() { - - # some internals + + # some internals + + IMPL::Web::QueryHandler::PageFormat->Invoke($action,$nextHandlerIsAuthHandler) { + + #some internals + + my $result = $nextHandlerIsAuthHandler() { + + # some internals - IMPL::Web::QueryHandler::AuthenticateCookie->Invoke($action,$nextHandlerIsSecCall) { - - # some internals - # do auth and generate security $context - - # impersonate $context and call the next handler - return $context->Impersonate($nextHandlerIsSecCall) { - - # some internals - - IMPL::Web::QueryHandler::SecCallToMethod->Invoke($action,undef) { - - # next handler isn't present as it is the last hanler - - # some internals - # calculate the $method and the $target from CGI request - - IMPL::Security->AccessCheck($target,$method); - return $target->$method(); - - } - - } - - } - } - - # some intenals - # formatted output to $action->response->streamBody - } + IMPL::Web::QueryHandler::AuthenticateCookie->Invoke($action,$nextHandlerIsSecCall) { + + # some internals + # do auth and generate security $context + + # impersonate $context and call the next handler + return $context->Impersonate($nextHandlerIsSecCall) { + + # some internals + + IMPL::Web::QueryHandler::SecCallToMethod->Invoke($action,undef) { + + # next handler isn't present as it is the last hanler + + # some internals + # calculate the $method and the $target from CGI request + + IMPL::Security->AccessCheck($target,$method); + return $target->$method(); + + } + + } + + } + } + + # some intenals + # formatted output to $action->response->streamBody + } } =end code