Skip to content

Commit

Permalink
renamed match to contains
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 9, 2011
1 parent 864e001 commit 4279a92
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -4,7 +4,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Code name "Leaf Fluttering In Wind", this is a major release.
- Increased Perl version requirement to 5.10.1.
- Added EXPERIMENTAL on_body attribute to Mojo::Content.
- Added EXPERIMENTAL match method to Mojo::Path.
- Added EXPERIMENTAL contains method to Mojo::Path.
- Improved message parser performance slightly.
- Improved Mojo::IOLoop to die if started twice.
- Improved setuidgid in Mojo::Server::Daemon.
Expand Down
12 changes: 6 additions & 6 deletions lib/Mojo/Path.pm
Expand Up @@ -70,13 +70,13 @@ sub clone {
return $clone;
}

sub match {
sub contains {
my ($self, $path) = @_;

my $parts = $self->new($path)->parts;
for my $part (@{$self->parts}) {
return 1 unless defined(my $match = shift @$parts);
return unless $part eq $match;
return 1 unless defined(my $try = shift @$parts);
return unless $part eq $try;
}

return @$parts ? undef : 1;
Expand Down Expand Up @@ -199,11 +199,11 @@ Canonicalize path.
Clone path.
=head2 C<match>
=head2 C<contains>
my $success = $path->match('/foo');
my $success = $path->contains('/foo');
Check if path matches given prefix.
Check if path contains given prefix.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<parse>
Expand Down
46 changes: 23 additions & 23 deletions t/mojo/path.t
Expand Up @@ -134,31 +134,31 @@ is $path->parts->[3], undef, 'no part';
is $path->leading_slash, 1, 'has leading slash';
is $path->trailing_slash, undef, 'no trailing slash';

# Match
# Contains
$path = Mojo::Path->new('/foo/bar');
is $path->match('/'), 1, 'match';
is $path->match('/foo'), 1, 'match';
is $path->match('/foo/bar'), 1, 'match';
is $path->match('/foobar'), undef, 'no match';
is $path->match('/foo/b'), undef, 'no match';
is $path->match('/foo/bar/baz'), undef, 'no match';
is $path->contains('/'), 1, 'contains path';
is $path->contains('/foo'), 1, 'contains path';
is $path->contains('/foo/bar'), 1, 'contains path';
is $path->contains('/foobar'), undef, 'does not contain path';
is $path->contains('/foo/b'), undef, 'does not contain path';
is $path->contains('/foo/bar/baz'), undef, 'does not contain path';
$path = Mojo::Path->new('/♥/bar');
is $path->match('/♥'), 1, 'match';
is $path->match('/♥/bar'), 1, 'match';
is $path->match('/♥foo'), undef, 'no match';
is $path->match('/foo♥'), undef, 'no match';
is $path->contains('/♥'), 1, 'contains path';
is $path->contains('/♥/bar'), 1, 'contains path';
is $path->contains('/♥foo'), undef, 'does not contain path';
is $path->contains('/foo♥'), undef, 'does not contain path';
$path = Mojo::Path->new('/');
is $path->match('/'), 1, 'match';
is $path->match('/foo'), undef, 'no match';
is $path->contains('/'), 1, 'contains path';
is $path->contains('/foo'), undef, 'does not contain path';
$path = Mojo::Path->new('/0');
is $path->match('/'), 1, 'match';
is $path->match('/0'), 1, 'match';
is $path->match('/0/0'), undef, 'no match';
is $path->contains('/'), 1, 'contains path';
is $path->contains('/0'), 1, 'contains path';
is $path->contains('/0/0'), undef, 'does not contain path';
$path = Mojo::Path->new('/0/♥.html');
is $path->match('/'), 1, 'match';
is $path->match('/0'), 1, 'match';
is $path->match('/0/♥.html'), 1, 'match';
is $path->match('/0/♥'), undef, 'no match';
is $path->match('/0/0.html'), undef, 'no match';
is $path->match('/0.html'), undef, 'no match';
is $path->match('/♥.html'), undef, 'no match';
is $path->contains('/'), 1, 'contains path';
is $path->contains('/0'), 1, 'contains path';
is $path->contains('/0/♥.html'), 1, 'contains path';
is $path->contains('/0/♥'), undef, 'does not contain path';
is $path->contains('/0/0.html'), undef, 'does not contain path';
is $path->contains('/0.html'), undef, 'does not contain path';
is $path->contains('/♥.html'), undef, 'does not contain path';
4 changes: 2 additions & 2 deletions t/mojolicious/dispatcher_lite_app.t
Expand Up @@ -19,7 +19,7 @@ app->hook(
before_dispatch => sub {
my $self = shift;
$self->render_text($self->param('a'), status => 205)
if $self->req->url->path->match('/custom');
if $self->req->url->path->contains('/custom');
}
);

Expand All @@ -28,7 +28,7 @@ app->hook(
after_static_dispatch => sub {
my $self = shift;
$self->render_text('this works too')
if $self->req->url->path->match('/custom_too');
if $self->req->url->path->contains('/custom_too');
}
);

Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -705,7 +705,7 @@ get '/bridge2stash' =>
# Make sure after_dispatch can make session changes
hook after_dispatch => sub {
my $self = shift;
return unless $self->req->url->path->match('/late/session');
return unless $self->req->url->path->contains('/late/session');
$self->session(late => 'works!');
};

Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/upload_stream_lite_app.t
Expand Up @@ -28,7 +28,7 @@ app->hook(
return unless $req->content->is_parsing_body;

# Trigger early request for everything under "/upload"
$tx->on_request->($tx) if $req->url->path->match('/upload');
$tx->on_request->($tx) if $req->url->path->contains('/upload');
}
);
}
Expand Down

0 comments on commit 4279a92

Please sign in to comment.