-
-
Save anonymous/8188f553d285be457218 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/.perltidyrc b/.perltidyrc | |
index 7c2cf62..4d311d8 100644 | |
--- a/.perltidyrc | |
+++ b/.perltidyrc | |
@@ -1,7 +1,7 @@ | |
-pbp # Start with Perl Best Practices | |
-w # Show all warnings | |
-iob # Ignore old breakpoints | |
--l=80 # 80 characters per line | |
+-l=100 # 80 characters per line | |
-mbl=2 # No more than 2 blank lines | |
-i=2 # Indentation is 2 columns | |
-ci=2 # Continuation indentation is 2 columns | |
diff --git a/lib/Mojo/Asset/File.pm b/lib/Mojo/Asset/File.pm | |
index 14743df..f5e71c9 100644 | |
--- a/lib/Mojo/Asset/File.pm | |
+++ b/lib/Mojo/Asset/File.pm | |
@@ -124,8 +124,7 @@ sub size { -s shift->handle } | |
sub slurp { | |
my $handle = shift->handle; | |
$handle->sysseek(0, SEEK_SET); | |
- defined $handle->sysread(my $content, -s $handle, 0) | |
- or croak qq{Can't read from asset: $!}; | |
+ defined $handle->sysread(my $content, -s $handle, 0) or croak qq{Can't read from asset: $!}; | |
return $content; | |
} | |
diff --git a/lib/Mojo/Base.pm b/lib/Mojo/Base.pm | |
index 9cbf862..5b96cb9 100644 | |
--- a/lib/Mojo/Base.pm | |
+++ b/lib/Mojo/Base.pm | |
@@ -12,8 +12,7 @@ use Carp (); | |
use IO::Handle (); | |
# Supported on Perl 5.22+ | |
-my $NAME | |
- = eval { require Sub::Util; Sub::Util->can('set_subname') } || sub { $_[1] }; | |
+my $NAME = eval { require Sub::Util; Sub::Util->can('set_subname') } || sub { $_[1] }; | |
# Protect subclasses using AUTOLOAD | |
sub DESTROY { } | |
@@ -39,17 +38,14 @@ sub attr { | |
# Very performance sensitive code with lots of micro-optimizations | |
if (ref $value) { | |
_monkey_patch $class, $attr, sub { | |
- return | |
- exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value->($_[0])) | |
- if @_ == 1; | |
+ return exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value->($_[0])) if @_ == 1; | |
$_[0]{$attr} = $_[1]; | |
$_[0]; | |
}; | |
} | |
elsif (defined $value) { | |
_monkey_patch $class, $attr, sub { | |
- return exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value) | |
- if @_ == 1; | |
+ return exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value) if @_ == 1; | |
$_[0]{$attr} = $_[1]; | |
$_[0]; | |
}; | |
diff --git a/lib/Mojo/Content.pm b/lib/Mojo/Content.pm | |
index 08678de..4af7b71 100644 | |
--- a/lib/Mojo/Content.pm | |
+++ b/lib/Mojo/Content.pm | |
@@ -11,8 +11,7 @@ has headers => sub { Mojo::Headers->new }; | |
has max_buffer_size => sub { $ENV{MOJO_MAX_BUFFER_SIZE} || 262144 }; | |
has max_leftover_size => sub { $ENV{MOJO_MAX_LEFTOVER_SIZE} || 262144 }; | |
-my $BOUNDARY_RE | |
- = qr!multipart.*boundary\s*=\s*(?:"([^"]+)"|([\w'(),.:?\-+/]+))!i; | |
+my $BOUNDARY_RE = qr!multipart.*boundary\s*=\s*(?:"([^"]+)"|([\w'(),.:?\-+/]+))!i; | |
sub body_contains { | |
croak 'Method "body_contains" not implemented by subclass'; | |
@@ -38,8 +37,7 @@ sub clone { | |
sub generate_body_chunk { | |
my ($self, $offset) = @_; | |
- $self->emit(drain => $offset) | |
- if !delete $self->{delay} && !length($self->{body_buffer} // ''); | |
+ $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; | |
@@ -89,8 +87,7 @@ sub parse { | |
# Not chunked, pass through to second buffer | |
else { | |
$self->{real_size} += length $self->{pre_buffer}; | |
- my $limit = $self->is_finished | |
- && length($self->{buffer}) > $self->max_leftover_size; | |
+ my $limit = $self->is_finished && length($self->{buffer}) > $self->max_leftover_size; | |
$self->{buffer} .= $self->{pre_buffer} unless $limit; | |
$self->{pre_buffer} = ''; | |
} | |
@@ -106,8 +103,7 @@ sub parse { | |
my $len = $headers->content_length // ''; | |
if ($self->auto_relax && !length $len) { | |
my $connection = lc($headers->connection // ''); | |
- $self->relaxed(1) | |
- if $connection eq 'close' || (!$connection && $self->expect_close); | |
+ $self->relaxed(1) if $connection eq 'close' || (!$connection && $self->expect_close); | |
} | |
# Chunked or relaxed content | |
@@ -179,13 +175,11 @@ sub _decompress { | |
my ($self, $chunk) = @_; | |
# No compression | |
- return $self->emit(read => $chunk) | |
- unless $self->auto_decompress && $self->is_compressed; | |
+ return $self->emit(read => $chunk) unless $self->auto_decompress && $self->is_compressed; | |
# Decompress | |
$self->{post_buffer} .= $chunk; | |
- my $gz = $self->{gz} | |
- //= Compress::Raw::Zlib::Inflate->new(WindowBits => WANT_GZIP); | |
+ my $gz = $self->{gz} //= Compress::Raw::Zlib::Inflate->new(WindowBits => WANT_GZIP); | |
my $status = $gz->inflate(\$self->{post_buffer}, my $out); | |
$self->emit(read => $out) if defined $out; | |
@@ -217,8 +211,7 @@ sub _parse_chunked { | |
# Start new chunk (ignore the chunk extension) | |
unless ($self->{chunk_len}) { | |
- last | |
- unless $self->{pre_buffer} =~ s/^(?:\x0d?\x0a)?([0-9a-fA-F]+).*\x0a//; | |
+ last unless $self->{pre_buffer} =~ s/^(?:\x0d?\x0a)?([0-9a-fA-F]+).*\x0a//; | |
next if $self->{chunk_len} = hex $1; | |
# Last chunk | |
@@ -234,8 +227,7 @@ sub _parse_chunked { | |
} | |
# Trailing headers | |
- $self->_parse_chunked_trailing_headers | |
- if ($self->{chunk_state} // '') eq 'trailing_headers'; | |
+ $self->_parse_chunked_trailing_headers if ($self->{chunk_state} // '') eq 'trailing_headers'; | |
# Check buffer size | |
@$self{qw(state limit)} = ('finished', 1) | |
diff --git a/lib/Mojo/Content/MultiPart.pm b/lib/Mojo/Content/MultiPart.pm | |
index a482909..f39d464 100644 | |
--- a/lib/Mojo/Content/MultiPart.pm | |
+++ b/lib/Mojo/Content/MultiPart.pm | |
@@ -7,8 +7,7 @@ has parts => sub { [] }; | |
sub body_contains { | |
my ($self, $chunk) = @_; | |
- ($_->headers_contain($chunk) or $_->body_contains($chunk)) and return 1 | |
- for @{$self->parts}; | |
+ ($_->headers_contain($chunk) or $_->body_contains($chunk)) and return 1 for @{$self->parts}; | |
return undef; | |
} | |
@@ -74,14 +73,12 @@ sub get_body_chunk { | |
# Headers | |
my $header_len = $part->header_size; | |
- return $part->get_header_chunk($offset - $len) | |
- if ($len + $header_len) > $offset; | |
+ return $part->get_header_chunk($offset - $len) if ($len + $header_len) > $offset; | |
$len += $header_len; | |
# Content | |
my $content_len = $part->body_size; | |
- return $part->get_body_chunk($offset - $len) | |
- if ($len + $content_len) > $offset; | |
+ return $part->get_body_chunk($offset - $len) if ($len + $content_len) > $offset; | |
$len += $content_len; | |
# Boundary | |
@@ -89,8 +86,7 @@ sub get_body_chunk { | |
$boundary .= '--'; | |
$boundary_len += 2; | |
} | |
- return substr "\x0d\x0a--$boundary\x0d\x0a", $offset - $len | |
- if ($len + $boundary_len) > $offset; | |
+ return substr "\x0d\x0a--$boundary\x0d\x0a", $offset - $len if ($len + $boundary_len) > $offset; | |
$len += $boundary_len; | |
} | |
} | |
diff --git a/lib/Mojo/Content/Single.pm b/lib/Mojo/Content/Single.pm | |
index a10f36e..ca3d681 100644 | |
--- a/lib/Mojo/Content/Single.pm | |
+++ b/lib/Mojo/Content/Single.pm | |
@@ -29,8 +29,7 @@ sub get_body_chunk { | |
sub new { | |
my $self = shift->SUPER::new(@_); | |
- $self->{read} | |
- = $self->on(read => sub { $_[0]->asset($_[0]->asset->add_chunk($_[1])) }); | |
+ $self->{read} = $self->on(read => sub { $_[0]->asset($_[0]->asset->add_chunk($_[1])) }); | |
return $self; | |
} | |
@@ -41,8 +40,7 @@ sub parse { | |
$self->_parse_until_body(@_); | |
# Parse body | |
- return $self->SUPER::parse | |
- unless $self->auto_upgrade && defined $self->boundary; | |
+ return $self->SUPER::parse unless $self->auto_upgrade && defined $self->boundary; | |
# Content needs to be upgraded to multipart | |
$self->unsubscribe(read => $self->{read}); | |
diff --git a/lib/Mojo/DOM.pm b/lib/Mojo/DOM.pm | |
index 519ff47..9e093a3 100644 | |
--- a/lib/Mojo/DOM.pm | |
+++ b/lib/Mojo/DOM.pm | |
@@ -170,8 +170,7 @@ sub _add { | |
return $self if (my $tree = $self->tree)->[0] eq 'root'; | |
my $parent = $self->_parent; | |
- splice @$parent, _offset($parent, $tree) + $offset, 0, | |
- _link($self->_parse($new), $parent); | |
+ splice @$parent, _offset($parent, $tree) + $offset, 0, _link($self->_parse($new), $parent); | |
return $self; | |
} | |
@@ -186,8 +185,7 @@ sub _all_text { | |
# Detect "pre" tag | |
my $tree = $self->tree; | |
$trim = 1 unless defined $trim; | |
- map { $_->[1] eq 'pre' and $trim = 0 } $self->_ancestors, $tree | |
- if $trim && $tree->[0] ne 'root'; | |
+ map { $_->[1] eq 'pre' and $trim = 0 } $self->_ancestors, $tree if $trim && $tree->[0] ne 'root'; | |
return _text([_nodes($tree)], $recurse, $trim); | |
} | |
@@ -197,8 +195,7 @@ sub _ancestors { | |
return unless my $tree = $self->_parent; | |
my @ancestors; | |
- do { push @ancestors, $tree } | |
- while ($tree->[0] eq 'tag') && ($tree = $tree->[3]); | |
+ do { push @ancestors, $tree } while ($tree->[0] eq 'tag') && ($tree = $tree->[3]); | |
return $root ? $ancestors[-1] : @ancestors[0 .. $#ancestors - 1]; | |
} | |
diff --git a/lib/Mojo/DOM/CSS.pm b/lib/Mojo/DOM/CSS.pm | |
index 88de1dc..cffeb74 100644 | |
--- a/lib/Mojo/DOM/CSS.pm | |
+++ b/lib/Mojo/DOM/CSS.pm | |
@@ -154,8 +154,7 @@ sub _pc { | |
return !_match($args, $current, $current) if $class eq 'not'; | |
# ":checked" | |
- return exists $current->[2]{checked} || exists $current->[2]{selected} | |
- if $class eq 'checked'; | |
+ return exists $current->[2]{checked} || exists $current->[2]{selected} if $class eq 'checked'; | |
# ":first-*" or ":last-*" (rewrite with equation) | |
($class, $args) = $1 ? ("nth-$class", [0, 1]) : ("nth-last-$class", [-1, 1]) | |
@@ -178,8 +177,7 @@ sub _pc { | |
# ":only-*" | |
elsif ($class =~ /^only-(?:child|(of-type))$/) { | |
- $_ ne $current and return undef | |
- for @{_siblings($current, $1 ? $current->[1] : undef)}; | |
+ $_ ne $current and return undef for @{_siblings($current, $1 ? $current->[1] : undef)}; | |
return 1; | |
} | |
@@ -242,8 +240,7 @@ sub _siblings { | |
my ($current, $type) = @_; | |
my $parent = $current->[3]; | |
- my @siblings = grep { $_->[0] eq 'tag' } | |
- @$parent[($parent->[0] eq 'root' ? 1 : 4) .. $#$parent]; | |
+ my @siblings = grep { $_->[0] eq 'tag' } @$parent[($parent->[0] eq 'root' ? 1 : 4) .. $#$parent]; | |
@siblings = grep { $type eq $_->[1] } @siblings if defined $type; | |
return \@siblings; | |
diff --git a/lib/Mojo/DOM/HTML.pm b/lib/Mojo/DOM/HTML.pm | |
index 016989a..111c36f 100644 | |
--- a/lib/Mojo/DOM/HTML.pm | |
+++ b/lib/Mojo/DOM/HTML.pm | |
@@ -65,18 +65,15 @@ map { $END{$_} = 'p' } ( | |
my %TABLE = map { $_ => 1 } qw(colgroup tbody td tfoot th thead tr); | |
# HTML elements with optional end tags and scoping rules | |
-my %CLOSE | |
- = (li => [{li => 1}, {ul => 1, ol => 1}], tr => [{tr => 1}, {table => 1}]); | |
+my %CLOSE = (li => [{li => 1}, {ul => 1, ol => 1}], tr => [{tr => 1}, {table => 1}]); | |
$CLOSE{$_} = [\%TABLE, {table => 1}] for qw(colgroup tbody tfoot thead); | |
$CLOSE{$_} = [{dd => 1, dt => 1}, {dl => 1}] for qw(dd dt); | |
$CLOSE{$_} = [{rp => 1, rt => 1}, {ruby => 1}] for qw(rp rt); | |
$CLOSE{$_} = [{th => 1, td => 1}, {table => 1}] for qw(td th); | |
# HTML elements without end tags | |
-my %EMPTY = map { $_ => 1 } ( | |
- qw(area base br col embed hr img input keygen link menuitem meta param), | |
- qw(source track wbr) | |
-); | |
+my %EMPTY = map { $_ => 1 } | |
+ (qw(area base br col embed hr img input keygen link menuitem meta param), qw(source track wbr)); | |
# HTML elements categorized as phrasing content (and obsolete inline elements) | |
my @PHRASING = ( | |
@@ -106,8 +103,7 @@ sub parse { | |
my $xml = $self->xml; | |
my $current = my $tree = ['root']; | |
while ($html =~ /\G$TOKEN_RE/gcso) { | |
- my ($text, $doctype, $comment, $cdata, $pi, $tag, $runaway) | |
- = ($1, $2, $3, $4, $5, $6, $11); | |
+ my ($text, $doctype, $comment, $cdata, $pi, $tag, $runaway) = ($1, $2, $3, $4, $5, $6, $11); | |
# Text (and runaway "<") | |
$text .= '<' if defined $runaway; | |
@@ -219,8 +215,7 @@ sub _render { | |
return '<?' . $tree->[1] . '?>' if $type eq 'pi'; | |
# Root | |
- return join '', map { _render($_, $xml) } @$tree[1 .. $#$tree] | |
- if $type eq 'root'; | |
+ return join '', map { _render($_, $xml) } @$tree[1 .. $#$tree] if $type eq 'root'; | |
# Start tag | |
my $tag = $tree->[1]; | |
@@ -233,8 +228,7 @@ sub _render { | |
} | |
# No children | |
- return $xml ? "$result />" : $EMPTY{$tag} ? "$result>" : "$result></$tag>" | |
- unless $tree->[4]; | |
+ return $xml ? "$result />" : $EMPTY{$tag} ? "$result>" : "$result></$tag>" unless $tree->[4]; | |
# Children | |
no warnings 'recursion'; | |
diff --git a/lib/Mojo/Date.pm b/lib/Mojo/Date.pm | |
index d52768c..99cc915 100644 | |
--- a/lib/Mojo/Date.pm | |
+++ b/lib/Mojo/Date.pm | |
@@ -48,16 +48,14 @@ sub parse { | |
# Prevent crash | |
my $epoch = eval { timegm $s, $m, $h, $day, $month, $year }; | |
- return $self->epoch( | |
- (defined $epoch && ($epoch += $offset) >= 0) ? $epoch : undef); | |
+ return $self->epoch((defined $epoch && ($epoch += $offset) >= 0) ? $epoch : undef); | |
} | |
sub to_datetime { | |
# RFC 3339 (1994-11-06T08:49:37Z) | |
my ($s, $m, $h, $day, $month, $year) = gmtime(my $epoch = shift->epoch); | |
- my $str = sprintf '%04d-%02d-%02dT%02d:%02d:%02d', $year + 1900, $month + 1, | |
- $day, $h, $m, $s; | |
+ my $str = sprintf '%04d-%02d-%02dT%02d:%02d:%02d', $year + 1900, $month + 1, $day, $h, $m, $s; | |
return $str . ($epoch =~ /(\.\d+)$/ ? "$1Z" : 'Z'); | |
} | |
@@ -65,8 +63,8 @@ sub to_string { | |
# RFC 7231 (Sun, 06 Nov 1994 08:49:37 GMT) | |
my ($s, $m, $h, $mday, $month, $year, $wday) = gmtime shift->epoch; | |
- return sprintf '%s, %02d %s %04d %02d:%02d:%02d GMT', $DAYS[$wday], $mday, | |
- $MONTHS[$month], $year + 1900, $h, $m, $s; | |
+ return sprintf '%s, %02d %s %04d %02d:%02d:%02d GMT', $DAYS[$wday], $mday, $MONTHS[$month], | |
+ $year + 1900, $h, $m, $s; | |
} | |
1; | |
diff --git a/lib/Mojo/Exception.pm b/lib/Mojo/Exception.pm | |
index 4cc6bc4..20d66d7 100644 | |
--- a/lib/Mojo/Exception.pm | |
+++ b/lib/Mojo/Exception.pm | |
@@ -22,8 +22,7 @@ sub to_string { | |
$str .= $_->[0] . ': ' . $_->[1] . "\n" for @{$self->lines_before}; | |
# Line | |
- $str .= ($self->line->[0] . ': ' . $self->line->[1] . "\n") | |
- if $self->line->[0]; | |
+ $str .= ($self->line->[0] . ': ' . $self->line->[1] . "\n") if $self->line->[0]; | |
# After | |
$str .= $_->[0] . ': ' . $_->[1] . "\n" for @{$self->lines_after}; | |
diff --git a/lib/Mojo/Headers.pm b/lib/Mojo/Headers.pm | |
index 50a0134..7c2a8eb 100644 | |
--- a/lib/Mojo/Headers.pm | |
+++ b/lib/Mojo/Headers.pm | |
@@ -77,8 +77,7 @@ sub leftovers { delete shift->{buffer} } | |
sub names { | |
my $self = shift; | |
- return [map { $NORMALCASE{$_} || $self->{normalcase}{$_} || $_ } | |
- keys %{$self->{headers}}]; | |
+ return [map { $NORMALCASE{$_} || $self->{normalcase}{$_} || $_ } keys %{$self->{headers}}]; | |
} | |
sub parse { | |
@@ -128,8 +127,7 @@ sub remove { | |
sub to_hash { | |
my ($self, $multi) = @_; | |
- return {map { $_ => $multi ? $self->{headers}{lc $_} : $self->header($_) } | |
- @{$self->names}}; | |
+ return {map { $_ => $multi ? $self->{headers}{lc $_} : $self->header($_) } @{$self->names}}; | |
} | |
sub to_string { | |
diff --git a/lib/Mojo/IOLoop.pm b/lib/Mojo/IOLoop.pm | |
index d47d165..dec633a 100644 | |
--- a/lib/Mojo/IOLoop.pm | |
+++ b/lib/Mojo/IOLoop.pm | |
@@ -187,8 +187,7 @@ sub _remove { | |
return if $reactor->remove($id); | |
# Acceptor | |
- return $self->_not_accepting->_maybe_accepting | |
- if delete $self->{acceptors}{$id}; | |
+ return $self->_not_accepting->_maybe_accepting if delete $self->{acceptors}{$id}; | |
# Connection | |
return unless delete $self->{connections}{$id}; | |
diff --git a/lib/Mojo/IOLoop/Client.pm b/lib/Mojo/IOLoop/Client.pm | |
index 85b504c..33b5122 100644 | |
--- a/lib/Mojo/IOLoop/Client.pm | |
+++ b/lib/Mojo/IOLoop/Client.pm | |
@@ -8,22 +8,16 @@ use Scalar::Util 'weaken'; | |
use Socket qw(IPPROTO_TCP SOCK_STREAM TCP_NODELAY); | |
# Non-blocking name resolution requires Net::DNS::Native | |
-use constant NDN => $ENV{MOJO_NO_NDN} | |
- ? 0 | |
- : eval 'use Net::DNS::Native 0.15 (); 1'; | |
+use constant NDN => $ENV{MOJO_NO_NDN} ? 0 : eval 'use Net::DNS::Native 0.15 (); 1'; | |
my $NDN = NDN ? Net::DNS::Native->new(pool => 5, extra_thread => 1) : undef; | |
# TLS support requires IO::Socket::SSL | |
-use constant TLS => $ENV{MOJO_NO_TLS} | |
- ? 0 | |
- : eval 'use IO::Socket::SSL 1.94 (); 1'; | |
+use constant TLS => $ENV{MOJO_NO_TLS} ? 0 : eval 'use IO::Socket::SSL 1.94 (); 1'; | |
use constant TLS_READ => TLS ? IO::Socket::SSL::SSL_WANT_READ() : 0; | |
use constant TLS_WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0; | |
# SOCKS support requires IO::Socket::Socks | |
-use constant SOCKS => $ENV{MOJO_NO_SOCKS} | |
- ? 0 | |
- : eval 'use IO::Socket::Socks 0.64 (); 1'; | |
+use constant SOCKS => $ENV{MOJO_NO_SOCKS} ? 0 : eval 'use IO::Socket::Socks 0.64 (); 1'; | |
use constant SOCKS_READ => SOCKS ? IO::Socket::Socks::SOCKS_WANT_READ() : 0; | |
use constant SOCKS_WRITE => SOCKS ? IO::Socket::Socks::SOCKS_WANT_WRITE() : 0; | |
@@ -37,18 +31,17 @@ sub connect { | |
# Timeout | |
weaken $self; | |
my $reactor = $self->reactor; | |
- $self->{timer} = $reactor->timer($args->{timeout} || 10, | |
- sub { $self->emit(error => 'Connect timeout') }); | |
+ $self->{timer} | |
+ = $reactor->timer($args->{timeout} || 10, sub { $self->emit(error => 'Connect timeout') }); | |
# Blocking name resolution | |
$_ && s/[[\]]//g for @$args{qw(address socks_address)}; | |
my $address = $args->{socks_address} || ($args->{address} ||= '127.0.0.1'); | |
- return $reactor->next_tick(sub { $self && $self->_connect($args) }) | |
- if !NDN || $args->{handle}; | |
+ return $reactor->next_tick(sub { $self && $self->_connect($args) }) if !NDN || $args->{handle}; | |
# Non-blocking name resolution | |
- my $handle = $self->{dns} = $NDN->getaddrinfo($address, _port($args), | |
- {protocol => IPPROTO_TCP, socktype => SOCK_STREAM}); | |
+ my $handle = $self->{dns} | |
+ = $NDN->getaddrinfo($address, _port($args), {protocol => IPPROTO_TCP, socktype => SOCK_STREAM}); | |
$reactor->io( | |
$handle => sub { | |
my $reactor = shift; | |
@@ -88,8 +81,7 @@ sub _connect { | |
# Wait for handle to become writable | |
weaken $self; | |
- $self->reactor->io($handle => sub { $self->_ready($args) }) | |
- ->watch($handle, 0, 1); | |
+ $self->reactor->io($handle => sub { $self->_ready($args) })->watch($handle, 0, 1); | |
} | |
sub _port { $_[0]{socks_port} || $_[0]{port} || ($_[0]{tls} ? 443 : 80) } | |
@@ -141,13 +133,10 @@ sub _try_socks { | |
my $handle = $self->{handle}; | |
return $self->_try_tls($args) unless $args->{socks_address}; | |
- return $self->emit( | |
- error => 'IO::Socket::Socks 0.64+ required for SOCKS support') | |
- unless SOCKS; | |
+ return $self->emit(error => 'IO::Socket::Socks 0.64+ required for SOCKS support') unless SOCKS; | |
my %options = (ConnectAddr => $args->{address}, ConnectPort => $args->{port}); | |
- @options{qw(AuthType Username Password)} | |
- = ('userpass', @$args{qw(socks_user socks_pass)}) | |
+ @options{qw(AuthType Username Password)} = ('userpass', @$args{qw(socks_user socks_pass)}) | |
if $args->{socks_user}; | |
my $reactor = $self->reactor; | |
$reactor->remove($handle); | |
@@ -162,18 +151,16 @@ sub _try_tls { | |
my $handle = $self->{handle}; | |
return $self->_cleanup->emit(connect => $handle) unless $args->{tls}; | |
- return $self->emit(error => 'IO::Socket::SSL 1.94+ required for TLS support') | |
- unless TLS; | |
+ return $self->emit(error => 'IO::Socket::SSL 1.94+ required for TLS support') unless TLS; | |
# Upgrade | |
weaken $self; | |
my %options = ( | |
- SSL_ca_file => $args->{tls_ca} | |
- && -T $args->{tls_ca} ? $args->{tls_ca} : undef, | |
- SSL_cert_file => $args->{tls_cert}, | |
- SSL_error_trap => sub { $self->emit(error => $_[1]) }, | |
- SSL_hostname => IO::Socket::SSL->can_client_sni ? $args->{address} : '', | |
- SSL_key_file => $args->{tls_key}, | |
+ SSL_ca_file => $args->{tls_ca} && -T $args->{tls_ca} ? $args->{tls_ca} : undef, | |
+ SSL_cert_file => $args->{tls_cert}, | |
+ SSL_error_trap => sub { $self->emit(error => $_[1]) }, | |
+ SSL_hostname => IO::Socket::SSL->can_client_sni ? $args->{address} : '', | |
+ SSL_key_file => $args->{tls_key}, | |
SSL_startHandshake => 0, | |
SSL_verify_mode => $args->{tls_ca} ? 0x01 : 0x00, | |
SSL_verifycn_name => $args->{address}, | |
diff --git a/lib/Mojo/IOLoop/Delay.pm b/lib/Mojo/IOLoop/Delay.pm | |
index 5bcc09b..9d1fb9f 100644 | |
--- a/lib/Mojo/IOLoop/Delay.pm | |
+++ b/lib/Mojo/IOLoop/Delay.pm | |
@@ -37,8 +37,7 @@ sub _die { $_[0]->has_subscribers('error') ? $_[0]->ioloop->stop : die $_[1] } | |
sub _step { | |
my ($self, $id, $offset, $len) = (shift, shift, shift, shift); | |
- $self->{args}[$id] | |
- = [@_ ? defined $len ? splice @_, $offset, $len : splice @_, $offset : ()]; | |
+ $self->{args}[$id] = [@_ ? defined $len ? splice @_, $offset, $len : splice @_, $offset : ()]; | |
return $self if $self->{fail} || --$self->{pending} || $self->{lock}; | |
local $self->{lock} = 1; | |
my @args = map {@$_} @{delete $self->{args}}; | |
diff --git a/lib/Mojo/IOLoop/Server.pm b/lib/Mojo/IOLoop/Server.pm | |
index 9840b4e..9a60bb7 100644 | |
--- a/lib/Mojo/IOLoop/Server.pm | |
+++ b/lib/Mojo/IOLoop/Server.pm | |
@@ -10,9 +10,7 @@ use Scalar::Util 'weaken'; | |
use Socket qw(IPPROTO_TCP TCP_NODELAY); | |
# TLS support requires IO::Socket::SSL | |
-use constant TLS => $ENV{MOJO_NO_TLS} | |
- ? 0 | |
- : eval 'use IO::Socket::SSL 1.94 (); 1'; | |
+use constant TLS => $ENV{MOJO_NO_TLS} ? 0 : eval 'use IO::Socket::SSL 1.94 (); 1'; | |
use constant TLS_READ => TLS ? IO::Socket::SSL::SSL_WANT_READ() : 0; | |
use constant TLS_WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0; | |
@@ -54,8 +52,7 @@ sub listen { | |
# Reuse file descriptor | |
my $handle; | |
if (defined $fd) { | |
- $handle = IO::Socket::IP->new_from_fd($fd, 'r') | |
- or croak "Can't open file descriptor $fd: $!"; | |
+ $handle = IO::Socket::IP->new_from_fd($fd, 'r') or croak "Can't open file descriptor $fd: $!"; | |
} | |
# New socket | |
@@ -69,8 +66,7 @@ sub listen { | |
); | |
$options{LocalPort} = $port if $port; | |
$options{LocalAddr} =~ s/[\[\]]//g; | |
- $handle = IO::Socket::IP->new(%options) | |
- or croak "Can't create listen socket: $@"; | |
+ $handle = IO::Socket::IP->new(%options) or croak "Can't create listen socket: $@"; | |
$fd = fileno $handle; | |
my $reuse = $self->{reuse} = join ':', $address, $handle->sockport, $fd; | |
$ENV{MOJO_REUSE} .= length $ENV{MOJO_REUSE} ? ",$reuse" : "$reuse"; | |
@@ -92,10 +88,9 @@ sub listen { | |
SSL_honor_cipher_order => 1, | |
SSL_key_file => $args->{tls_key} || $KEY, | |
SSL_startHandshake => 0, | |
- SSL_verify_mode => $args->{tls_verify} // ($args->{tls_ca} ? 0x03 : 0x00) | |
+ SSL_verify_mode => $args->{tls_verify} // ($args->{tls_ca} ? 0x03 : 0x00) | |
}; | |
- $tls->{SSL_ca_file} = $args->{tls_ca} | |
- if $args->{tls_ca} && -T $args->{tls_ca}; | |
+ $tls->{SSL_ca_file} = $args->{tls_ca} if $args->{tls_ca} && -T $args->{tls_ca}; | |
$tls->{SSL_cipher_list} = $args->{tls_ciphers} if $args->{tls_ciphers}; | |
} | |
diff --git a/lib/Mojo/IOLoop/Stream.pm b/lib/Mojo/IOLoop/Stream.pm | |
index 23a6dbd..04eb6aa 100644 | |
--- a/lib/Mojo/IOLoop/Stream.pm | |
+++ b/lib/Mojo/IOLoop/Stream.pm | |
@@ -41,8 +41,7 @@ sub start { | |
# Resume | |
my $reactor = $self->reactor; | |
- return $reactor->watch($self->{handle}, 1, $self->is_writing) | |
- if delete $self->{paused}; | |
+ return $reactor->watch($self->{handle}, 1, $self->is_writing) if delete $self->{paused}; | |
weaken $self; | |
my $cb = sub { pop() ? $self->_write : $self->_read }; | |
@@ -57,8 +56,7 @@ sub steal_handle { | |
sub stop { | |
my $self = shift; | |
- $self->reactor->watch($self->{handle}, 0, $self->is_writing) | |
- unless $self->{paused}++; | |
+ $self->reactor->watch($self->{handle}, 0, $self->is_writing) unless $self->{paused}++; | |
} | |
sub timeout { | |
@@ -70,8 +68,7 @@ sub timeout { | |
$reactor->remove(delete $self->{timer}) if $self->{timer}; | |
return $self unless my $timeout = $self->{timeout} = shift; | |
weaken $self; | |
- $self->{timer} | |
- = $reactor->timer($timeout => sub { $self->emit('timeout')->close }); | |
+ $self->{timer} = $reactor->timer($timeout => sub { $self->emit('timeout')->close }); | |
return $self; | |
} | |
@@ -82,8 +79,7 @@ sub write { | |
$self->{buffer} .= $chunk; | |
if ($cb) { $self->once(drain => $cb) } | |
elsif (!length $self->{buffer}) { return $self } | |
- $self->reactor->watch($self->{handle}, !$self->{paused}, 1) | |
- if $self->{handle}; | |
+ $self->reactor->watch($self->{handle}, !$self->{paused}, 1) if $self->{handle}; | |
return $self; | |
} | |
@@ -94,8 +90,7 @@ sub _read { | |
my $self = shift; | |
my $read = $self->{handle}->sysread(my $buffer, 131072, 0); | |
- return $read == 0 ? $self->close : $self->emit(read => $buffer)->_again | |
- if defined $read; | |
+ return $read == 0 ? $self->close : $self->emit(read => $buffer)->_again if defined $read; | |
# Retry | |
return if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK; | |
diff --git a/lib/Mojo/JSON.pm b/lib/Mojo/JSON.pm | |
index a67d07f..12943a3 100644 | |
--- a/lib/Mojo/JSON.pm | |
+++ b/lib/Mojo/JSON.pm | |
@@ -98,8 +98,7 @@ sub _decode_object { | |
until (m/\G[\x20\x09\x0a\x0d]*\}/gc) { | |
# Quote | |
- /\G[\x20\x09\x0a\x0d]*"/gc | |
- or _throw('Expected string while parsing object'); | |
+ /\G[\x20\x09\x0a\x0d]*"/gc or _throw('Expected string while parsing object'); | |
# Key | |
my $key = _decode_string(); | |
@@ -132,8 +131,7 @@ sub _decode_string { | |
# Invalid character | |
unless (m/\G"/gc) { | |
- _throw('Unexpected character or invalid escape while parsing string') | |
- if /\G[\x00-\x1f\\]/; | |
+ _throw('Unexpected character or invalid escape while parsing string') if /\G[\x00-\x1f\\]/; | |
_throw('Unterminated string'); | |
} | |
@@ -159,8 +157,7 @@ sub _decode_string { | |
if (($ord & 0xf800) == 0xd800) { | |
# High surrogate | |
- ($ord & 0xfc00) == 0xd800 | |
- or pos = $pos + pos($str), _throw('Missing high-surrogate'); | |
+ ($ord & 0xfc00) == 0xd800 or pos = $pos + pos($str), _throw('Missing high-surrogate'); | |
# Low surrogate | |
$str =~ /\G\\u([Dd][C-Fc-f]..)/gc | |
@@ -193,8 +190,7 @@ sub _decode_value { | |
return _decode_array() if /\G\[/gc; | |
# Number | |
- return 0 + $1 | |
- if /\G([-]?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?)/gc; | |
+ return 0 + $1 if /\G([-]?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?)/gc; | |
# True | |
return $TRUE if /\Gtrue/gc; | |
@@ -215,8 +211,7 @@ sub _encode_array { | |
sub _encode_object { | |
my $object = shift; | |
- my @pairs = map { _encode_string($_) . ':' . _encode_value($object->{$_}) } | |
- keys %$object; | |
+ my @pairs = map { _encode_string($_) . ':' . _encode_value($object->{$_}) } keys %$object; | |
return '{' . join(',', @pairs) . '}'; | |
} | |
diff --git a/lib/Mojo/Loader.pm b/lib/Mojo/Loader.pm | |
index 1f41115..15940c3 100644 | |
--- a/lib/Mojo/Loader.pm | |
+++ b/lib/Mojo/Loader.pm | |
@@ -7,8 +7,7 @@ use File::Spec::Functions qw(catdir catfile splitdir); | |
use Mojo::Exception; | |
use Mojo::Util qw(b64_decode class_to_path); | |
-our @EXPORT_OK | |
- = qw(data_section file_is_binary find_modules find_packages load_class); | |
+our @EXPORT_OK = qw(data_section file_is_binary find_modules find_packages load_class); | |
my (%BIN, %CACHE); | |
@@ -78,8 +77,8 @@ sub _all { | |
my $all = $CACHE{$class} = {}; | |
while (@files) { | |
my ($name, $data) = splice @files, 0, 2; | |
- $all->{$name} = $name =~ s/\s*\(\s*base64\s*\)$// | |
- && ++$BIN{$class}{$name} ? b64_decode $data : $data; | |
+ $all->{$name} | |
+ = $name =~ s/\s*\(\s*base64\s*\)$// && ++$BIN{$class}{$name} ? b64_decode $data : $data; | |
} | |
return $all; | |
diff --git a/lib/Mojo/Message.pm b/lib/Mojo/Message.pm | |
index 56d5cd9..ce3cfe1 100644 | |
--- a/lib/Mojo/Message.pm | |
+++ b/lib/Mojo/Message.pm | |
@@ -25,8 +25,7 @@ sub body { | |
return $content->is_multipart ? '' : $content->asset->slurp unless @_; | |
# Set (multipart content needs to be downgraded) | |
- $content = $self->content(Mojo::Content::Single->new)->content | |
- if $content->is_multipart; | |
+ $content = $self->content(Mojo::Content::Single->new)->content if $content->is_multipart; | |
$content->asset(Mojo::Asset::Memory->new->add_chunk(@_)); | |
return $self; | |
@@ -154,8 +153,7 @@ sub parse { | |
# Check start-line size | |
my $len = index $self->{buffer}, "\x0a"; | |
$len = length $self->{buffer} if $len < 0; | |
- return $self->_limit('Maximum start-line size exceeded') | |
- if $len > $self->max_line_size; | |
+ return $self->_limit('Maximum start-line size exceeded') if $len > $self->max_line_size; | |
$self->{state} = 'content' if $self->extract_start_line(\$self->{buffer}); | |
} | |
@@ -167,16 +165,13 @@ sub parse { | |
# Check message size | |
my $max = $self->max_message_size; | |
- return $self->_limit('Maximum message size exceeded') | |
- if $max && $max < $self->{raw_size}; | |
+ return $self->_limit('Maximum message size exceeded') if $max && $max < $self->{raw_size}; | |
# Check header size | |
- return $self->_limit('Maximum header size exceeded') | |
- if $self->headers->is_limit_exceeded; | |
+ return $self->_limit('Maximum header size exceeded') if $self->headers->is_limit_exceeded; | |
# Check buffer size | |
- return $self->_limit('Maximum buffer size exceeded') | |
- if $self->content->is_limit_exceeded; | |
+ return $self->_limit('Maximum buffer size exceeded') if $self->content->is_limit_exceeded; | |
return $self->emit('progress')->content->is_finished ? $self->finish : $self; | |
} | |
diff --git a/lib/Mojo/Message/Request.pm b/lib/Mojo/Message/Request.pm | |
index e23fcf1..c2a09ac 100644 | |
--- a/lib/Mojo/Message/Request.pm | |
+++ b/lib/Mojo/Message/Request.pm | |
@@ -31,8 +31,7 @@ sub cookies { | |
# Parse cookies | |
my $headers = $self->headers; | |
- return [map { @{Mojo::Cookie::Request->parse($_)} } $headers->cookie] | |
- unless @_; | |
+ return [map { @{Mojo::Cookie::Request->parse($_)} } $headers->cookie] unless @_; | |
# Add cookies | |
my @cookies = $headers->cookie || (); | |
@@ -103,8 +102,7 @@ sub param { shift->params->param(@_) } | |
sub params { | |
my $self = shift; | |
- return $self->{params} | |
- ||= $self->body_params->clone->append($self->query_params); | |
+ return $self->{params} ||= $self->body_params->clone->append($self->query_params); | |
} | |
sub parse { | |
@@ -140,8 +138,7 @@ sub parse { | |
# "X-Forwarded-Proto" | |
$base->scheme('https') | |
- if $self->reverse_proxy | |
- && ($headers->header('X-Forwarded-Proto') // '') eq 'https'; | |
+ if $self->reverse_proxy && ($headers->header('X-Forwarded-Proto') // '') eq 'https'; | |
return $self; | |
} | |
diff --git a/lib/Mojo/Message/Response.pm b/lib/Mojo/Message/Response.pm | |
index 8b0f0b0..98038c9 100644 | |
--- a/lib/Mojo/Message/Response.pm | |
+++ b/lib/Mojo/Message/Response.pm | |
@@ -75,8 +75,7 @@ sub cookies { | |
# Parse cookies | |
my $headers = $self->headers; | |
- return [map { @{Mojo::Cookie::Response->parse($_)} } $headers->set_cookie] | |
- unless @_; | |
+ return [map { @{Mojo::Cookie::Response->parse($_)} } $headers->set_cookie] unless @_; | |
# Add cookies | |
for my $cookie (@_) { | |
diff --git a/lib/Mojo/Path.pm b/lib/Mojo/Path.pm | |
index b9d1964..c06c0d6 100644 | |
--- a/lib/Mojo/Path.pm | |
+++ b/lib/Mojo/Path.pm | |
@@ -19,7 +19,7 @@ sub canonicalize { | |
splice @$parts, $i, 1; | |
} | |
elsif ($i < 1 || $parts->[$i] ne '..' || $parts->[$i - 1] eq '..') { $i++ } | |
- else { splice @$parts, --$i, 2 } | |
+ else { splice @$parts, --$i, 2 } | |
} | |
return @$parts ? $self : $self->trailing_slash(undef); | |
@@ -96,8 +96,7 @@ sub to_string { | |
# Build path | |
my @parts = @{$self->parts}; | |
@parts = map { encode $charset, $_ } @parts if $charset; | |
- my $path = join '/', | |
- map { url_escape $_, '^A-Za-z0-9\-._~!$&\'()*+,;=:@' } @parts; | |
+ my $path = join '/', map { url_escape $_, '^A-Za-z0-9\-._~!$&\'()*+,;=:@' } @parts; | |
$path = "/$path" if $self->leading_slash; | |
$path = "$path/" if $self->trailing_slash; | |
return $path; | |
diff --git a/lib/Mojo/Reactor/EV.pm b/lib/Mojo/Reactor/EV.pm | |
index 307fe4d..e640ab0 100644 | |
--- a/lib/Mojo/Reactor/EV.pm | |
+++ b/lib/Mojo/Reactor/EV.pm | |
@@ -45,8 +45,7 @@ sub watch { | |
else { | |
my $cb = sub { | |
my ($w, $revents) = @_; | |
- $self->_try('I/O watcher', $self->{io}{$fd}{cb}, 0) | |
- if EV::READ & $revents; | |
+ $self->_try('I/O watcher', $self->{io}{$fd}{cb}, 0) if EV::READ & $revents; | |
$self->_try('I/O watcher', $self->{io}{$fd}{cb}, 1) | |
if EV::WRITE & $revents && $self->{io}{$fd}; | |
}; | |
diff --git a/lib/Mojo/Reactor/Poll.pm b/lib/Mojo/Reactor/Poll.pm | |
index ef8366b..dc8fe16 100644 | |
--- a/lib/Mojo/Reactor/Poll.pm | |
+++ b/lib/Mojo/Reactor/Poll.pm | |
@@ -130,9 +130,8 @@ sub _next { | |
sub _timer { | |
my ($self, $recurring, $after, $cb) = @_; | |
- my $id = $self->_id; | |
- my $timer = $self->{timers}{$id} | |
- = {cb => $cb, after => $after, time => steady_time + $after}; | |
+ my $id = $self->_id; | |
+ my $timer = $self->{timers}{$id} = {cb => $cb, after => $after, time => steady_time + $after}; | |
$timer->{recurring} = $after if $recurring; | |
return $id; | |
diff --git a/lib/Mojo/Server.pm b/lib/Mojo/Server.pm | |
index f1c3d69..d53bea4 100644 | |
--- a/lib/Mojo/Server.pm | |
+++ b/lib/Mojo/Server.pm | |
@@ -51,8 +51,7 @@ sub load_app { | |
# Try to load application from script into sandbox | |
delete $INC{$path}; | |
- my $app = eval | |
- "package Mojo::Server::Sandbox::@{[md5_sum $path]}; require \$path"; | |
+ my $app = eval "package Mojo::Server::Sandbox::@{[md5_sum $path]}; require \$path"; | |
die qq{Can't load application from file "$path": $@} if $@; | |
die qq{File "$path" did not return an application object.\n} | |
unless blessed $app && $app->isa('Mojo'); | |
diff --git a/lib/Mojo/Server/Daemon.pm b/lib/Mojo/Server/Daemon.pm | |
index 660fecf..37f5d4e 100644 | |
--- a/lib/Mojo/Server/Daemon.pm | |
+++ b/lib/Mojo/Server/Daemon.pm | |
@@ -42,8 +42,7 @@ sub start { | |
my $loop = $self->ioloop; | |
if (my $max = $self->max_clients) { $loop->max_connections($max) } | |
if (my $servers = $self->{servers}) { | |
- push @{$self->acceptors}, $loop->acceptor(delete $servers->{$_}) | |
- for keys %$servers; | |
+ push @{$self->acceptors}, $loop->acceptor(delete $servers->{$_}) for keys %$servers; | |
} | |
# Start listening | |
@@ -151,12 +150,8 @@ sub _listen { | |
my $proto = $url->protocol; | |
croak qq{Invalid listen location "$listen"} unless $proto =~ /^https?$/; | |
- my $query = $url->query; | |
- my $options = { | |
- address => $url->host, | |
- backlog => $self->backlog, | |
- reuse => $query->param('reuse') | |
- }; | |
+ my $query = $url->query; | |
+ my $options = {address => $url->host, backlog => $self->backlog, reuse => $query->param('reuse')}; | |
if (my $port = $url->port) { $options->{port} = $port } | |
$options->{"tls_$_"} = $query->param($_) for qw(ca cert ciphers key); | |
my $verify = $query->param('verify'); | |
@@ -174,11 +169,9 @@ sub _listen { | |
$stream->timeout($self->inactivity_timeout); | |
$stream->on(close => sub { $self && $self->_close($id) }); | |
- $stream->on(error => | |
- sub { $self && $self->app->log->error(pop) && $self->_close($id) }); | |
+ $stream->on(error => sub { $self && $self->app->log->error(pop) && $self->_close($id) }); | |
$stream->on(read => sub { $self->_read($id => pop) }); | |
- $stream->on(timeout => | |
- sub { $self->app->log->debug('Inactivity timeout') if $c->{tx} }); | |
+ $stream->on(timeout => sub { $self->app->log->debug('Inactivity timeout') if $c->{tx} }); | |
} | |
); | |
diff --git a/lib/Mojo/Server/Hypnotoad.pm b/lib/Mojo/Server/Hypnotoad.pm | |
index c173b98..1da77ad 100644 | |
--- a/lib/Mojo/Server/Hypnotoad.pm | |
+++ b/lib/Mojo/Server/Hypnotoad.pm | |
@@ -28,8 +28,7 @@ sub configure { | |
$prefork->max_requests($c->{requests}) if $c->{requests}; | |
defined $c->{$_} and $prefork->$_($c->{$_}) | |
for qw(accepts backlog graceful_timeout heartbeat_interval), | |
- qw(heartbeat_timeout inactivity_timeout listen multi_accept pid_file), | |
- qw(workers); | |
+ qw(heartbeat_timeout inactivity_timeout listen multi_accept pid_file), qw(workers); | |
} | |
sub run { | |
@@ -46,13 +45,12 @@ sub run { | |
$ENV{MOJO_MODE} ||= 'production'; | |
# Clean start (to make sure everything works) | |
- die "Can't exec: $!" | |
- if !$ENV{HYPNOTOAD_REV}++ && !exec $^X, $ENV{HYPNOTOAD_EXE}; | |
+ die "Can't exec: $!" if !$ENV{HYPNOTOAD_REV}++ && !exec $^X, $ENV{HYPNOTOAD_EXE}; | |
# Preload application and configure server | |
my $prefork = $self->prefork->cleanup(0); | |
- $prefork->load_app($app)->config->{hypnotoad}{pid_file} | |
- //= catfile dirname($ENV{HYPNOTOAD_APP}), 'hypnotoad.pid'; | |
+ $prefork->load_app($app)->config->{hypnotoad}{pid_file} //= catfile dirname($ENV{HYPNOTOAD_APP}), | |
+ 'hypnotoad.pid'; | |
$self->configure('hypnotoad'); | |
weaken $self; | |
$prefork->on(wait => sub { $self->_manage }); | |
@@ -121,14 +119,12 @@ sub _manage { | |
} | |
# Timeout | |
- kill 'KILL', $self->{new} | |
- if $self->{upgrade} + $self->upgrade_timeout <= steady_time; | |
+ kill 'KILL', $self->{new} if $self->{upgrade} + $self->upgrade_timeout <= steady_time; | |
} | |
} | |
sub _stop { | |
- _exit('Hypnotoad server not running.') | |
- unless my $pid = shift->prefork->check_pid; | |
+ _exit('Hypnotoad server not running.') unless my $pid = shift->prefork->check_pid; | |
kill 'QUIT', $pid; | |
_exit("Stopping Hypnotoad server $pid gracefully."); | |
} | |
diff --git a/lib/Mojo/Server/Prefork.pm b/lib/Mojo/Server/Prefork.pm | |
index 678bfe8..220f664 100644 | |
--- a/lib/Mojo/Server/Prefork.pm | |
+++ b/lib/Mojo/Server/Prefork.pm | |
@@ -46,8 +46,7 @@ sub ensure_pid_file { | |
# Create PID file | |
$self->app->log->info(qq{Creating process id file "$file"}); | |
- die qq{Can't create process id file "$file": $!} | |
- unless open my $handle, '>', $file; | |
+ die qq{Can't create process id file "$file": $!} unless open my $handle, '>', $file; | |
chmod 0644, $handle; | |
print $handle $$; | |
} | |
@@ -118,20 +117,17 @@ sub _manage { | |
next unless my $w = $self->{pool}{$pid}; | |
# No heartbeat (graceful stop) | |
- $log->error("Worker $pid has no heartbeat, restarting") | |
- and $w->{graceful} = $time | |
+ $log->error("Worker $pid has no heartbeat, restarting") and $w->{graceful} = $time | |
if !$w->{graceful} && ($w->{time} + $interval + $ht <= $time); | |
# Graceful stop with timeout | |
my $graceful = $w->{graceful} ||= $self->{graceful} ? $time : undef; | |
- $log->debug("Stopping worker $pid gracefully") | |
- and (kill 'QUIT', $pid or $self->_stopped($pid)) | |
+ $log->debug("Stopping worker $pid gracefully") and (kill 'QUIT', $pid or $self->_stopped($pid)) | |
if $graceful && !$w->{quit}++; | |
$w->{force} = 1 if $graceful && $graceful + $gt <= $time; | |
# Normal stop | |
- $log->debug("Stopping worker $pid") | |
- and (kill 'KILL', $pid or $self->_stopped($pid)) | |
+ $log->debug("Stopping worker $pid") and (kill 'KILL', $pid or $self->_stopped($pid)) | |
if $w->{force} || ($self->{finished} && !$graceful); | |
} | |
} | |
@@ -141,8 +137,7 @@ sub _spawn { | |
# Manager | |
die "Can't fork: $!" unless defined(my $pid = fork); | |
- return $self->emit(spawn => $pid)->{pool}{$pid} = {time => steady_time} | |
- if $pid; | |
+ return $self->emit(spawn => $pid)->{pool}{$pid} = {time => steady_time} if $pid; | |
# Heartbeat messages | |
my $loop = $self->cleanup(0)->ioloop; | |
@@ -171,8 +166,7 @@ sub _stopped { | |
my $log = $self->app->log; | |
$log->debug("Worker $pid stopped"); | |
- $log->error("Worker $pid stopped too early, shutting down") and $self->_term | |
- unless $w->{healthy}; | |
+ $log->error("Worker $pid stopped too early, shutting down") and $self->_term unless $w->{healthy}; | |
} | |
sub _term { | |
diff --git a/lib/Mojo/Template.pm b/lib/Mojo/Template.pm | |
index feccfb0..4d33c0b 100644 | |
--- a/lib/Mojo/Template.pm | |
+++ b/lib/Mojo/Template.pm | |
@@ -129,8 +129,7 @@ sub parse { | |
my $end = $self->tag_end; | |
my $start = $self->line_start; | |
- my $line_re | |
- = qr/^(\s*)\Q$start\E(?:(\Q$replace\E)|(\Q$cmnt\E)|(\Q$expr\E))?(.*)$/; | |
+ my $line_re = qr/^(\s*)\Q$start\E(?:(\Q$replace\E)|(\Q$cmnt\E)|(\Q$expr\E))?(.*)$/; | |
my $token_re = qr/ | |
( | |
\Q$tag\E(?:\Q$replace\E|\Q$cmnt\E) # Replace | |
diff --git a/lib/Mojo/Transaction.pm b/lib/Mojo/Transaction.pm | |
index e6cd10e..51c1ece 100644 | |
--- a/lib/Mojo/Transaction.pm | |
+++ b/lib/Mojo/Transaction.pm | |
@@ -5,8 +5,7 @@ use Carp 'croak'; | |
use Mojo::Message::Request; | |
use Mojo::Message::Response; | |
-has [ | |
- qw(kept_alive local_address local_port original_remote_address remote_port)]; | |
+has [qw(kept_alive local_address local_port original_remote_address remote_port)]; | |
has req => sub { Mojo::Message::Request->new }; | |
has res => sub { Mojo::Message::Response->new }; | |
diff --git a/lib/Mojo/Transaction/HTTP.pm b/lib/Mojo/Transaction/HTTP.pm | |
index 79af3c4..0a5ee31 100644 | |
--- a/lib/Mojo/Transaction/HTTP.pm | |
+++ b/lib/Mojo/Transaction/HTTP.pm | |
@@ -14,8 +14,7 @@ sub client_read { | |
return unless $res->parse($chunk)->is_finished; | |
# Unexpected 1xx response | |
- return $self->{state} = 'finished' | |
- if !$res->is_status_class(100) || $res->headers->upgrade; | |
+ return $self->{state} = 'finished' if !$res->is_status_class(100) || $res->headers->upgrade; | |
$self->res($res->new)->emit(unexpected => $res); | |
return unless length(my $leftovers = $res->content->leftovers); | |
$self->client_read($leftovers); | |
@@ -126,8 +125,7 @@ sub _start_line { | |
$self->{offset} += $written; | |
# Switch to headers | |
- @$self{qw(http_state write offset)} = ('headers', $msg->header_size, 0) | |
- if $self->{write} <= 0; | |
+ @$self{qw(http_state write offset)} = ('headers', $msg->header_size, 0) if $self->{write} <= 0; | |
return $buffer; | |
} | |
@@ -142,8 +140,7 @@ sub _write { | |
# Nothing written yet | |
$self->{$_} ||= 0 for qw(offset write); | |
my $msg = $server ? $self->res : $self->req; | |
- @$self{qw(http_state write)} = ('start_line', $msg->start_line_size) | |
- unless $self->{http_state}; | |
+ @$self{qw(http_state write)} = ('start_line', $msg->start_line_size) unless $self->{http_state}; | |
# Start-line | |
my $chunk = ''; | |
diff --git a/lib/Mojo/Transaction/WebSocket.pm b/lib/Mojo/Transaction/WebSocket.pm | |
index fd4cf70..04219fc 100644 | |
--- a/lib/Mojo/Transaction/WebSocket.pm | |
+++ b/lib/Mojo/Transaction/WebSocket.pm | |
@@ -10,21 +10,14 @@ use Mojo::Util qw(b64_encode decode dumper encode sha1_bytes xor_encode); | |
use constant DEBUG => $ENV{MOJO_WEBSOCKET_DEBUG} || 0; | |
# Perl with support for quads | |
-use constant MODERN => | |
- (($Config{use64bitint} // '') eq 'define' || $Config{longsize} >= 8); | |
+use constant MODERN => (($Config{use64bitint} // '') eq 'define' || $Config{longsize} >= 8); | |
# Unique value from RFC 6455 | |
use constant GUID => '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; | |
# Opcodes | |
-use constant { | |
- CONTINUATION => 0x0, | |
- TEXT => 0x1, | |
- BINARY => 0x2, | |
- CLOSE => 0x8, | |
- PING => 0x9, | |
- PONG => 0xa | |
-}; | |
+use constant {CONTINUATION => 0x0, TEXT => 0x1, BINARY => 0x2, CLOSE => 0x8, PING => 0x9, | |
+ PONG => 0xa}; | |
has [qw(compressed masked)]; | |
has handshake => sub { Mojo::Transaction::HTTP->new }; | |
@@ -81,16 +74,13 @@ sub build_message { | |
$frame->{text} = encode_json($frame->{json}) if exists $frame->{json}; | |
# Raw text or binary | |
- if (exists $frame->{text}) { $frame = [1, 0, 0, 0, TEXT, $frame->{text}] } | |
- else { $frame = [1, 0, 0, 0, BINARY, $frame->{binary}] } | |
+ if (exists $frame->{text}) { $frame = [1, 0, 0, 0, TEXT, $frame->{text}] } | |
+ else { $frame = [1, 0, 0, 0, BINARY, $frame->{binary}] } | |
# "permessage-deflate" extension | |
return $self->build_frame(@$frame) unless $self->compressed; | |
- my $deflate = $self->{deflate} ||= Compress::Raw::Zlib::Deflate->new( | |
- AppendOutput => 1, | |
- MemLevel => 8, | |
- WindowBits => -15 | |
- ); | |
+ my $deflate = $self->{deflate} | |
+ ||= Compress::Raw::Zlib::Deflate->new(AppendOutput => 1, MemLevel => 8, WindowBits => -15); | |
$deflate->deflate($frame->[5], my $out); | |
$deflate->flush($out, Z_SYNC_FLUSH); | |
@$frame[1, 5] = (1, substr($out, 0, length($out) - 4)); | |
@@ -102,11 +92,10 @@ sub client_challenge { | |
# "permessage-deflate" extension | |
my $headers = $self->res->headers; | |
- $self->compressed(1) | |
- if ($headers->sec_websocket_extensions // '') =~ /permessage-deflate/; | |
+ $self->compressed(1) if ($headers->sec_websocket_extensions // '') =~ /permessage-deflate/; | |
- return _challenge($self->req->headers->sec_websocket_key) eq | |
- $headers->sec_websocket_accept && ++$self->{open}; | |
+ return _challenge($self->req->headers->sec_websocket_key) eq $headers->sec_websocket_accept | |
+ && ++$self->{open}; | |
} | |
sub client_handshake { | |
@@ -241,8 +230,7 @@ sub server_handshake { | |
my $req_headers = $self->req->headers; | |
($req_headers->sec_websocket_protocol // '') =~ /^\s*([^,]+)/ | |
and $res_headers->sec_websocket_protocol($1); | |
- $res_headers->sec_websocket_accept( | |
- _challenge($req_headers->sec_websocket_key)); | |
+ $res_headers->sec_websocket_accept(_challenge($req_headers->sec_websocket_key)); | |
} | |
sub server_open { shift->{open}++ } | |
@@ -273,10 +261,8 @@ sub with_compression { | |
my $self = shift; | |
# "permessage-deflate" extension | |
- $self->compressed(1) | |
- and $self->res->headers->sec_websocket_extensions('permessage-deflate') | |
- if ($self->req->headers->sec_websocket_extensions // '') | |
- =~ /permessage-deflate/; | |
+ $self->compressed(1) and $self->res->headers->sec_websocket_extensions('permessage-deflate') | |
+ if ($self->req->headers->sec_websocket_extensions // '') =~ /permessage-deflate/; | |
} | |
sub _challenge { b64_encode(sha1_bytes(($_[0] || '') . GUID), '') } | |
@@ -294,8 +280,7 @@ sub _message { | |
# Close | |
if ($op == CLOSE) { | |
return $self->finish unless length $frame->[5] >= 2; | |
- return $self->finish(unpack('n', substr($frame->[5], 0, 2, '')), | |
- decode('UTF-8', $frame->[5])); | |
+ return $self->finish(unpack('n', substr($frame->[5], 0, 2, '')), decode('UTF-8', $frame->[5])); | |
} | |
# Append chunk and check message size | |
@@ -310,11 +295,8 @@ sub _message { | |
# "permessage-deflate" extension (handshake and RSV1) | |
my $msg = delete $self->{message}; | |
if ($self->compressed && $frame->[1]) { | |
- my $inflate = $self->{inflate} ||= Compress::Raw::Zlib::Inflate->new( | |
- Bufsize => $max, | |
- LimitOutput => 1, | |
- WindowBits => -15 | |
- ); | |
+ my $inflate = $self->{inflate} | |
+ ||= Compress::Raw::Zlib::Inflate->new(Bufsize => $max, LimitOutput => 1, WindowBits => -15); | |
$inflate->inflate(($msg .= "\x00\x00\xff\xff"), my $out); | |
return $self->finish(1009) if length $msg; | |
$msg = $out; | |
diff --git a/lib/Mojo/URL.pm b/lib/Mojo/URL.pm | |
index 4ee8f9d..6bd9e5e 100644 | |
--- a/lib/Mojo/URL.pm | |
+++ b/lib/Mojo/URL.pm | |
@@ -4,8 +4,7 @@ use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1; | |
use Mojo::Parameters; | |
use Mojo::Path; | |
-use Mojo::Util | |
- qw(decode encode punycode_decode punycode_encode url_escape url_unescape); | |
+use Mojo::Util qw(decode encode punycode_decode punycode_encode url_escape url_unescape); | |
has base => sub { Mojo::URL->new }; | |
has [qw(fragment host port scheme userinfo)]; | |
@@ -53,8 +52,7 @@ sub ihost { | |
my $self = shift; | |
# Decode | |
- return $self->host(join '.', | |
- map { /^xn--(.+)$/ ? punycode_decode($_) : $_ } split /\./, shift) | |
+ return $self->host(join '.', map { /^xn--(.+)$/ ? punycode_decode($_) : $_ } split /\./, shift) | |
if @_; | |
# Check if host needs to be encoded | |
@@ -62,9 +60,7 @@ sub ihost { | |
return lc $host unless $host =~ /[^\x00-\x7f]/; | |
# Encode | |
- return lc join '.', | |
- map { /[^\x00-\x7f]/ ? ('xn--' . punycode_encode $_) : $_ } split /\./, | |
- $host; | |
+ return lc join '.', map { /[^\x00-\x7f]/ ? ('xn--' . punycode_encode $_) : $_ } split /\./, $host; | |
} | |
sub is_abs { !!shift->scheme } | |
@@ -149,8 +145,7 @@ sub to_abs { | |
# Inherit path | |
my $base_path = $base->path; | |
if (!@{$path->parts}) { | |
- $path | |
- = $abs->path($base_path->clone)->path->trailing_slash(0)->canonicalize; | |
+ $path = $abs->path($base_path->clone)->path->trailing_slash(0)->canonicalize; | |
# Query | |
return $abs if length $abs->query->to_string; | |
diff --git a/lib/Mojo/UserAgent.pm b/lib/Mojo/UserAgent.pm | |
index 24f6b7b..a68f91c 100644 | |
--- a/lib/Mojo/UserAgent.pm | |
+++ b/lib/Mojo/UserAgent.pm | |
@@ -89,8 +89,7 @@ sub _connect { | |
my $t = $self->transactor; | |
my ($proto, $host, $port) = $peer ? $t->peer($tx) : $t->endpoint($tx); | |
- my %options | |
- = (address => $host, port => $port, timeout => $self->connect_timeout); | |
+ my %options = (address => $host, port => $port, timeout => $self->connect_timeout); | |
if (my $local = $self->local_address) { $options{local_address} = $local } | |
$options{handle} = $handle if $handle; | |
@@ -105,8 +104,7 @@ sub _connect { | |
} | |
# TLS | |
- map { $options{"tls_$_"} = $self->$_ } qw(ca cert key) | |
- if ($options{tls} = $proto eq 'https'); | |
+ map { $options{"tls_$_"} = $self->$_ } qw(ca cert key) if ($options{tls} = $proto eq 'https'); | |
weaken $self; | |
my $id; | |
@@ -138,8 +136,7 @@ sub _connect_proxy { | |
my ($self, $tx) = @_; | |
# CONNECT failed (connection needs to be kept alive) | |
- $old->res->error({message => 'Proxy connection failed'}) | |
- and return $self->$cb($old) | |
+ $old->res->error({message => 'Proxy connection failed'}) and return $self->$cb($old) | |
if $tx->error || !$tx->res->is_status_class(200) || !$tx->keep_alive; | |
# Start real transaction | |
@@ -163,9 +160,8 @@ sub _connected { | |
my ($self, $id) = @_; | |
# Inactivity timeout | |
- my $c = $self->{connections}{$id}; | |
- my $stream | |
- = $self->_loop($c->{nb})->stream($id)->timeout($self->inactivity_timeout); | |
+ my $c = $self->{connections}{$id}; | |
+ my $stream = $self->_loop($c->{nb})->stream($id)->timeout($self->inactivity_timeout); | |
# Store connection information in transaction | |
my $tx = $c->{tx}->connection($id); | |
@@ -321,8 +317,8 @@ sub _start { | |
my $id = $self->emit(start => $tx)->_connection($nb, $tx, $cb); | |
if (my $timeout = $self->request_timeout) { | |
weaken $self; | |
- $self->{connections}{$id}{timeout} = $self->_loop($nb) | |
- ->timer($timeout => sub { $self->_error($id, 'Request timeout') }); | |
+ $self->{connections}{$id}{timeout} | |
+ = $self->_loop($nb)->timer($timeout => sub { $self->_error($id, 'Request timeout') }); | |
} | |
return $id; | |
diff --git a/lib/Mojo/UserAgent/Server.pm b/lib/Mojo/UserAgent/Server.pm | |
index 08b7312..31a41e2 100644 | |
--- a/lib/Mojo/UserAgent/Server.pm | |
+++ b/lib/Mojo/UserAgent/Server.pm | |
@@ -33,8 +33,7 @@ sub _restart { | |
$self->{proto} = $proto ||= 'http'; | |
# Blocking | |
- my $server = $self->{server} | |
- = Mojo::Server::Daemon->new(ioloop => $self->ioloop, silent => 1); | |
+ my $server = $self->{server} = Mojo::Server::Daemon->new(ioloop => $self->ioloop, silent => 1); | |
weaken $server->app($self->app)->{app}; | |
my $port = $self->{port} ? ":$self->{port}" : ''; | |
$self->{port} = $server->listen(["$proto://127.0.0.1$port"]) | |
diff --git a/lib/Mojo/UserAgent/Transactor.pm b/lib/Mojo/UserAgent/Transactor.pm | |
index 028b96d..ff9dee2 100644 | |
--- a/lib/Mojo/UserAgent/Transactor.pm | |
+++ b/lib/Mojo/UserAgent/Transactor.pm | |
@@ -163,8 +163,7 @@ sub _form { | |
# Multipart | |
if ($multipart) { | |
my $parts = $self->_multipart($options{charset}, $form); | |
- $req->content( | |
- Mojo::Content::MultiPart->new(headers => $headers, parts => $parts)); | |
+ $req->content(Mojo::Content::MultiPart->new(headers => $headers, parts => $parts)); | |
_type($headers, 'multipart/form-data'); | |
return $tx; | |
} | |
@@ -205,8 +204,7 @@ sub _multipart { | |
if (my $file = delete $value->{file}) { | |
$file = Mojo::Asset::File->new(path => $file) unless ref $file; | |
$part->asset($file); | |
- $value->{filename} //= basename $file->path | |
- if $file->isa('Mojo::Asset::File'); | |
+ $value->{filename} //= basename $file->path if $file->isa('Mojo::Asset::File'); | |
} | |
# Memory | |
diff --git a/lib/Mojo/Util.pm b/lib/Mojo/Util.pm | |
index 73dc7e6..e2a6a3c 100644 | |
--- a/lib/Mojo/Util.pm | |
+++ b/lib/Mojo/Util.pm | |
@@ -14,8 +14,7 @@ use Symbol 'delete_package'; | |
use Time::HiRes (); | |
# Check for monotonic clock support | |
-use constant MONOTONIC => | |
- eval { !!Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC()) }; | |
+use constant MONOTONIC => eval { !!Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC()) }; | |
# Punycode bootstring parameters | |
use constant { | |
@@ -37,13 +36,7 @@ while (my $line = <DATA>) { | |
} | |
# Characters that should be escaped in XML | |
-my %XML = ( | |
- '&' => '&', | |
- '<' => '<', | |
- '>' => '>', | |
- '"' => '"', | |
- '\'' => ''' | |
-); | |
+my %XML = ('&' => '&', '<' => '<', '>' => '>', '"' => '"', '\'' => '''); | |
# "Sun, 06 Nov 1994 08:49:37 GMT" and "Sunday, 06-Nov-94 08:49:37 GMT" | |
my $EXPIRES_RE = qr/(\w+\W+\d+\W+\w+\W+\d+\W+\d+:\d+:\d+\W*\w+)/; | |
@@ -94,8 +87,7 @@ sub decamelize { | |
sub decode { | |
my ($encoding, $bytes) = @_; | |
- return undef | |
- unless eval { $bytes = _encoding($encoding)->decode("$bytes", 1); 1 }; | |
+ return undef unless eval { $bytes = _encoding($encoding)->decode("$bytes", 1); 1 }; | |
return $bytes; | |
} | |
@@ -234,8 +226,7 @@ sub sha1_sum { sha1_hex @_ } | |
sub slurp { | |
my $path = shift; | |
open my $file, '<', $path or croak qq{Can't open file "$path": $!}; | |
- defined $file->sysread(my $content, -s $file, 0) | |
- or croak qq{Can't read from file "$path": $!}; | |
+ defined $file->sysread(my $content, -s $file, 0) or croak qq{Can't read from file "$path": $!}; | |
return $content; | |
} | |
@@ -245,8 +236,7 @@ sub split_header { _header(shift, 0) } | |
sub spurt { | |
my ($content, $path) = @_; | |
open my $file, '>', $path or croak qq{Can't open file "$path": $!}; | |
- defined $file->syswrite($content) | |
- or croak qq{Can't write to file "$path": $!}; | |
+ defined $file->syswrite($content) or croak qq{Can't write to file "$path": $!}; | |
return $content; | |
} | |
@@ -257,9 +247,7 @@ sub squish { | |
} | |
sub steady_time () { | |
- MONOTONIC | |
- ? Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC()) | |
- : Time::HiRes::time; | |
+ MONOTONIC ? Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC()) : Time::HiRes::time; | |
} | |
sub tablify { | |
@@ -331,8 +319,7 @@ sub xor_encode { | |
# Encode with variable key length | |
my $len = length $key; | |
my $buffer = my $output = ''; | |
- $output .= $buffer ^ $key | |
- while length($buffer = substr($input, 0, $len, '')) == $len; | |
+ $output .= $buffer ^ $key while length($buffer = substr($input, 0, $len, '')) == $len; | |
return $output .= $buffer ^ substr($key, 0, length $buffer, ''); | |
} | |
diff --git a/lib/Mojolicious.pm b/lib/Mojolicious.pm | |
index b9eecc9..20c0a70 100644 | |
--- a/lib/Mojolicious.pm | |
+++ b/lib/Mojolicious.pm | |
@@ -70,8 +70,7 @@ sub build_controller { | |
# Build default controller | |
my $defaults = $self->defaults; | |
@$stash{keys %$defaults} = values %$defaults; | |
- my $c | |
- = $self->controller_class->new(app => $self, stash => $stash, tx => $tx); | |
+ my $c = $self->controller_class->new(app => $self, stash => $stash, tx => $tx); | |
Scalar::Util::weaken $c->{app}; | |
return $c; | |
@@ -93,8 +92,7 @@ sub dispatch { | |
# Try to find a static file | |
my $tx = $c->tx; | |
- $self->static->dispatch($c) and $plugins->emit_hook(after_static => $c) | |
- unless $tx->res->code; | |
+ $self->static->dispatch($c) and $plugins->emit_hook(after_static => $c) unless $tx->res->code; | |
# Start timer (ignore static files) | |
my $stash = $c->stash; | |
@@ -134,8 +132,7 @@ sub handler { | |
sub helper { | |
my ($self, $name, $cb) = @_; | |
my $r = $self->renderer; | |
- $self->log->debug(qq{Helper "$name" already exists, replacing}) | |
- if exists $r->helpers->{$name}; | |
+ $self->log->debug(qq{Helper "$name" already exists, replacing}) if exists $r->helpers->{$name}; | |
$r->add_helper($name => $cb); | |
} | |
@@ -160,11 +157,9 @@ sub new { | |
# Check if we have a log directory that is writable | |
my $mode = $self->mode; | |
- $self->log->path($home->rel_file("log/$mode.log")) | |
- if -d $home->rel_file('log') && -w _; | |
+ $self->log->path($home->rel_file("log/$mode.log")) if -d $home->rel_file('log') && -w _; | |
- $self->plugin($_) | |
- for qw(HeaderCondition DefaultHelpers TagHelpers EPLRenderer EPRenderer); | |
+ $self->plugin($_) for qw(HeaderCondition DefaultHelpers TagHelpers EPLRenderer EPRenderer); | |
# Exception handling should be first in chain | |
$self->hook(around_dispatch => \&_exception); | |
@@ -192,8 +187,7 @@ sub startup { } | |
sub _exception { | |
my ($next, $c) = @_; | |
- local $SIG{__DIE__} | |
- = sub { ref $_[0] ? CORE::die($_[0]) : Mojo::Exception->throw(@_) }; | |
+ local $SIG{__DIE__} = sub { ref $_[0] ? CORE::die($_[0]) : Mojo::Exception->throw(@_) }; | |
$c->helpers->reply->exception($@) unless eval { $next->(); 1 }; | |
} | |
diff --git a/lib/Mojolicious/Command/daemon.pm b/lib/Mojolicious/Command/daemon.pm | |
index 9384858..e308119 100644 | |
--- a/lib/Mojolicious/Command/daemon.pm | |
+++ b/lib/Mojolicious/Command/daemon.pm | |
@@ -15,9 +15,9 @@ sub run { | |
'b|backlog=i' => sub { $daemon->backlog($_[1]) }, | |
'c|clients=i' => sub { $daemon->max_clients($_[1]) }, | |
'i|inactivity-timeout=i' => sub { $daemon->inactivity_timeout($_[1]) }, | |
- 'l|listen=s' => \my @listen, | |
- 'p|proxy' => sub { $daemon->reverse_proxy(1) }, | |
- 'r|requests=i' => sub { $daemon->max_requests($_[1]) }; | |
+ 'l|listen=s' => \my @listen, | |
+ 'p|proxy' => sub { $daemon->reverse_proxy(1) }, | |
+ 'r|requests=i' => sub { $daemon->max_requests($_[1]) }; | |
$daemon->listen(\@listen) if @listen; | |
$daemon->run; | |
diff --git a/lib/Mojolicious/Command/generate/app.pm b/lib/Mojolicious/Command/generate/app.pm | |
index aa67a91..7c78666 100644 | |
--- a/lib/Mojolicious/Command/generate/app.pm | |
+++ b/lib/Mojolicious/Command/generate/app.pm | |
@@ -37,10 +37,8 @@ EOF | |
$self->render_to_rel_file('static', "$name/public/index.html"); | |
# Templates | |
- $self->render_to_rel_file('layout', | |
- "$name/templates/layouts/default.html.ep"); | |
- $self->render_to_rel_file('welcome', | |
- "$name/templates/example/welcome.html.ep"); | |
+ $self->render_to_rel_file('layout', "$name/templates/layouts/default.html.ep"); | |
+ $self->render_to_rel_file('welcome', "$name/templates/example/welcome.html.ep"); | |
} | |
1; | |
diff --git a/lib/Mojolicious/Command/get.pm b/lib/Mojolicious/Command/get.pm | |
index 4a0a71b..026b4ff 100644 | |
--- a/lib/Mojolicious/Command/get.pm | |
+++ b/lib/Mojolicious/Command/get.pm | |
@@ -43,9 +43,7 @@ sub run { | |
# Verbose | |
weaken $tx; | |
- $tx->res->content->on( | |
- body => sub { warn _header($tx->req), _header($tx->res) }) | |
- if $verbose; | |
+ $tx->res->content->on(body => sub { warn _header($tx->req), _header($tx->res) }) if $verbose; | |
# Stream content (ignore redirects) | |
$tx->res->content->unsubscribe('read')->on( | |
@@ -62,8 +60,7 @@ sub run { | |
STDOUT->autoflush(1); | |
my $tx = $ua->start($ua->build_tx($method, $url, \%headers, $content)); | |
my $err = $tx->error; | |
- warn qq{Problem loading URL "@{[$tx->req->url]}": $err->{message}\n} | |
- if $err && !$err->{code}; | |
+ warn qq{Problem loading URL "@{[$tx->req->url]}": $err->{message}\n} if $err && !$err->{code}; | |
# JSON Pointer | |
return unless defined $selector; | |
@@ -105,8 +102,7 @@ sub _select { | |
return _say($results->map('all_text')->each) if $command eq 'all'; | |
# Attribute | |
- return _say($results->map(attr => $args[0] // '')->each) | |
- if $command eq 'attr'; | |
+ return _say($results->map(attr => $args[0] // '')->each) if $command eq 'attr'; | |
# Unknown | |
die qq{Unknown command "$command".\n}; | |
diff --git a/lib/Mojolicious/Command/prefork.pm b/lib/Mojolicious/Command/prefork.pm | |
index dc1b8f5..9b52d30 100644 | |
--- a/lib/Mojolicious/Command/prefork.pm | |
+++ b/lib/Mojolicious/Command/prefork.pm | |
@@ -4,8 +4,7 @@ use Mojo::Base 'Mojolicious::Command'; | |
use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case); | |
use Mojo::Server::Prefork; | |
-has description => | |
- 'Start application with preforking HTTP and WebSocket server'; | |
+has description => 'Start application with preforking HTTP and WebSocket server'; | |
has usage => sub { shift->extract_usage }; | |
sub run { | |
@@ -20,12 +19,12 @@ sub run { | |
'I|heartbeat-interval=i' => sub { $prefork->heartbeat_interval($_[1]) }, | |
'H|heartbeat-timeout=i' => sub { $prefork->heartbeat_timeout($_[1]) }, | |
'i|inactivity-timeout=i' => sub { $prefork->inactivity_timeout($_[1]) }, | |
- 'l|listen=s' => \my @listen, | |
- 'M|multi-accept=i' => sub { $prefork->multi_accept($_[1]) }, | |
- 'P|pid-file=s' => sub { $prefork->pid_file($_[1]) }, | |
- 'p|proxy' => sub { $prefork->reverse_proxy(1) }, | |
- 'r|requests=i' => sub { $prefork->max_requests($_[1]) }, | |
- 'w|workers=i' => sub { $prefork->workers($_[1]) }; | |
+ 'l|listen=s' => \my @listen, | |
+ 'M|multi-accept=i' => sub { $prefork->multi_accept($_[1]) }, | |
+ 'P|pid-file=s' => sub { $prefork->pid_file($_[1]) }, | |
+ 'p|proxy' => sub { $prefork->reverse_proxy(1) }, | |
+ 'r|requests=i' => sub { $prefork->max_requests($_[1]) }, | |
+ 'w|workers=i' => sub { $prefork->workers($_[1]) }; | |
$prefork->listen(\@listen) if @listen; | |
$prefork->run; | |
diff --git a/lib/Mojolicious/Command/version.pm b/lib/Mojolicious/Command/version.pm | |
index 4fac123..269e30d 100644 | |
--- a/lib/Mojolicious/Command/version.pm | |
+++ b/lib/Mojolicious/Command/version.pm | |
@@ -38,8 +38,7 @@ EOF | |
my $msg = 'This version is up to date, have fun!'; | |
$msg = 'Thanks for testing a development release, you are awesome!' | |
if $latest < $Mojolicious::VERSION; | |
- $msg = "You might want to update your Mojolicious to $latest!" | |
- if $latest > $Mojolicious::VERSION; | |
+ $msg = "You might want to update your Mojolicious to $latest!" if $latest > $Mojolicious::VERSION; | |
say $msg; | |
} | |
diff --git a/lib/Mojolicious/Commands.pm b/lib/Mojolicious/Commands.pm | |
index 486ba1f..8c830da 100644 | |
--- a/lib/Mojolicious/Commands.pm | |
+++ b/lib/Mojolicious/Commands.pm | |
@@ -47,8 +47,7 @@ sub run { | |
$module = _command("${_}::$name", 1) and last for @{$self->namespaces}; | |
# Unknown command | |
- die qq{Unknown command "$name", maybe you need to install it?\n} | |
- unless $module; | |
+ die qq{Unknown command "$name", maybe you need to install it?\n} unless $module; | |
# Run command | |
my $command = $module->new(app => $self->app); | |
@@ -75,8 +74,7 @@ sub start_app { shift; Mojo::Server->new->build_app(shift)->start(@_) } | |
sub _args { | |
return if __PACKAGE__->detect; | |
- my $save | |
- = Getopt::Long::Configure(qw(no_auto_abbrev no_ignore_case pass_through)); | |
+ my $save = Getopt::Long::Configure(qw(no_auto_abbrev no_ignore_case pass_through)); | |
GetOptionsFromArray shift, | |
'h|help' => \$ENV{MOJO_HELP}, | |
'home=s' => \$ENV{MOJO_HOME}, | |
@@ -89,8 +87,7 @@ BEGIN { _args([@ARGV]) } | |
sub _command { | |
my ($module, $fatal) = @_; | |
- return $module->isa('Mojolicious::Command') ? $module : undef | |
- unless my $e = load_class $module; | |
+ return $module->isa('Mojolicious::Command') ? $module : undef unless my $e = load_class $module; | |
$fatal && ref $e ? die $e : return undef; | |
} | |
diff --git a/lib/Mojolicious/Controller.pm b/lib/Mojolicious/Controller.pm | |
index 1640f95..1278ce2 100644 | |
--- a/lib/Mojolicious/Controller.pm | |
+++ b/lib/Mojolicious/Controller.pm | |
@@ -11,8 +11,7 @@ use Scalar::Util (); | |
use Time::HiRes (); | |
has [qw(app tx)]; | |
-has match => | |
- sub { Mojolicious::Routes::Match->new(root => shift->app->routes) }; | |
+has match => sub { Mojolicious::Routes::Match->new(root => shift->app->routes) }; | |
# Reserved stash values | |
my %RESERVED = map { $_ => 1 } ( | |
@@ -123,8 +122,7 @@ sub flash { | |
# Check old flash | |
my $session = $self->session; | |
- return $session->{flash} ? $session->{flash}{$_[0]} : undef | |
- if @_ == 1 && !ref $_[0]; | |
+ return $session->{flash} ? $session->{flash}{$_[0]} : undef if @_ == 1 && !ref $_[0]; | |
# Initialize new flash and merge values | |
my $values = ref $_[0] ? $_[0] : {@_}; | |
@@ -173,13 +171,11 @@ sub render { | |
# Maybe no 404 | |
return defined $output ? Mojo::ByteStream->new($output) : undef if $ts; | |
- return $maybe ? undef : !$self->helpers->reply->not_found | |
- unless defined $output; | |
+ return $maybe ? undef : !$self->helpers->reply->not_found unless defined $output; | |
$plugins->emit_hook(after_render => $self, \$output, $format); | |
my $headers = $self->res->body($output)->headers; | |
- $headers->content_type($app->types->type($format) || 'text/plain') | |
- unless $headers->content_type; | |
+ $headers->content_type($app->types->type($format) || 'text/plain') unless $headers->content_type; | |
return !!$self->rendered($self->stash->{status}); | |
} | |
@@ -203,8 +199,7 @@ sub rendered { | |
# Disable auto rendering and stop timer | |
my $app = $self->render_later->app; | |
if (my $started = delete $stash->{'mojo.started'}) { | |
- my $elapsed = sprintf '%f', | |
- Time::HiRes::tv_interval($started, [Time::HiRes::gettimeofday()]); | |
+ my $elapsed = sprintf '%f', Time::HiRes::tv_interval($started, [Time::HiRes::gettimeofday()]); | |
my $rps = $elapsed == 0 ? '??' : sprintf '%.3f', 1 / $elapsed; | |
my $code = $res->code; | |
my $msg = $res->message || $res->default_message($code); | |
@@ -249,8 +244,7 @@ sub respond_to { | |
sub send { | |
my ($self, $msg, $cb) = @_; | |
my $tx = $self->tx; | |
- Carp::croak 'No WebSocket connection to send message to' | |
- unless $tx->is_websocket; | |
+ Carp::croak 'No WebSocket connection to send message to' unless $tx->is_websocket; | |
$tx->send($msg, $cb ? sub { shift; $self->$cb(@_) } : ()); | |
return $tx->is_established ? $self : $self->rendered(101); | |
} | |
@@ -259,8 +253,7 @@ sub session { | |
my $self = shift; | |
my $stash = $self->stash; | |
- $self->app->sessions->load($self) | |
- unless exists $stash->{'mojo.active_session'}; | |
+ $self->app->sessions->load($self) unless exists $stash->{'mojo.active_session'}; | |
# Hash | |
my $session = $stash->{'mojo.session'} ||= {}; | |
@@ -283,8 +276,7 @@ sub signed_cookie { | |
return $self->every_signed_cookie($name)->[-1] unless defined $value; | |
# Response cookie | |
- my $checksum | |
- = Mojo::Util::hmac_sha1_sum($value, $self->stash->{'mojo.secrets'}[0]); | |
+ my $checksum = Mojo::Util::hmac_sha1_sum($value, $self->stash->{'mojo.secrets'}[0]); | |
return $self->cookie($name, "$value--$checksum", $options); | |
} | |
@@ -318,8 +310,7 @@ sub url_for { | |
else { | |
my $generated = $self->match->path_for($target, @_); | |
$path->parse($generated->{path}) if $generated->{path}; | |
- $base->scheme($base->protocol eq 'https' ? 'wss' : 'ws') | |
- if $generated->{websocket}; | |
+ $base->scheme($base->protocol eq 'https' ? 'wss' : 'ws') if $generated->{websocket}; | |
} | |
# Make path absolute | |
diff --git a/lib/Mojolicious/Lite.pm b/lib/Mojolicious/Lite.pm | |
index 649c491..a159eed 100644 | |
--- a/lib/Mojolicious/Lite.pm | |
+++ b/lib/Mojolicious/Lite.pm | |
@@ -13,8 +13,7 @@ sub import { | |
$ENV{MOJO_EXE} ||= (caller)[1]; | |
# Reuse home directory if possible | |
- local $ENV{MOJO_HOME} = catdir split('/', dirname $ENV{MOJO_EXE}) | |
- unless $ENV{MOJO_HOME}; | |
+ local $ENV{MOJO_HOME} = catdir split('/', dirname $ENV{MOJO_EXE}) unless $ENV{MOJO_HOME}; | |
# Initialize application class | |
my $caller = caller; | |
diff --git a/lib/Mojolicious/Plugin/Charset.pm b/lib/Mojolicious/Plugin/Charset.pm | |
index 65ed0ed..d532884 100644 | |
--- a/lib/Mojolicious/Plugin/Charset.pm | |
+++ b/lib/Mojolicious/Plugin/Charset.pm | |
@@ -7,8 +7,7 @@ sub register { | |
return unless my $c = $conf->{charset}; | |
$app->types->type(html => "text/html;charset=$c"); | |
$app->renderer->encoding($c); | |
- $app->hook(before_dispatch => | |
- sub { shift->req->default_charset($c)->url->query->charset($c) }); | |
+ $app->hook(before_dispatch => sub { shift->req->default_charset($c)->url->query->charset($c) }); | |
} | |
1; | |
diff --git a/lib/Mojolicious/Plugin/DefaultHelpers.pm b/lib/Mojolicious/Plugin/DefaultHelpers.pm | |
index 82b1bc2..bc96781 100644 | |
--- a/lib/Mojolicious/Plugin/DefaultHelpers.pm | |
+++ b/lib/Mojolicious/Plugin/DefaultHelpers.pm | |
@@ -67,8 +67,7 @@ sub _content { | |
sub _csrf_token { | |
my $c = shift; | |
- $c->session->{csrf_token} | |
- ||= sha1_sum $c->app->secrets->[0] . steady_time . rand 999; | |
+ $c->session->{csrf_token} ||= sha1_sum $c->app->secrets->[0] . steady_time . rand 999; | |
} | |
sub _current_route { | |
@@ -91,8 +90,8 @@ sub _development { | |
# Filtered stash snapshot | |
my $stash = $c->stash; | |
- my %snapshot = map { $_ => $stash->{$_} } | |
- grep { !/^mojo\./ and defined $stash->{$_} } keys %$stash; | |
+ my %snapshot | |
+ = map { $_ => $stash->{$_} } grep { !/^mojo\./ and defined $stash->{$_} } keys %$stash; | |
# Render with fallbacks | |
my $mode = $app->mode; | |
diff --git a/lib/Mojolicious/Plugin/EPLRenderer.pm b/lib/Mojolicious/Plugin/EPLRenderer.pm | |
index 1ed7d76..51eca9e 100644 | |
--- a/lib/Mojolicious/Plugin/EPLRenderer.pm | |
+++ b/lib/Mojolicious/Plugin/EPLRenderer.pm | |
@@ -42,8 +42,7 @@ sub _epl { | |
# Try DATA section | |
elsif (my $d = $renderer->get_data_template($options)) { | |
$log->debug(qq{Rendering template "$name" from DATA section}); | |
- $$output | |
- = $mt->name(qq{template "$name" from DATA section})->render($d, $c); | |
+ $$output = $mt->name(qq{template "$name" from DATA section})->render($d, $c); | |
} | |
# No template | |
diff --git a/lib/Mojolicious/Plugin/EPRenderer.pm b/lib/Mojolicious/Plugin/EPRenderer.pm | |
index 2811cc1..8102a55 100644 | |
--- a/lib/Mojolicious/Plugin/EPRenderer.pm | |
+++ b/lib/Mojolicious/Plugin/EPRenderer.pm | |
@@ -30,8 +30,7 @@ sub register { | |
my $mt = $options->{'mojo.template'} = Mojo::Template->new($template); | |
# Helpers (only once) | |
- ++$self->{helpers} and _helpers($ns, $renderer->helpers) | |
- unless $self->{helpers}; | |
+ ++$self->{helpers} and _helpers($ns, $renderer->helpers) unless $self->{helpers}; | |
# Stash values (every time) | |
my $prepend = 'my $self = my $c = shift; my $_S = $c->stash; {'; | |
diff --git a/lib/Mojolicious/Plugin/HeaderCondition.pm b/lib/Mojolicious/Plugin/HeaderCondition.pm | |
index 538fbfb..79e9647 100644 | |
--- a/lib/Mojolicious/Plugin/HeaderCondition.pm | |
+++ b/lib/Mojolicious/Plugin/HeaderCondition.pm | |
@@ -5,16 +5,13 @@ sub register { | |
my ($self, $app) = @_; | |
$app->routes->add_condition(headers => \&_headers); | |
- $app->routes->add_condition( | |
- agent => sub { _headers(@_[0 .. 2], {'User-Agent' => $_[3]}) }); | |
- $app->routes->add_condition( | |
- host => sub { _check($_[1]->req->url->to_abs->host, $_[3]) }); | |
+ $app->routes->add_condition(agent => sub { _headers(@_[0 .. 2], {'User-Agent' => $_[3]}) }); | |
+ $app->routes->add_condition(host => sub { _check($_[1]->req->url->to_abs->host, $_[3]) }); | |
} | |
sub _check { | |
my ($value, $pattern) = @_; | |
- return 1 | |
- if $value && $pattern && ref $pattern eq 'Regexp' && $value =~ $pattern; | |
+ return 1 if $value && $pattern && ref $pattern eq 'Regexp' && $value =~ $pattern; | |
return $value && defined $pattern && $pattern eq $value; | |
} | |
@@ -24,8 +21,7 @@ sub _headers { | |
# All headers need to match | |
my $headers = $c->req->headers; | |
- _check($headers->header($_), $patterns->{$_}) || return undef | |
- for keys %$patterns; | |
+ _check($headers->header($_), $patterns->{$_}) || return undef for keys %$patterns; | |
return 1; | |
} | |
diff --git a/lib/Mojolicious/Plugin/PODRenderer.pm b/lib/Mojolicious/Plugin/PODRenderer.pm | |
index c6c0d68..92ad337 100644 | |
--- a/lib/Mojolicious/Plugin/PODRenderer.pm | |
+++ b/lib/Mojolicious/Plugin/PODRenderer.pm | |
@@ -25,14 +25,12 @@ sub register { | |
} | |
); | |
- $app->helper( | |
- pod_to_html => sub { shift; Mojo::ByteStream->new(_pod_to_html(@_)) }); | |
+ $app->helper(pod_to_html => sub { shift; Mojo::ByteStream->new(_pod_to_html(@_)) }); | |
# Perldoc browser | |
return undef if $conf->{no_perldoc}; | |
my $defaults = {module => 'Mojolicious/Guides', format => 'html'}; | |
- return $app->routes->any( | |
- '/perldoc/:module' => $defaults => [module => qr/[^.]+/] => \&_perldoc); | |
+ return $app->routes->any('/perldoc/:module' => $defaults => [module => qr/[^.]+/] => \&_perldoc); | |
} | |
sub _indentation { | |
@@ -45,8 +43,7 @@ sub _html { | |
# Rewrite links | |
my $dom = Mojo::DOM->new(_pod_to_html($src)); | |
my $perldoc = $c->url_for('/perldoc/'); | |
- $_->{href} =~ s!^https://metacpan\.org/pod/!$perldoc! | |
- and $_->{href} =~ s!::!/!gi | |
+ $_->{href} =~ s!^https://metacpan\.org/pod/!$perldoc! and $_->{href} =~ s!::!/!gi | |
for $dom->find('a[href]')->map('attr')->each; | |
# Rewrite code blocks for syntax highlighting and correct indentation | |
@@ -86,10 +83,8 @@ sub _perldoc { | |
# Find module or redirect to CPAN | |
my $module = join '::', split('/', $c->param('module')); | |
- my $path | |
- = Pod::Simple::Search->new->find($module, map { $_, "$_/pods" } @INC); | |
- return $c->redirect_to("https://metacpan.org/pod/$module") | |
- unless $path && -r $path; | |
+ my $path = Pod::Simple::Search->new->find($module, map { $_, "$_/pods" } @INC); | |
+ return $c->redirect_to("https://metacpan.org/pod/$module") unless $path && -r $path; | |
my $src = slurp $path; | |
$c->respond_to(txt => {data => $src}, html => sub { _html($c, $src) }); | |
diff --git a/lib/Mojolicious/Plugin/TagHelpers.pm b/lib/Mojolicious/Plugin/TagHelpers.pm | |
index 3ee9643..f403a07 100644 | |
--- a/lib/Mojolicious/Plugin/TagHelpers.pm | |
+++ b/lib/Mojolicious/Plugin/TagHelpers.pm | |
@@ -20,14 +20,12 @@ sub register { | |
); | |
$app->helper($_ => __PACKAGE__->can("_$_")) for @helpers; | |
- $app->helper(check_box => | |
- sub { _input(shift, shift, value => shift, @_, type => 'checkbox') }); | |
+ $app->helper(check_box => sub { _input(shift, shift, value => shift, @_, type => 'checkbox') }); | |
$app->helper(file_field => sub { _empty_field('file', @_) }); | |
$app->helper(image => sub { _tag('img', src => shift->url_for(shift), @_) }); | |
- $app->helper(input_tag => sub { _input(@_) }); | |
+ $app->helper(input_tag => sub { _input(@_) }); | |
$app->helper(password_field => sub { _empty_field('password', @_) }); | |
- $app->helper(radio_button => | |
- sub { _input(shift, shift, value => shift, @_, type => 'radio') }); | |
+ $app->helper(radio_button => sub { _input(shift, shift, value => shift, @_, type => 'radio') }); | |
# "t" is just a shortcut for the "tag" helper | |
$app->helper($_ => sub { shift; _tag(@_) }) for qw(t tag); | |
@@ -87,10 +85,9 @@ sub _input { | |
} | |
sub _javascript { | |
- my $c = shift; | |
- my $content | |
- = ref $_[-1] eq 'CODE' ? "//<![CDATA[\n" . pop->() . "\n//]]>" : ''; | |
- my @src = @_ % 2 ? (src => $c->url_for(shift)) : (); | |
+ my $c = shift; | |
+ my $content = ref $_[-1] eq 'CODE' ? "//<![CDATA[\n" . pop->() . "\n//]]>" : ''; | |
+ my @src = @_ % 2 ? (src => $c->url_for(shift)) : (); | |
return _tag('script', @src, @_, sub {$content}); | |
} | |
@@ -151,8 +148,7 @@ sub _select_field { | |
sub _stylesheet { | |
my $c = shift; | |
- my $content | |
- = ref $_[-1] eq 'CODE' ? "/*<![CDATA[*/\n" . pop->() . "\n/*]]>*/" : ''; | |
+ my $content = ref $_[-1] eq 'CODE' ? "/*<![CDATA[*/\n" . pop->() . "\n/*]]>*/" : ''; | |
return _tag('style', @_, sub {$content}) unless @_ % 2; | |
return _tag('link', rel => 'stylesheet', href => $c->url_for(shift), @_); | |
} | |
diff --git a/lib/Mojolicious/Renderer.pm b/lib/Mojolicious/Renderer.pm | |
index e8a35d5..6b21bfe 100644 | |
--- a/lib/Mojolicious/Renderer.pm | |
+++ b/lib/Mojolicious/Renderer.pm | |
@@ -25,8 +25,7 @@ has paths => sub { [] }; | |
# Bundled templates | |
my $HOME = Mojo::Home->new; | |
-$HOME->parse( | |
- $HOME->parse($HOME->mojo_lib_dir)->rel_dir('Mojolicious/templates')); | |
+$HOME->parse($HOME->parse($HOME->mojo_lib_dir)->rel_dir('Mojolicious/templates')); | |
my %TEMPLATES = map { $_ => slurp $HOME->rel_file($_) } @{$HOME->list_files}; | |
sub DESTROY { Mojo::Util::_teardown($_) for @{shift->{namespaces}} } | |
@@ -141,13 +140,11 @@ sub render { | |
@$options{qw(handler template)} = ($stash->{handler}, $extends); | |
$options->{format} = $stash->{format} || $self->default_format; | |
$self->_render_template($c, \$output, $options); | |
- $content->{content} = $output | |
- if $content->{content} !~ /\S/ && $output =~ /\S/; | |
+ $content->{content} = $output if $content->{content} !~ /\S/ && $output =~ /\S/; | |
} | |
# Encoding | |
- $output = encode $options->{encoding}, $output | |
- if !$ts && $options->{encoding} && $output; | |
+ $output = encode $options->{encoding}, $output if !$ts && $options->{encoding} && $output; | |
return $output, $options->{format}; | |
} | |
@@ -158,8 +155,7 @@ sub template_for { | |
# Normal default template | |
my $stash = $c->stash; | |
my ($controller, $action) = @$stash{qw(controller action)}; | |
- return join '/', split('-', decamelize $controller), $action | |
- if $controller && $action; | |
+ return join '/', split('-', decamelize $controller), $action if $controller && $action; | |
# Try the route name if we don't have controller and action | |
return undef unless my $route = $c->match->endpoint; | |
@@ -168,7 +164,7 @@ sub template_for { | |
sub template_handler { | |
my ($self, $options) = @_; | |
- return undef unless my $file = $self->template_name($options); | |
+ return undef unless my $file = $self->template_name($options); | |
return $self->default_handler unless my $handlers = $self->{templates}{$file}; | |
return $handlers->[0]; | |
} | |
@@ -187,8 +183,7 @@ sub template_name { | |
if (defined(my $variant = $options->{variant})) { | |
$variant = "$template+$variant"; | |
my $handlers = $self->{templates}{$variant} // []; | |
- $template = $variant | |
- if @$handlers && !defined $handler || grep { $_ eq $handler } @$handlers; | |
+ $template = $variant if @$handlers && !defined $handler || grep { $_ eq $handler } @$handlers; | |
} | |
return defined $handler ? "$template.$handler" : $template; | |
diff --git a/lib/Mojolicious/Routes.pm b/lib/Mojolicious/Routes.pm | |
index 9844b53..b2c2cc9 100644 | |
--- a/lib/Mojolicious/Routes.pm | |
+++ b/lib/Mojolicious/Routes.pm | |
@@ -33,7 +33,7 @@ sub continue { | |
my $continue; | |
my $last = !$stack->[++$position]; | |
if (my $cb = $field->{cb}) { $continue = $self->_callback($c, $cb, $last) } | |
- else { $continue = $self->_controller($c, $field, $last) } | |
+ else { $continue = $self->_controller($c, $field, $last) } | |
$match->position($position); | |
$self->continue($c) if $last || $continue; | |
} | |
@@ -86,8 +86,7 @@ sub match { | |
# Check routes | |
$match->find($c => {method => $method, path => $path, websocket => $ws}); | |
return unless my $route = $match->endpoint; | |
- $cache->set( | |
- "$method:$path:$ws" => {endpoint => $route, stack => $match->stack}); | |
+ $cache->set("$method:$path:$ws" => {endpoint => $route, stack => $match->stack}); | |
} | |
sub _action { shift->plugins->emit_chain(around_action => @_) } | |
diff --git a/lib/Mojolicious/Routes/Match.pm b/lib/Mojolicious/Routes/Match.pm | |
index fb9800e..e1879f3 100644 | |
--- a/lib/Mojolicious/Routes/Match.pm | |
+++ b/lib/Mojolicious/Routes/Match.pm | |
@@ -26,9 +26,7 @@ sub path_for { | |
%values = (%$captures, format => undef, %values); | |
my $pattern = $route->pattern; | |
$values{format} | |
- //= defined $captures->{format} | |
- ? $captures->{format} | |
- : $pattern->defaults->{format} | |
+ //= defined $captures->{format} ? $captures->{format} : $pattern->defaults->{format} | |
if $pattern->constraints->{format}; | |
my $path = $route->render(\%values); | |
@@ -42,8 +40,7 @@ sub _match { | |
my $path = $options->{path}; | |
my $partial = $r->partial; | |
my $detect = (my $endpoint = $r->is_endpoint) && !$partial; | |
- return undef | |
- unless my $captures = $r->pattern->match_partial(\$path, $detect); | |
+ return undef unless my $captures = $r->pattern->match_partial(\$path, $detect); | |
local $options->{path} = $path; | |
local @{$self->{captures} ||= {}}{keys %$captures} = values %$captures; | |
$captures = $self->{captures}; | |
diff --git a/lib/Mojolicious/Routes/Route.pm b/lib/Mojolicious/Routes/Route.pm | |
index 1a36729..037f96c 100644 | |
--- a/lib/Mojolicious/Routes/Route.pm | |
+++ b/lib/Mojolicious/Routes/Route.pm | |
@@ -44,8 +44,7 @@ sub find { | |
while (my $child = shift @children) { | |
# Custom names have priority | |
- $candidate = $child->has_custom_name ? return $child : $child | |
- if $child->name eq $name; | |
+ $candidate = $child->has_custom_name ? return $child : $child if $child->name eq $name; | |
push @children, @{$child->children}; | |
} | |
@@ -111,8 +110,7 @@ sub remove { | |
sub render { | |
my ($self, $values) = @_; | |
my $path = join '', | |
- map { $_->pattern->render($values, !@{$_->children} && !$_->partial) } | |
- @{$self->_chain}; | |
+ map { $_->pattern->render($values, !@{$_->children} && !$_->partial) } @{$self->_chain}; | |
return $path || '/'; | |
} | |
@@ -216,8 +214,7 @@ sub _generate_route { | |
elsif (ref $arg eq 'HASH') { %defaults = (%defaults, %$arg) } | |
} | |
- my $route | |
- = $self->route($pattern, @constraints)->over(\@conditions)->to(\%defaults); | |
+ my $route = $self->route($pattern, @constraints)->over(\@conditions)->to(\%defaults); | |
$methods eq 'under' ? $route->inline(1) : $route->via($methods); | |
return defined $name ? $route->name($name) : $route; | |
diff --git a/lib/Mojolicious/Sessions.pm b/lib/Mojolicious/Sessions.pm | |
index 7ae5f8b..90c7fbf 100644 | |
--- a/lib/Mojolicious/Sessions.pm | |
+++ b/lib/Mojolicious/Sessions.pm | |
@@ -45,8 +45,7 @@ sub store { | |
# Generate "expires" value from "expiration" if necessary | |
my $expiration = $session->{expiration} // $self->default_expiration; | |
my $default = delete $session->{expires}; | |
- $session->{expires} = $default || time + $expiration | |
- if $expiration || $default; | |
+ $session->{expires} = $default || time + $expiration if $expiration || $default; | |
my $value = b64_encode $self->serialize->($session), ''; | |
$value =~ y/=/-/; | |
diff --git a/lib/Mojolicious/Static.pm b/lib/Mojolicious/Static.pm | |
index 29d3e3b..cbedc32 100644 | |
--- a/lib/Mojolicious/Static.pm | |
+++ b/lib/Mojolicious/Static.pm | |
@@ -98,8 +98,7 @@ sub serve_asset { | |
return $res->code(304) if $self->is_fresh($c, $options); | |
# Range | |
- return $res->content->asset($asset) | |
- unless my $range = $c->req->headers->range; | |
+ return $res->content->asset($asset) unless my $range = $c->req->headers->range; | |
# Not satisfiable | |
return $res->code(416) unless my $size = $asset->size; | |
@@ -124,8 +123,7 @@ sub _get_data_file { | |
$self->_warmup unless $self->{index}; | |
# Find file | |
- return undef | |
- unless defined(my $data = data_section($self->{index}{$rel}, $rel)); | |
+ return undef unless defined(my $data = data_section($self->{index}{$rel}, $rel)); | |
return Mojo::Asset::Memory->new->add_chunk($data); | |
} | |
diff --git a/lib/Mojolicious/Types.pm b/lib/Mojolicious/Types.pm | |
index 8b53d31..7bdb466 100644 | |
--- a/lib/Mojolicious/Types.pm | |
+++ b/lib/Mojolicious/Types.pm | |
@@ -37,8 +37,7 @@ sub detect { | |
# Extract and prioritize MIME types | |
my %types; | |
- /^\s*([^,; ]+)(?:\s*\;\s*q\s*=\s*(\d+(?:\.\d+)?))?\s*$/i | |
- and $types{lc $1} = $2 // 1 | |
+ /^\s*([^,; ]+)(?:\s*\;\s*q\s*=\s*(\d+(?:\.\d+)?))?\s*$/i and $types{lc $1} = $2 // 1 | |
for split ',', $accept // ''; | |
my @detected = sort { $types{$b} <=> $types{$a} } sort keys %types; | |
return [] if !$prioritize && @detected > 1; | |
diff --git a/lib/Mojolicious/Validator/Validation.pm b/lib/Mojolicious/Validator/Validation.pm | |
index 4078261..df5450a 100644 | |
--- a/lib/Mojolicious/Validator/Validation.pm | |
+++ b/lib/Mojolicious/Validator/Validation.pm | |
@@ -37,8 +37,7 @@ sub check { | |
sub csrf_protect { | |
my $self = shift; | |
my $token = $self->input->{csrf_token}; | |
- $self->error(csrf_token => ['csrf_protect']) | |
- unless $token && $token eq ($self->csrf_token // ''); | |
+ $self->error(csrf_token => ['csrf_protect']) unless $token && $token eq ($self->csrf_token // ''); | |
return $self; | |
} | |
@@ -68,8 +67,7 @@ sub optional { | |
my $input = $self->input->{$name}; | |
my @input = ref $input eq 'ARRAY' ? @$input : $input; | |
- $self->output->{$name} = $input | |
- unless grep { !defined($_) || !length($_) } @input; | |
+ $self->output->{$name} = $input unless grep { !defined($_) || !length($_) } @input; | |
return $self->topic($name); | |
} | |
diff --git a/lib/Test/Mojo.pm b/lib/Test/Mojo.pm | |
index 013aa37..66d7cee 100644 | |
--- a/lib/Test/Mojo.pm | |
+++ b/lib/Test/Mojo.pm | |
@@ -50,29 +50,25 @@ sub content_like { | |
sub content_type_is { | |
my ($self, $type, $desc) = @_; | |
$desc ||= "Content-Type: $type"; | |
- return $self->_test('is', $self->tx->res->headers->content_type, $type, | |
- $desc); | |
+ return $self->_test('is', $self->tx->res->headers->content_type, $type, $desc); | |
} | |
sub content_type_isnt { | |
my ($self, $type, $desc) = @_; | |
$desc ||= "not Content-Type: $type"; | |
- return $self->_test('isnt', $self->tx->res->headers->content_type, $type, | |
- $desc); | |
+ return $self->_test('isnt', $self->tx->res->headers->content_type, $type, $desc); | |
} | |
sub content_type_like { | |
my ($self, $regex, $desc) = @_; | |
$desc ||= 'Content-Type is similar'; | |
- return $self->_test('like', $self->tx->res->headers->content_type, $regex, | |
- $desc); | |
+ return $self->_test('like', $self->tx->res->headers->content_type, $regex, $desc); | |
} | |
sub content_type_unlike { | |
my ($self, $regex, $desc) = @_; | |
$desc ||= 'Content-Type is not similar'; | |
- return $self->_test('unlike', $self->tx->res->headers->content_type, $regex, | |
- $desc); | |
+ return $self->_test('unlike', $self->tx->res->headers->content_type, $regex, $desc); | |
} | |
sub content_unlike { | |
@@ -123,43 +119,37 @@ sub head_ok { shift->_build_ok(HEAD => @_) } | |
sub header_is { | |
my ($self, $name, $value, $desc) = @_; | |
$desc ||= "$name: " . ($value // ''); | |
- return $self->_test('is', $self->tx->res->headers->header($name), $value, | |
- $desc); | |
+ return $self->_test('is', $self->tx->res->headers->header($name), $value, $desc); | |
} | |
sub header_isnt { | |
my ($self, $name, $value, $desc) = @_; | |
$desc ||= "not $name: " . ($value // ''); | |
- return $self->_test('isnt', $self->tx->res->headers->header($name), $value, | |
- $desc); | |
+ return $self->_test('isnt', $self->tx->res->headers->header($name), $value, $desc); | |
} | |
sub header_like { | |
my ($self, $name, $regex, $desc) = @_; | |
$desc ||= "$name is similar"; | |
- return $self->_test('like', $self->tx->res->headers->header($name), $regex, | |
- $desc); | |
+ return $self->_test('like', $self->tx->res->headers->header($name), $regex, $desc); | |
} | |
sub header_unlike { | |
my ($self, $name, $regex, $desc) = @_; | |
$desc ||= "$name is not similar"; | |
- return $self->_test('unlike', $self->tx->res->headers->header($name), | |
- $regex, $desc); | |
+ return $self->_test('unlike', $self->tx->res->headers->header($name), $regex, $desc); | |
} | |
sub json_has { | |
my ($self, $p, $desc) = @_; | |
$desc ||= encode 'UTF-8', qq{has value for JSON Pointer "$p"}; | |
- return $self->_test('ok', | |
- !!Mojo::JSON::Pointer->new($self->tx->res->json)->contains($p), $desc); | |
+ return $self->_test('ok', !!Mojo::JSON::Pointer->new($self->tx->res->json)->contains($p), $desc); | |
} | |
sub json_hasnt { | |
my ($self, $p, $desc) = @_; | |
$desc ||= encode 'UTF-8', qq{has no value for JSON Pointer "$p"}; | |
- return $self->_test('ok', | |
- !Mojo::JSON::Pointer->new($self->tx->res->json)->contains($p), $desc); | |
+ return $self->_test('ok', !Mojo::JSON::Pointer->new($self->tx->res->json)->contains($p), $desc); | |
} | |
sub json_is { | |
@@ -371,8 +361,7 @@ sub _request_ok { | |
# Perform request | |
$self->tx($self->ua->start($tx)); | |
my $err = $self->tx->error; | |
- Test::More::diag $err->{message} | |
- if !(my $ok = !$err->{message} || $err->{code}) && $err; | |
+ Test::More::diag $err->{message} if !(my $ok = !$err->{message} || $err->{code}) && $err; | |
my $desc = encode 'UTF-8', "@{[uc $tx->req->method]} $url"; | |
return $self->_test('ok', $ok, $desc); | |
} | |
diff --git a/lib/ojo.pm b/lib/ojo.pm | |
index d1bd0ce..e9ac00b 100644 | |
--- a/lib/ojo.pm | |
+++ b/lib/ojo.pm | |
@@ -45,8 +45,7 @@ sub _request { | |
my $tx = $ua->start($ua->build_tx(@_)); | |
my $err = $tx->error; | |
- warn qq/Problem loading URL "@{[$tx->req->url]}": $err->{message}\n/ | |
- if $err && !$err->{code}; | |
+ warn qq/Problem loading URL "@{[$tx->req->url]}": $err->{message}\n/ if $err && !$err->{code}; | |
return $tx->res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment