Skip to content

Commit

Permalink
use numeric comparison for status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 12, 2014
1 parent d5a08aa commit 06b041e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

4.93 2014-04-09
4.93 2014-04-13
- Fixed bug where Mojolicious::Static would not use the correct default MIME
type.

Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Message/Response.pm
Expand Up @@ -88,7 +88,7 @@ sub cookies {
return $self;
}

sub default_message { $MESSAGES{$_[1] || $_[0]->code || 404} || '' }
sub default_message { $MESSAGES{$_[1] || $_[0]->code // 404} || '' }

sub extract_start_line {
my ($self, $bufref) = @_;
Expand Down Expand Up @@ -128,7 +128,7 @@ sub get_start_line_chunk {
sub is_empty {
my $self = shift;
return undef unless my $code = $self->code;
return $self->is_status_class(100) || $code eq 204 || $code eq 304;
return $self->is_status_class(100) || $code == 204 || $code == 304;
}

sub is_status_class {
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/Daemon.pm
Expand Up @@ -113,7 +113,7 @@ sub _finish {
if (my $ws = $c->{tx} = delete $c->{ws}) {

# Successful upgrade
if ($ws->res->code eq '101') {
if ($ws->res->code == 101) {
weaken $self;
$ws->on(resume => sub { $self->_write($id) });
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/PSGI.pm
Expand Up @@ -30,7 +30,7 @@ sub run {

# PSGI response
my $io = Mojo::Server::PSGI::_IO->new(tx => $tx, empty => $tx->is_empty);
return [$res->code || 404, \@headers, $io];
return [$res->code // 404, \@headers, $io];
}

sub to_psgi_app {
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -70,8 +70,8 @@ sub redirect {

# Commonly used codes
my $res = $old->res;
my $code = $res->code // '';
return undef unless grep { $_ eq $code } 301, 302, 303, 307, 308;
my $code = $res->code // 0;
return undef unless grep { $_ == $code } 301, 302, 303, 307, 308;

# Fix broken location without authority and/or scheme
return unless my $location = $res->headers->location;
Expand All @@ -81,7 +81,7 @@ sub redirect {
# Clone request if necessary
my $new = Mojo::Transaction::HTTP->new;
my $req = $old->req;
if ($code eq 307 || $code eq 308) {
if ($code == 307 || $code == 308) {
return undef unless my $clone = $req->clone;
$new->req($clone);
}
Expand Down Expand Up @@ -126,8 +126,8 @@ sub tx {

sub upgrade {
my ($self, $tx) = @_;
my $code = $tx->res->code // '';
return undef unless $tx->req->is_handshake && $code eq '101';
my $code = $tx->res->code // 0;
return undef unless $tx->req->is_handshake && $code == 101;
my $ws = Mojo::Transaction::WebSocket->new(handshake => $tx, masked => 1);
return $ws->client_challenge ? $ws : undef;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Command/cpanify.pm
Expand Up @@ -28,10 +28,10 @@ sub run {
);

unless ($tx->success) {
my $code = $tx->res->code || '';
my $code = $tx->res->code // 0;
my $msg = $tx->error;
if ($code eq '401') { $msg = 'Wrong username or password.' }
elsif ($code eq '409') { $msg = 'File already exists on CPAN.' }
if ($code == 401) { $msg = 'Wrong username or password.' }
elsif ($code == 409) { $msg = 'File already exists on CPAN.' }
die qq{Problem uploading file "$file". ($msg)\n};
}

Expand Down

0 comments on commit 06b041e

Please sign in to comment.