Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 20, 2012
1 parent 40d631f commit 1c6c2fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -50,7 +50,7 @@ sub clone {
}

sub from_hash {
my ($self, $hash) = (shift, shift);
my ($self, $hash) = @_;

# Empty hash deletes all headers
delete $self->{headers} if keys %{$hash} == 0;
Expand Down
11 changes: 7 additions & 4 deletions lib/Mojo/Log.pm
Expand Up @@ -6,10 +6,9 @@ use Fcntl ':flock';

# "Would you kindly shut your noise-hole?"
has handle => sub {
my $self = shift;

# File
if (my $path = $self->path) {
if (my $path = shift->path) {
croak qq{Can't open log file "$path": $!}
unless open my $file, '>>:utf8', $path;
return $file;
Expand Down Expand Up @@ -63,11 +62,15 @@ sub log { shift->emit('message', lc(shift), @_) }
sub warn { shift->log(warn => @_) }

sub _message {
my ($self, $level) = (shift, shift);
my ($self, $level, @lines) = @_;

# Check level
return unless $self->is_level($level) && (my $handle = $self->handle);

# Format lines and write to handle
flock $handle, LOCK_EX;
croak "Can't write to log: $!"
unless defined $handle->syswrite($self->format($level, @_));
unless defined $handle->syswrite($self->format($level, @lines));
flock $handle, LOCK_UN;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -167,11 +167,11 @@ sub handler {
}

sub helper {
my ($self, $name) = (shift, shift);
my ($self, $name, $cb) = @_;
my $r = $self->renderer;
$self->log->debug(qq{Helper "$name" already exists, replacing.})
if exists $r->helpers->{$name};
$r->add_helper($name => @_);
$r->add_helper($name => $cb);
}

# "He knows when you are sleeping.
Expand Down

0 comments on commit 1c6c2fd

Please sign in to comment.