X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FWeb%2FDispatch%2FWrapper.pm;h=80e6356889c6a1f045609efdf10e8b4938d9d1b3;hb=876e62e1e9790a0d16f82b5793e98d4eed904bb5;hp=f60a435958e23f03f6b7242e9f4a0ab17348ba5f;hpb=3706e2a088071de6429d8653a4dabded26db6ca1;p=catagits%2FWeb-Simple.git diff --git a/lib/Web/Dispatch/Wrapper.pm b/lib/Web/Dispatch/Wrapper.pm index f60a435..80e6356 100644 --- a/lib/Web/Dispatch/Wrapper.pm +++ b/lib/Web/Dispatch/Wrapper.pm @@ -3,23 +3,28 @@ package Web::Dispatch::Wrapper; use strictures 1; use Exporter 'import'; -our @EXPORT_OK = qw(dispatch_wrapper redispatch_to response_filter); +our @EXPORT = qw(dispatch_wrapper redispatch_to response_filter); sub dispatch_wrapper (&) { + my ($code) = @_; + __PACKAGE__->from_code($code); +} + +sub from_code { my ($class, $code) = @_; bless(\$code, $class); } sub redispatch_to { - my ($class, $new_path) = @_; - $class->from_code(sub { + my ($new_path) = @_; + __PACKAGE__->from_code(sub { $_[1]->({ %{$_[0]}, PATH_INFO => $new_path }); }); } sub response_filter (&) { - my ($class, $code) = @_; - $class->from_code(sub { + my ($code) = @_; + __PACKAGE__->from_code(sub { my @result = $_[1]->($_[0]); if (@result) { $code->(@result);