Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 25, 2013
1 parent 6cb60d3 commit 8b37afc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.83 2013-01-25
3.83 2013-01-26
- Moved bundled static files to mojo directory.
- Improved documentation.
- Improved tests.
Expand Down
7 changes: 3 additions & 4 deletions lib/Mojo/Base.pm
Expand Up @@ -55,13 +55,12 @@ sub attr {
my ($class, $attrs, $default) = @_;
return unless ($class = ref $class || $class) && $attrs;

Carp::croak('Default has to be a code reference or constant value')
Carp::croak 'Default has to be a code reference or constant value'
if ref $default && ref $default ne 'CODE';

# Compile attributes
for my $attr (@{ref $attrs eq 'ARRAY' ? $attrs : [$attrs]}) {
Carp::croak(qq{Attribute "$attr" invalid})
unless $attr =~ /^[a-zA-Z_]\w*$/;
Carp::croak qq{Attribute "$attr" invalid} unless $attr =~ /^[a-zA-Z_]\w*$/;

# Header (check arguments)
my $code = "package $class;\nsub $attr {\n if (\@_ == 1) {\n";
Expand Down Expand Up @@ -89,7 +88,7 @@ sub attr {
# We compile custom attribute code for speed
no strict 'refs';
warn "-- Attribute $attr in $class\n$code\n\n" if $ENV{MOJO_BASE_DEBUG};
Carp::croak("Mojo::Base error: $@") unless eval "$code;1";
Carp::croak "Mojo::Base error: $@" unless eval "$code;1";
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/Mojolicious/Controller.pm
@@ -1,6 +1,7 @@
package Mojolicious::Controller;
use Mojo::Base -base;

# No imports, for security reasons!
use Carp ();
use Mojo::ByteStream;
use Mojo::Cookie::Response;
Expand Down Expand Up @@ -29,11 +30,11 @@ sub AUTOLOAD {

# Method
my ($package, $method) = our $AUTOLOAD =~ /^([\w:]+)::(\w+)$/;
Carp::croak("Undefined subroutine &${package}::$method called")
unless Scalar::Util::blessed($self) && $self->isa(__PACKAGE__);
Carp::croak "Undefined subroutine &${package}::$method called"
unless Scalar::Util::blessed $self && $self->isa(__PACKAGE__);

# Call helper
Carp::croak(qq{Can't locate object method "$method" via package "$package"})
Carp::croak qq{Can't locate object method "$method" via package "$package"}
unless my $helper = $self->app->renderer->helpers->{$method};
return $self->$helper(@_);
}
Expand Down Expand Up @@ -309,7 +310,7 @@ sub respond_to {
sub send {
my ($self, $msg, $cb) = @_;
my $tx = $self->tx;
Carp::croak('No WebSocket connection to send message to')
Carp::croak 'No WebSocket connection to send message to'
unless $tx->is_websocket;
$tx->send($msg => sub { shift and $self->$cb(@_) if $cb });
return $self->rendered(101);
Expand Down Expand Up @@ -394,8 +395,7 @@ sub url_for {
my $target = shift // '';

# Absolute URL
return $target
if Scalar::Util::blessed($target) && $target->isa('Mojo::URL');
return $target if Scalar::Util::blessed $target && $target->isa('Mojo::URL');
return Mojo::URL->new($target) if $target =~ m!^\w+://!;

# Base
Expand Down

0 comments on commit 8b37afc

Please sign in to comment.