view Lib/IMPL/Web/QueryHandler/UrlController.pm @ 144:b56ebc31bf18

Empty nodes no more created while transforming a post request to the DOM document minor speed improvements to the object CTOR caching Added support for a secure processing (and 'laundering' ) a CGI parameters Many minor fixes
author wizard
date Tue, 13 Jul 2010 02:05:38 +0400
parents 5a9f64890c31
children e6447ad85cb4
line wrap: on
line source

package IMPL::Web::QueryHandler::UrlController;
use strict;
use base qw(IMPL::Web::QueryHandler);

use IMPL::Class::Property;
use IMPL::Exception;
use Carp qw(croak);

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 eval{ $module->can('InvokeAction'); };
	if (my $err = $@ ) {
		die new IMPL::Exception("Failed to load module",$module,$err);
	}
	
	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