Skip to content

Commit

Permalink
fixed a few boolean tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 23, 2011
1 parent 8c3e610 commit 9d8c327
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 244 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Mojolicious.

2.07 2011-10-23 00:00:00
- Improved documentation.
- Fixed a few small test bugs.

2.06 2011-10-23 00:00:00
- Improved documentation.
Expand Down
22 changes: 5 additions & 17 deletions lib/Mojo/Content.pm
Expand Up @@ -112,17 +112,12 @@ sub get_header_chunk {

sub has_leftovers {
my $self = shift;
return 1 if length $self->{buffer} || length $self->{pre_buffer};
return;
return length($self->{buffer}) || length($self->{pre_buffer});
}

sub header_size { length shift->build_headers }

sub is_chunked {
my $self = shift;
my $encoding = $self->headers->transfer_encoding || '';
return $encoding =~ /chunked/i ? 1 : 0;
}
sub is_chunked { (shift->headers->transfer_encoding || '') =~ /chunked/i }

# DEPRECATED in Leaf Fluttering In Wind!
sub is_done {
Expand All @@ -134,21 +129,14 @@ EOF

sub is_dynamic {
my $self = shift;
return 1 if $self->{dynamic} && !defined $self->headers->content_length;
return;
return $self->{dynamic} && !defined $self->headers->content_length;
}

sub is_finished {
return 1 if (shift->{state} || '') eq 'finished';
return;
}
sub is_finished { (shift->{state} || '') eq 'finished' }

sub is_multipart {undef}

sub is_parsing_body {
return 1 if (shift->{state} || '') eq 'body';
return;
}
sub is_parsing_body { (shift->{state} || '') eq 'body' }

sub leftovers {
my $self = shift;
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojo/EventEmitter.pm
Expand Up @@ -15,10 +15,7 @@ use constant DEBUG => $ENV{MOJO_EVENTEMITTER_DEBUG} || 0;
sub emit { shift->_emit(0, @_) }
sub emit_safe { shift->_emit(1, @_) }

sub has_subscribers {
return 1 if @{shift->subscribers(shift)};
return;
}
sub has_subscribers { scalar @{shift->subscribers(shift)} }

sub on {
my ($self, $name, $cb) = @_;
Expand Down
10 changes: 2 additions & 8 deletions lib/Mojo/IOLoop/Resolver.pm
Expand Up @@ -111,15 +111,9 @@ sub build {
return $req;
}

sub is_ipv4 {
return 1 if pop =~ $IPV4_RE;
return;
}
sub is_ipv4 { pop =~ $IPV4_RE }

sub is_ipv6 {
return 1 if pop =~ $IPV6_RE;
return;
}
sub is_ipv6 { pop =~ $IPV6_RE }

sub lookup {
my ($self, $name, $cb) = @_;
Expand Down
4 changes: 1 addition & 3 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -34,9 +34,7 @@ sub handle { shift->{handle} }

sub is_finished {
my $self = shift;
return if length $self->{buffer};
return if @{$self->subscribers('drain')};
return 1;
return !length($self->{buffer}) && !@{$self->subscribers('drain')};
}

sub pause {
Expand Down
8 changes: 2 additions & 6 deletions lib/Mojo/Message.pm
Expand Up @@ -291,16 +291,12 @@ EOF

sub is_dynamic { shift->content->is_dynamic }

sub is_finished {
return 1 if (shift->{state} || '') eq 'finished';
return;
}
sub is_finished { (shift->{state} || '') eq 'finished' }

sub is_limit_exceeded {
my $self = shift;
return unless my $code = ($self->error)[1];
return unless $code ~~ [413, 431];
return 1;
return $code ~~ [413, 431];
}

sub is_multipart { shift->content->is_multipart }
Expand Down
11 changes: 3 additions & 8 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -98,17 +98,12 @@ sub fix_headers {
}

sub is_secure {
my $self = shift;
my $url = $self->url;
return 1 if ($url->scheme || $url->base->scheme || '') eq 'https';
return;
my $url = shift->url;
return ($url->scheme || $url->base->scheme || '') eq 'https';
}

sub is_xhr {
my $self = shift;
return unless my $with = $self->headers->header('X-Requested-With');
return 1 if $with =~ /XMLHttpRequest/i;
return;
(shift->headers->header('X-Requested-With') || '') =~ /XMLHttpRequest/i;
}

sub param {
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/Message/Response.pm
Expand Up @@ -121,8 +121,7 @@ sub fix_headers {
sub is_status_class {
my ($self, $class) = @_;
return unless my $code = $self->code;
return 1 if $code >= $class && $code < ($class + 100);
return;
return $code >= $class && $code < ($class + 100);
}

sub _build_start_line {
Expand Down
8 changes: 2 additions & 6 deletions lib/Mojo/Transaction.pm
Expand Up @@ -29,17 +29,13 @@ EOF
shift->is_finished;
}

sub is_finished {
return 1 if (shift->{state} || '') eq 'finished';
return;
}
sub is_finished { (shift->{state} || '') eq 'finished' }

sub is_websocket {undef}

sub is_writing {
return 1 unless my $state = shift->{state};
return 1 if $state ~~ [qw/write write_start_line write_headers write_body/];
return;
return $state ~~ [qw/write write_start_line write_headers write_body/];
}

# DEPRECATED in Smiling Face With Sunglasses!
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/URL.pm
Expand Up @@ -125,8 +125,7 @@ sub ihost {

sub is_abs {
my $self = shift;
return 1 if $self->scheme && $self->authority;
return;
return $self->scheme && $self->authority;
}

sub parse {
Expand Down
21 changes: 7 additions & 14 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -162,20 +162,17 @@ sub get { shift->_generate_route('get', @_) }
sub has_conditions {
my $self = shift;
return 1 if @{$self->conditions};
if (my $parent = $self->parent) { return $parent->has_conditions }
return;
return unless my $parent = $self->parent;
return $parent->has_conditions;
}

sub has_custom_name {
return 1 if shift->{custom};
return;
}
sub has_custom_name { shift->{custom} }

sub has_websocket {
my $self = shift;
return 1 if $self->is_websocket;
if (my $parent = $self->parent) { return $parent->is_websocket }
return;
return unless my $parent = $self->parent;
return $parent->is_websocket;
}

sub hide { push @{shift->hidden}, @_ }
Expand All @@ -184,14 +181,10 @@ sub is_endpoint {
my $self = shift;
return if $self->inline;
return 1 if $self->block;
return if @{$self->children};
return 1;
return !@{$self->children};
}

sub is_websocket {
return 1 if shift->{websocket};
return;
}
sub is_websocket { shift->{websocket} }

sub name {
my $self = shift;
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/eventemitter.t
Expand Up @@ -121,9 +121,9 @@ $e->unsubscribe(foo => $cb);
is scalar @{$e->subscribers('foo')}, 2, 'two subscribers';
$e->emit('foo');
is $counter, 5, 'event was emitted two times';
is $e->has_subscribers('foo'), 1, 'has subscribers';
ok $e->has_subscribers('foo'), 'has subscribers';
$e->unsubscribe_all('foo');
is $e->has_subscribers('foo'), undef, 'no subscribers';
ok !$e->has_subscribers('foo'), 'no subscribers';
is scalar @{$e->subscribers('foo')}, 0, 'no subscribers';
$e->emit('foo');
is $counter, 5, 'event was not emitted again';
Expand Down

0 comments on commit 9d8c327

Please sign in to comment.