Skip to content

Commit

Permalink
return array references consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 25, 2015
1 parent 9b758ca commit 4e934d0
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 148 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -23,6 +23,8 @@
- Removed deprecated render_exception and render_not_found methods from
Mojolicious::Controller.
- Removed deprecated keep_alive_requests setting from Hypnotoad.
- Changed return values of all and find methods in
Mojo::UserAgent::CookieJar.
- Renamed types attribute in Mojolicious::Types to mapping.
- Renamed current attribute in Mojolicious::Routes::Match to position.
- Renamed pattern attribute in Mojolicious::Routes::Route to unparsed.
Expand Down
16 changes: 8 additions & 8 deletions lib/Mojo/UserAgent/CookieJar.pm
Expand Up @@ -34,7 +34,7 @@ sub add {

sub all {
my $jar = shift->{jar};
return map { @{$jar->{$_}} } sort keys %$jar;
return [map { @{$jar->{$_}} } sort keys %$jar];
}

sub empty { delete shift->{jar} }
Expand Down Expand Up @@ -65,9 +65,9 @@ sub extract {
sub find {
my ($self, $url) = @_;

return unless my $domain = my $host = $url->ihost;
my $path = $url->path->to_abs_string;
my @found;
return \@found unless my $domain = my $host = $url->ihost;
my $path = $url->path->to_abs_string;
while ($domain =~ /[^.]+\.[^.]+|localhost$/) {
next unless my $old = $self->{jar}{$domain};

Expand All @@ -92,14 +92,14 @@ sub find {
# Remove another part
continue { $domain =~ s/^[^.]+\.?// }

return @found;
return \@found;
}

sub inject {
my ($self, $tx) = @_;
return unless keys %{$self->{jar}};
my $req = $tx->req;
$req->cookies($self->find($req->url));
$req->cookies(@{$self->find($req->url)});
}

sub _compare {
Expand Down Expand Up @@ -134,7 +134,7 @@ Mojo::UserAgent::CookieJar - Cookie jar for HTTP user agents
);
# Find request cookies
for my $cookie ($jar->find(Mojo::URL->new('http://localhost/test'))) {
for my $cookie (@{$jar->find(Mojo::URL->new('http://localhost/test'))}) {
say $cookie->name;
say $cookie->value;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ Add multiple L<Mojo::Cookie::Response> objects to the jar.
=head2 all
my @cookies = $jar->all;
my $cookies = $jar->all;
Return all L<Mojo::Cookie::Response> objects that are currently stored in the
jar.
Expand All @@ -195,7 +195,7 @@ Extract response cookies from transaction.
=head2 find
my @cookies = $jar->find(Mojo::URL->new);
my $cookies = $jar->find(Mojo::URL->new);
Find L<Mojo::Cookie::Request> objects in the jar for L<Mojo::URL> object.
Expand Down

0 comments on commit 4e934d0

Please sign in to comment.