Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (42 sloc) 1.33 KB
package Angelos::Middleware::Builder;
use HTTP::Engine::Middleware;
use UNIVERSAL::require;
use Angelos::Config;
sub build {
my $class = shift;
my $application_request_handler = shift;
my $middlewares = $class->_get_middlewares;
$class->_build_request_handler( $application_request_handler,
$middlewares );
}
sub _build_request_handler {
my ( $class, $application_request_handler, $middlewares ) = @_;
my $request_handler = $application_request_handler;
my $mw = HTTP::Engine::Middleware->new;
for my $middleware ( @{$middlewares} ) {
my $middleware_name
= $class->resovle_middleware_name( $middleware->{module} );
$mw->install( $middleware_name => $middleware->{config} || {} );
}
$mw->handler($application_request_handler);
}
sub resovle_middleware_name {
my ( $class, $name ) = @_;
my $middleeware_name ||= 'Angelos::Middleware::' . $name;
return $middleeware_name;
}
sub _get_middlewares {
Angelos::Config->instance->middlewares;
}
1;
__END__
=head1 NAME
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 AUTHOR
Takatoshi Kitano E<lt>kitano.tk@gmail.comE<gt>
=head1 SEE ALSO
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
Jump to Line
Something went wrong with that request. Please try again.