| 14 | | my %exports = ( |
| 15 | | middlewares => sub { |
| 16 | | subname 'HTTPEx::Declare::middlewares' => sub (@) { |
| 17 | | HTTP::Engine->load_middlewares( @_ ); |
| 18 | | } |
| 19 | | }, |
| 20 | | interface => sub { |
| 21 | | subname 'HTTPEx::Declare::interface' => sub ($$) { |
| 22 | | $interface = { |
| 23 | | module => shift, |
| 24 | | args => shift, |
| 25 | | }; |
| 26 | | } |
| 27 | | }, |
| 28 | | run => sub { |
| 29 | | subname 'HTTPEx::Declare::run' => sub (&;@) { |
| 30 | | unless ($interface) { |
| 31 | | require Carp; |
| 32 | | Carp::croak 'please define interface previously'; |
| 33 | | } |
| 34 | | my $request_handler = shift; |
| 35 | | my $engine = HTTP::Engine->new( |
| 36 | | interface => { |
| 37 | | module => $interface->{module}, |
| 38 | | args => $interface->{args}, |
| 39 | | request_handler => $request_handler, |
| 40 | | }, |
| 41 | | ); |
| 42 | | undef $interface; |
| 43 | | $engine->run(@_); |
| 44 | | } |
| 45 | | }, |
| 46 | | ); |
| | 13 | sub middlewares (@) { |
| | 14 | HTTP::Engine->load_middlewares(@_); |
| | 15 | } |
| 48 | | Sub::Exporter::setup_exporter({ |
| 49 | | exports => \%exports, |
| 50 | | groups => { default => [':all'] } |
| 51 | | }); |
| | 17 | sub interface($$) { |
| | 18 | $interface = { |
| | 19 | module => shift, |
| | 20 | args => shift, |
| | 21 | }; |
| | 22 | } |
| | 23 | |
| | 24 | sub run(&;@) { |
| | 25 | unless ($interface) { |
| | 26 | require Carp; |
| | 27 | Carp::croak 'please define interface previously'; |
| | 28 | } |
| | 29 | my $request_handler = shift; |
| | 30 | my $engine = HTTP::Engine->new( |
| | 31 | interface => { |
| | 32 | module => $interface->{module}, |
| | 33 | args => $interface->{args}, |
| | 34 | request_handler => $request_handler, |
| | 35 | }, |
| | 36 | ); |
| | 37 | undef $interface; |
| | 38 | $engine->run(@_); |
| | 39 | } |