change filter_response to response_filter in the places I got it wrong
[catagits/Web-Simple.git] / lib / Web / Simple.pm
index fe1722e..5e38ba8 100644 (file)
@@ -30,7 +30,7 @@ sub _export_into {
     *{"${app_package}::dispatch"} = sub {
       $app_package->_setup_dispatcher(@_);
     };
-    *{"${app_package}::filter_response"} = sub (&) {
+    *{"${app_package}::response_filter"} = sub (&) {
       $app_package->_construct_response_filter($_[0]);
     };
     *{"${app_package}::redispatch_to"} = sub {
@@ -148,7 +148,7 @@ It also exports the following subroutines:
 
   dispatch [ sub (...) { ... }, ... ];
 
-  filter_response { ... };
+  response_filter { ... };
 
   redispatch_to '/somewhere';
 
@@ -421,7 +421,7 @@ will match and strip .html from the path (assuming the subroutine itself
 returns something, of course). This is normally used for rendering - e.g.
 
   sub (.html) {
-    filter_response { $self->render_html($_[1]) }
+    response_filter { $self->render_html($_[1]) }
   }
 
 Additionally,
@@ -431,6 +431,50 @@ Additionally,
 will match any extension and supplies the stripped extension as a match
 argument.
 
+=head3 Query and body parameter matches
+
+Query and body parameters can be match via
+
+  sub (?<param spec>) { # match URI query
+  sub (%<param spec>) { # match body params
+
+The body is only matched if the content type is
+application/x-www-form-urlencoded (note this means that Web::Simple does
+not yet handle uploads; this will be addressed in a later release).
+
+The param spec is elements of one of the following forms -
+
+  param~        # optional parameter
+  param=        # required parameter
+  @param~       # optional multiple parameter
+  @param=       # required multiple parameter
+  *             # include all other parameters
+  @*            # include all other parameters as multiple
+
+separated by the & character.
+
+So, to match a page parameter with an optional order_by parameter one
+would write:
+
+  sub (?page=&order_by~) {
+
+Parameters selected are turned into a hashref; in the case of singular
+parameters then if multiple values are found the last one is used. In the
+case of multiple parameters an arrayref of all values (or an empty arrayref
+for a missing optional) is used. The resulting hashref is provided as a
+match argument. So we might write something like:
+
+  sub (?page=&order_by~) {
+    my ($self, $p) = @_;
+    return unless $p->{page} =~ /^\d+$/;
+    $p->{order_by} ||= 'id';
+    response_filter {
+      $_[1]->search_rs({}, $p);
+    }
+  }
+
+to implement paging and ordering against a L<DBIx::Class::ResultSet> object.
+
 =head3 Combining matches
 
 Matches may be combined with the + character - e.g.