Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 5, 2012
1 parent 149210c commit c6d0c24
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.76 2012-04-06
2.76 2012-04-05
- Improved documentation.

2.75 2012-04-05
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -37,7 +37,7 @@ sub add {

# Add lines
push @{$self->{headers}->{$lcname}},
map { (ref $_ || '') eq 'ARRAY' ? $_ : [$_] } @_;
map { ref $_ eq 'ARRAY' ? $_ : [$_] } @_;

return $self;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Template.pm
Expand Up @@ -34,7 +34,7 @@ sub capture;
*capture = sub { shift->(@_) };
sub escape;
*escape = sub {
return $_[0] if (ref $_[0] || '') eq 'Mojo::ByteStream';
return $_[0] if ref $_[0] eq 'Mojo::ByteStream';
no warnings 'uninitialized';
Mojo::Util::xml_escape "$_[0]";
};
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -220,7 +220,7 @@ sub send {
my ($self, $frame, $cb) = @_;

# Binary or raw text
if ((ref $frame || '') eq 'HASH') {
if (ref $frame eq 'HASH') {
$frame =
exists $frame->{text}
? [1, 0, 0, 0, TEXT, $frame->{text}]
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/URL.pm
Expand Up @@ -143,7 +143,7 @@ sub query {
if (@_ > 1) { $self->{query} = Mojo::Parameters->new(@_) }

# Merge with array
elsif ((ref $_[0] || '') eq 'ARRAY') {
elsif (ref $_[0] eq 'ARRAY') {
my $q = $self->{query} ||= Mojo::Parameters->new;
while (my $name = shift @{$_[0]}) {
my $value = shift @{$_[0]};
Expand All @@ -152,7 +152,7 @@ sub query {
}

# Append hash
elsif ((ref $_[0] || '') eq 'HASH') {
elsif (ref $_[0] eq 'HASH') {
($self->{query} ||= Mojo::Parameters->new)->append(%{$_[0]});
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -33,7 +33,7 @@ has transactor => sub { Mojo::UserAgent::Transactor->new };
for my $name (qw/DELETE GET HEAD OPTIONS PATCH POST PUT/) {
*{__PACKAGE__ . '::' . lc($name)} = sub {
my $self = shift;
my $cb = (ref $_[-1] eq 'CODE') ? pop : undef;
my $cb = ref $_[-1] eq 'CODE' ? pop : undef;
$self->start($self->build_tx($name, @_), $cb);
};
}
Expand Down Expand Up @@ -89,7 +89,7 @@ sub need_proxy {

sub post_form {
my $self = shift;
my $cb = (ref $_[-1] eq 'CODE') ? pop : undef;
my $cb = ref $_[-1] eq 'CODE' ? pop : undef;
$self->start($self->build_form_tx(@_), $cb);
}

Expand Down Expand Up @@ -127,7 +127,7 @@ sub start {

sub websocket {
my $self = shift;
my $cb = (ref $_[-1] eq 'CODE') ? pop : undef;
my $cb = ref $_[-1] eq 'CODE' ? pop : undef;
$self->start($self->build_websocket_tx(@_), $cb);
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -147,25 +147,25 @@ sub param {
my ($self, $name) = (shift, shift);

# List names
my $p = $self->stash->{'mojo.captures'} ||= {};
my $captures = $self->stash->{'mojo.captures'} ||= {};
my $req = $self->req;
unless (defined $name) {
my %seen;
my @keys = grep { !$seen{$_}++ } $req->param;
push @keys, grep { !$seen{$_}++ } map { $_->name } @{$req->uploads};
push @keys, grep { !$RESERVED{$_} && !$seen{$_}++ } keys %$p;
push @keys, grep { !$RESERVED{$_} && !$seen{$_}++ } keys %$captures;
return sort @keys;
}

# Override values
if (@_) {
$p->{$name} = @_ > 1 ? [@_] : $_[0];
$captures->{$name} = @_ > 1 ? [@_] : $_[0];
return $self;
}

# Captured unreserved values
if (!$RESERVED{$name} && defined(my $v = $p->{$name})) {
return (ref $v || '') eq 'ARRAY' ? wantarray ? @$v : $$v[0] : $v;
if (!$RESERVED{$name} && defined(my $value = $captures->{$name})) {
return ref $value eq 'ARRAY' ? wantarray ? @$value : $$value[0] : $value;
}

# Upload
Expand Down Expand Up @@ -555,14 +555,14 @@ sub url_for {

sub write {
my ($self, $chunk, $cb) = @_;
($cb, $chunk) = ($chunk, undef) if (ref $chunk || '') eq 'CODE';
($cb, $chunk) = ($chunk, undef) if ref $chunk eq 'CODE';
$self->res->write($chunk, sub { shift and $self->$cb(@_) if $cb });
return $self->rendered;
}

sub write_chunk {
my ($self, $chunk, $cb) = @_;
($cb, $chunk) = ($chunk, undef) if (ref $chunk || '') eq 'CODE';
($cb, $chunk) = ($chunk, undef) if ref $chunk eq 'CODE';
$self->res->write_chunk($chunk, sub { shift and $self->$cb(@_) if $cb });
return $self->rendered;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/Config.pm
Expand Up @@ -29,7 +29,7 @@ sub parse {
die qq/Couldn't parse config file "$file": $@/
unless my $config = eval "sub app { \$app }; $content";
die qq/Config file "$file" did not return a hash reference.\n/
unless (ref $config || '') eq 'HASH';
unless ref $config eq 'HASH';

return $config;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -84,11 +84,11 @@ sub register {
memorize => sub {
shift;
my $cb = pop;
return '' unless (ref $cb || '') eq 'CODE';
return '' unless ref $cb eq 'CODE';
my $name = shift;
my $args;
if ((ref $name || '') eq 'HASH') { ($args, $name) = ($name, undef) }
else { $args = shift || {} }
if (ref $name eq 'HASH') { ($args, $name) = ($name, undef) }
else { $args = shift || {} }

# Default name
$name ||= join '', map { $_ || '' } (caller(1))[0 .. 3];
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -70,7 +70,7 @@ sub register {

# CDATA
my $cb = sub {''};
if ((ref $_[-1] || '') eq 'CODE') {
if (ref $_[-1] eq 'CODE') {
my $old = pop;
$cb = sub { "//<![CDATA[\n" . $old->() . "\n//]]>" }
}
Expand Down Expand Up @@ -173,7 +173,7 @@ sub register {

# CDATA
my $cb;
if ((ref $_[-1] || '') eq 'CODE') {
if (ref $_[-1] eq 'CODE') {
my $old = pop;
$cb = sub { "/*<![CDATA[*/\n" . $old->() . "\n/*]]>*/" }
}
Expand Down Expand Up @@ -210,7 +210,7 @@ sub register {
my ($c, $name) = (shift, shift);

# Content
my $cb = defined $_[-1] && ref($_[-1]) eq 'CODE' ? pop @_ : sub {''};
my $cb = ref $_[-1] eq 'CODE' ? pop @_ : sub {''};
my $content = @_ % 2 ? shift : undef;

# Make sure content is wrapped
Expand Down Expand Up @@ -261,7 +261,7 @@ sub _tag {
my ($self, $name) = (shift, shift);

# Content
my $cb = defined $_[-1] && ref($_[-1]) eq 'CODE' ? pop @_ : undef;
my $cb = ref $_[-1] eq 'CODE' ? pop @_ : undef;
my $content = @_ % 2 ? pop : undef;

# Start tag
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -184,7 +184,7 @@ sub _compile {
# "Interesting... Oh no wait, the other thing, tedious."
sub _compile_req {
my $req = shift;
return "($req)" if !ref $req || ref $req ne 'ARRAY';
return "($req)" if ref $req ne 'ARRAY';
return '(' . join('|', map {quotemeta} reverse sort @$req) . ')';
}

Expand Down

0 comments on commit c6d0c24

Please sign in to comment.