Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
no need to use length in boolean context
  • Loading branch information
kraih committed Feb 5, 2014
1 parent af606a5 commit cad4da1
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Collection.pm
Expand Up @@ -27,7 +27,7 @@ sub DESTROY { }
sub c { __PACKAGE__->new(@_) }

sub compact {
shift->grep(sub { length($_ // '') });
shift->grep(sub { ($_ // '') ne '' });
}

sub each {
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Content.pm
Expand Up @@ -43,7 +43,7 @@ sub generate_body_chunk {
$self->emit(drain => $offset)
if !delete $self->{delay} && !length($self->{body_buffer} // '');
my $chunk = delete $self->{body_buffer} // '';
return $self->{eof} ? '' : undef unless length $chunk;
return $self->{eof} ? '' : undef if $chunk eq '';

return $chunk;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ sub parse {
my $connection = $headers->connection // '';
my $len = $headers->content_length // '';
$self->relaxed(1)
if !length $len && ($connection =~ /close/i || $headers->content_type);
if $len eq '' && ($connection =~ /close/i || $headers->content_type);
}

# Chunked or relaxed content
Expand Down Expand Up @@ -201,7 +201,7 @@ sub _build_chunk {
my ($self, $chunk) = @_;

# End
return "\x0d\x0a0\x0d\x0a\x0d\x0a" if length $chunk == 0;
return "\x0d\x0a0\x0d\x0a\x0d\x0a" if $chunk eq '';

# First chunk has no leading CRLF
my $crlf = $self->{chunks}++ ? "\x0d\x0a" : '';
Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/DOM.pm
Expand Up @@ -821,6 +821,9 @@ children of the first innermost element.
# "<p><b>BA</b></p>"
$dom->parse('<p>A<p>')->at('p')->wrap_content('<b>B</b>')->root;
# "<p><b>A</b></p><p>B</p>"
$dom->parse('<b>A</b>')->wrap_content('<p></p><p>B</p>');
=head2 xml
my $bool = $dom->xml;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/IOLoop/Server.pm
Expand Up @@ -81,7 +81,7 @@ sub listen {
$options{LocalAddr} =~ s/[\[\]]//g;
$handle = $class->new(%options) or croak "Can't create listen socket: $@";
$fd = fileno $handle;
$ENV{MOJO_REUSE} .= length $ENV{MOJO_REUSE} ? ",$reuse:$fd" : "$reuse:$fd";
$ENV{MOJO_REUSE} .= $ENV{MOJO_REUSE} ne '' ? ",$reuse:$fd" : "$reuse:$fd";
}
$handle->blocking(0);
$self->{handle} = $handle;
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -88,7 +88,7 @@ sub write {

$self->{buffer} .= $chunk;
if ($cb) { $self->once(drain => $cb) }
else { return $self unless length $self->{buffer} }
elsif ($self->{buffer} eq '') { return $self }
$self->reactor->watch($self->{handle}, !$self->{paused}, 1)
if $self->{handle};

Expand Down Expand Up @@ -122,16 +122,16 @@ sub _write {
my $self = shift;

my $handle = $self->{handle};
if (length $self->{buffer}) {
if ($self->{buffer} ne '') {
my $written = $handle->syswrite($self->{buffer});
return $self->_error unless defined $written;
$self->emit_safe(write => substr($self->{buffer}, 0, $written, ''));
$self->_again;
}

$self->emit_safe('drain') unless length $self->{buffer};
return if $self->is_writing;
return $self->close if $self->{graceful};
$self->emit_safe('drain') if $self->{buffer} eq '';
return if $self->is_writing;
return $self->close if $self->{graceful};
$self->reactor->watch($handle, !$self->{paused}, 0) if $self->{handle};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Message.pm
Expand Up @@ -116,7 +116,7 @@ sub get_body_chunk {

$self->emit('progress', 'body', $offset);
my $chunk = $self->content->get_body_chunk($offset);
return $chunk if !defined $chunk || length $chunk;
return $chunk if !defined $chunk || $chunk ne '';
$self->finish;

return $chunk;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Parameters.pm
Expand Up @@ -79,7 +79,7 @@ sub params {
# Parse string
if (defined(my $str = delete $self->{string})) {
my $params = $self->{params} = [];
return $params unless length $str;
return $params if $str eq '';

# W3C suggests to also accept ";" as a separator
my $charset = $self->charset;
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Template.pm
Expand Up @@ -46,7 +46,7 @@ sub build {
# Text (quote and fix line ending)
if ($op eq 'text') {
$value = $newline ? quotemeta($value) . '\n' : quotemeta $value;
$lines[-1] .= "\$_M .= \"" . $value . "\";" if length $value;
$lines[-1] .= "\$_M .= \"" . $value . "\";" if $value ne '';
}

# Code or multiline expression
Expand All @@ -61,7 +61,7 @@ sub build {
# Escaped
if (($op eq 'escp' && !$escape) || ($op eq 'expr' && $escape)) {
$lines[-1] .= "\$_M .= _escape";
$lines[-1] .= " scalar $value" if length $value;
$lines[-1] .= " scalar $value" if $value ne '';
}

# Raw
Expand Down Expand Up @@ -264,7 +264,7 @@ sub _trim {
splice @$line, $j, 0, 'code', $1 if $line->[$j + 1] =~ s/(\s+)$//;

# Text left
return if length $line->[$j + 1];
return if $line->[$j + 1] ne '';
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -84,7 +84,7 @@ sub _body {

# Finished
$self->{state} = $finish ? 'finished' : 'read'
if $self->{write} <= 0 || (defined $buffer && !length $buffer);
if $self->{write} <= 0 || (defined $buffer && $buffer eq '');

return defined $buffer ? $buffer : '';
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -322,7 +322,7 @@ sub _message {
WindowBits => -15
);
$inflate->inflate(($msg .= "\x00\x00\xff\xff"), my $out);
return $self->finish(1009) if length $msg;
return $self->finish(1009) if $msg ne '';
$msg = $out;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/URL.pm
Expand Up @@ -149,7 +149,7 @@ sub to_abs {
= $abs->path($base_path->clone)->path->trailing_slash(0)->canonicalize;

# Query
return $abs if length $abs->query->to_string;
return $abs if $abs->query->to_string ne '';
$abs->query($base->query->clone);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Command/get.pm
Expand Up @@ -86,7 +86,7 @@ sub _json {
say $json->encode($data);
}

sub _say { length && say encode('UTF-8', $_) for @_ }
sub _say { $_ ne '' && say encode('UTF-8', $_) for @_ }

sub _select {
my ($buffer, $selector, $charset, @args) = @_;
Expand Down
7 changes: 2 additions & 5 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -790,11 +790,8 @@ web application.
# Text or CDATA node
print $n->content if $n->node eq 'text' || $n->node eq 'cdata';

# Make sure we have a tag node
next unless $n->node eq 'tag';

# Also include alternate text for images
print $n->{alt} if $n->type eq 'img';
print $n->{alt} if $n->node eq 'tag' && $n->type eq 'img';
}

For a full list of available CSS selectors see L<Mojo::DOM::CSS/"SELECTORS">.
Expand Down Expand Up @@ -974,7 +971,7 @@ Sending a streaming request is almost just as easy.
$drain = sub {
my $content = shift;
my $chunk = substr $body, 0, 1, '';
$drain = undef unless length $body;
$drain = undef if $body eq '';
$content->write($chunk, $drain);
};
$tx->req->content->$drain;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes/Match.pm
Expand Up @@ -60,7 +60,7 @@ sub _match {
return if $r->is_websocket && !$options->{websocket};

# Partial
my $empty = !length $path || $path eq '/';
my $empty = $path eq '' || $path eq '/';
if ($r->partial) {
$captures->{path} = $path;
$self->endpoint($r);
Expand Down

0 comments on commit cad4da1

Please sign in to comment.