factor out match_not
Matt S Trout [Wed, 15 Dec 2010 12:14:20 +0000 (12:14 +0000)]
lib/Web/Dispatch/Parser.pm
lib/Web/Dispatch/Predicates.pm

index 69c510b..92aa9b6 100644 (file)
@@ -106,13 +106,7 @@ sub _parse_spec_section {
     # !something
 
     /\G!/gc and
-      return do {
-        my $match = $self->_parse_spec_section($_);
-        return sub {
-          return {} unless my @discard = $match->(@_);
-          return;
-        };
-      };
+      return match_not($self->_parse_spec_section($_));
 
     # ?<param spec>
     /\G\?/gc and
index bfc5f2f..f47605b 100644 (file)
@@ -4,7 +4,7 @@ use strictures 1;
 use base qw(Exporter);
 
 our @EXPORT = qw(
-  match_and match_or match_method match_path match_path_strip
+  match_and match_or match_not match_method match_path match_path_strip
   match_extension
 );
 
@@ -41,6 +41,17 @@ sub match_or {
   }
 }
 
+sub match_not {
+  my ($match) = @_;
+  sub {
+    if (my @discard = $match->($_[0])) {
+      ();
+    } else {
+      ({});
+    }
+  }
+}
+
 sub match_method {
   my ($method) = @_;
   sub {