isolate param matching in Predicates
[catagits/Web-Simple.git] / lib / Web / Dispatch / Predicates.pm
index 432058c..758afed 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
 );
 
 sub match_and {
@@ -101,6 +101,28 @@ sub match_extension {
   };
 }
 
+sub match_query {
+  my $spec = shift;
+  require Web::Dispatch::ParamParser;
+  sub {
+    _extract_params(
+      Web::Dispatch::ParamParser::get_unpacked_query_from($_[0]),
+      $spec
+    )
+  };
+}
+
+sub match_body {
+  my $spec = shift;
+  require Web::Dispatch::ParamParser;
+  sub {
+    _extract_params(
+      Web::Dispatch::ParamParser::get_unpacked_body_from($_[0]),
+      $spec
+    )
+  };
+}
+
 sub _extract_params {
   my ($raw, $spec) = @_;
   foreach my $name (@{$spec->{required}||[]}) {