[Bps-public-commit] r16920 - in Path-Dispatcher/trunk: lib/Path/Dispatcher lib/Path/Dispatcher/Rule
sartak at bestpractical.com
sartak at bestpractical.com
Tue Nov 18 20:07:09 EST 2008
Author: sartak
Date: Tue Nov 18 20:07:08 2008
New Revision: 16920
Added:
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Eq.pm
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
Log:
r75791 at onn: sartak | 2008-11-18 20:07:06 -0500
Simple rule: Eq, which tests: path eq $string
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule.pm Tue Nov 18 20:07:08 2008
@@ -64,6 +64,7 @@
require Path::Dispatcher::Rule::CodeRef;
require Path::Dispatcher::Rule::Dispatch;
require Path::Dispatcher::Rule::Empty;
+require Path::Dispatcher::Rule::Eq;
require Path::Dispatcher::Rule::Intersection;
require Path::Dispatcher::Rule::Metadata;
require Path::Dispatcher::Rule::Regex;
Added: Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Eq.pm
==============================================================================
--- (empty file)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Rule/Eq.pm Tue Nov 18 20:07:08 2008
@@ -0,0 +1,52 @@
+#!/usr/bin/env perl
+package Path::Dispatcher::Rule::Eq;
+use Moose;
+extends 'Path::Dispatcher::Rule';
+
+has string => (
+ is => 'rw',
+ isa => 'Str',
+ required => 1,
+);
+
+sub _match {
+ my $self = shift;
+ my $path = shift;
+
+ return $path->path eq $self->string;
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Path::Dispatcher::Rule::Regex - predicate is a regular expression
+
+=head1 SYNOPSIS
+
+ my $rule = Path::Dispatcher::Rule::Regex->new(
+ regex => qr{^/comment(s?)/(\d+)$},
+ block => sub { display_comment($2) },
+ );
+
+=head1 DESCRIPTION
+
+Rules of this class use a regular expression to match against the path.
+
+=head1 ATTRIBUTES
+
+=head2 regex
+
+The regular expression to match against the path. It works just as you'd expect!
+
+The results are the capture variables (C<$1>, C<$2>, etc) and when the
+resulting L<Path::Dispatcher::Match> is executed, the codeblock will see these
+values. C<$`>, C<$&>, and C<$'> are not (yet) restored.
+
+=cut
+
More information about the Bps-public-commit
mailing list