fix config handling, finish porting bloggery, safer exporting
[catagits/Web-Simple.git] / lib / Web / Dispatch / Wrapper.pm
CommitLineData
4ed4fb42 1package Web::Dispatch::Wrapper;
2
3use strictures 1;
445b3ea0 4use Exporter 'import';
4ed4fb42 5
876e62e1 6our @EXPORT = qw(dispatch_wrapper redispatch_to response_filter);
445b3ea0 7
8sub dispatch_wrapper (&) {
876e62e1 9 my ($code) = @_;
10 __PACKAGE__->from_code($code);
11}
12
13sub from_code {
4ed4fb42 14 my ($class, $code) = @_;
15 bless(\$code, $class);
16}
17
445b3ea0 18sub redispatch_to {
876e62e1 19 my ($new_path) = @_;
20 __PACKAGE__->from_code(sub {
445b3ea0 21 $_[1]->({ %{$_[0]}, PATH_INFO => $new_path });
22 });
23}
24
25sub 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 37sub wrap {
38 my $code = ${$_[0]};
39 my $app = $_[1];
40 sub { $code->($_[0], $app) }
41}
42
431;