Commit | Line | Data |
---|---|---|
4ed4fb42 | 1 | package Web::Dispatch::Wrapper; |
2 | ||
3 | use strictures 1; | |
445b3ea0 | 4 | use Exporter 'import'; |
4ed4fb42 | 5 | |
876e62e1 | 6 | our @EXPORT = qw(dispatch_wrapper redispatch_to response_filter); |
445b3ea0 | 7 | |
8 | sub dispatch_wrapper (&) { | |
876e62e1 | 9 | my ($code) = @_; |
10 | __PACKAGE__->from_code($code); | |
11 | } | |
12 | ||
13 | sub from_code { | |
4ed4fb42 | 14 | my ($class, $code) = @_; |
15 | bless(\$code, $class); | |
16 | } | |
17 | ||
445b3ea0 | 18 | sub redispatch_to { |
876e62e1 | 19 | my ($new_path) = @_; |
20 | __PACKAGE__->from_code(sub { | |
445b3ea0 | 21 | $_[1]->({ %{$_[0]}, PATH_INFO => $new_path }); |
22 | }); | |
23 | } | |
24 | ||
25 | sub response_filter (&) { | |
876e62e1 | 26 | my ($code) = @_; |
27 | __PACKAGE__->from_code(sub { | |
445b3ea0 | 28 | my @result = $_[1]->($_[0]); |
29 | if (@result) { | |
30 | $code->(@result); | |
31 | } else { | |
32 | () | |
33 | } | |
34 | }); | |
35 | } | |
36 | ||
4ed4fb42 | 37 | sub wrap { |
38 | my $code = ${$_[0]}; | |
39 | my $app = $_[1]; | |
40 | sub { $code->($_[0], $app) } | |
41 | } | |
42 | ||
43 | 1; |