Mercurial > pub > Impl
changeset 110:c13a215508ca
Refactoring,
ControllerUnit
author | wizard |
---|---|
date | Mon, 17 May 2010 17:42:27 +0400 |
parents | ddf0f037d460 |
children | 6c25ea91c985 |
files | Lib/IMPL/Web/Application/ControllerUnit.pm Lib/IMPL/Web/QueryHandler/SecureCall.pm Lib/IMPL/Web/QueryHandler/UrlController.pm |
diffstat | 3 files changed, 81 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Web/Application/ControllerUnit.pm Mon May 17 17:42:27 2010 +0400 @@ -0,0 +1,30 @@ +package IMPL::Web::Application::ControllerUnit; + +use base qw(IMPL::Object); + +use IMPL::Class::Property; + +BEGIN { + public property action => prop_get | owner_set; + public property application => prop_get | owner_set; + public property query => prop_get | owner_set; +} + +sub CTOR { + my ($this,$action) = @_; + + $this->action($action); + $this->application($action->application); + $this->query($action->query); +} + +sub InvokeAction { + my ($self,$method,$action) = @_; + + if ($self->can($method)) { + my $unit = $self->new($action); + $unit->$method(); + } else { + die new IMPL::InvalidOperationException("Invalid method call",$self,$method); + } +} \ No newline at end of file
--- a/Lib/IMPL/Web/QueryHandler/SecureCall.pm Mon May 17 05:12:08 2010 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -package IMPL::Web::QueryHandler::SecureCall; -use strict; -use base qw(IMPL::Web::QueryHandler); - -use IMPL::Class::Property; -use IMPL::Exception; -use Carp; - -BEGIN { - public property namespace => prop_all; -} - -__PACKAGE__->PassThroughArgs; - -sub Process { - my ($this,$action,$nextHandler) = @_; - - my $namespace = $this->namespace || $action->application->type; - - my @target = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("No target specified"); - - my $method = pop @target; - $method =~ s/\.\w+$//; - - my $module = join '::',$namespace,@target; - - eval "require $module; 1;"; - carp $@ if $@; - - if(UNIVERSAL::can($module,'InvokeAction')) { - $module->InvokeAction($method,$action); - } else { - die new IMPL::InvalidOperationException("Failed to invoke action",$ENV{PATH_INFO},$module,$method); - } -} - -1; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Web/QueryHandler/UrlController.pm Mon May 17 17:42:27 2010 +0400 @@ -0,0 +1,51 @@ +package IMPL::Web::QueryHandler::UrlController; +use strict; +use base qw(IMPL::Web::QueryHandler); + +use IMPL::Class::Property; +use IMPL::Exception; +use Carp; + +BEGIN { + public property namespace => prop_all; +} + +__PACKAGE__->PassThroughArgs; + +sub Process { + my ($this,$action,$nextHandler) = @_; + + my $namespace = $this->namespace || $action->application->type; + + my @target = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("No target specified"); + + my $method = pop @target; + $method =~ s/\.\w+$//; + + my $module = join '::',$namespace,@target; + + eval "require $module; 1;" unless $INC{$module}; + carp $@ if $@; + + if(UNIVERSAL::can($module,'InvokeAction')) { + $module->InvokeAction($method,$action); + } else { + die new IMPL::InvalidOperationException("Failed to invoke action",$ENV{PATH_INFO},$module,$method); + } +} + +1; + +__END__ + +=pod + +=head1 NAME + +C<IMPL::Web::QueryHandler::UrlController> - вызов метода на основе <url> запроса. + +=head1 DESCRIPTION + +Использует переменную C<$ENV{PATH_INFO}> для получения имени и метода модуля. + +=cut \ No newline at end of file