experimental upload support
[catagits/Web-Simple.git] / lib / Web / Dispatch / Predicates.pm
index 432058c..db2ad88 100644 (file)
@@ -5,7 +5,7 @@ use base qw(Exporter);
 
 our @EXPORT = qw(
   match_and match_or match_not match_method match_path match_path_strip
-  match_extension
+  match_extension match_query match_body match_uploads
 );
 
 sub match_and {
@@ -101,6 +101,27 @@ sub match_extension {
   };
 }
 
+sub match_query {
+  _param_matcher(query => $_[0]);
+}
+
+sub match_body {
+  _param_matcher(body => $_[0]);
+}
+
+sub match_uploads {
+  _param_matcher(uploads => $_[0]);
+}
+
+sub _param_matcher {
+  my ($type, $spec) = @_;
+  require Web::Dispatch::ParamParser;
+  my $unpack = Web::Dispatch::ParamParser->can("get_unpacked_${type}_from");
+  sub {
+    _extract_params($unpack->($_[0]), $spec)
+  };
+}
+
 sub _extract_params {
   my ($raw, $spec) = @_;
   foreach my $name (@{$spec->{required}||[]}) {