Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use less imports in classes with AUTOLOAD methods
  • Loading branch information
kraih committed Oct 29, 2014
1 parent bbd5f40 commit 6a06ad6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
24 changes: 12 additions & 12 deletions lib/Mojolicious.pm
Expand Up @@ -2,9 +2,9 @@ package Mojolicious;
use Mojo::Base 'Mojo';

# "Fry: Shut up and take my money!"
use Carp 'croak';
use Carp ();
use Mojo::Exception;
use Mojo::Util 'decamelize';
use Mojo::Util;
use Mojolicious::Commands;
use Mojolicious::Controller;
use Mojolicious::Plugins;
Expand All @@ -14,17 +14,17 @@ use Mojolicious::Sessions;
use Mojolicious::Static;
use Mojolicious::Types;
use Mojolicious::Validator;
use Scalar::Util qw(blessed weaken);
use Time::HiRes 'gettimeofday';
use Scalar::Util ();
use Time::HiRes ();

has commands => sub {
my $commands = Mojolicious::Commands->new(app => shift);
weaken $commands->{app};
Scalar::Util::weaken $commands->{app};
return $commands;
};
has controller_class => 'Mojolicious::Controller';
has mode => sub { $ENV{MOJO_MODE} || $ENV{PLACK_ENV} || 'development' };
has moniker => sub { decamelize ref shift };
has moniker => sub { Mojo::Util::decamelize ref shift };
has plugins => sub { Mojolicious::Plugins->new };
has renderer => sub { Mojolicious::Renderer->new };
has routes => sub { Mojolicious::Routes->new };
Expand All @@ -49,11 +49,11 @@ sub AUTOLOAD {
my $self = shift;

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

# Call helper with fresh controller
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->renderer->get_helper($method);
return $self->build_controller->$helper(@_);
}
Expand All @@ -72,7 +72,7 @@ sub build_controller {
@$stash{keys %$defaults} = values %$defaults;
my $c
= $self->controller_class->new(app => $self, stash => $stash, tx => $tx);
weaken $c->{app};
Scalar::Util::weaken $c->{app};

return $c;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ sub dispatch {
my $method = $req->method;
my $path = $req->url->path->to_abs_string;
$self->log->debug(qq{$method "$path".});
$stash->{'mojo.started'} = [gettimeofday];
$stash->{'mojo.started'} = [Time::HiRes::gettimeofday];
}

# Routes
Expand All @@ -129,7 +129,7 @@ sub handler {

# Process with chain
my $c = $self->build_controller(@_);
weaken $c->{tx};
Scalar::Util::weaken $c->{tx};
$self->plugins->emit_chain(around_dispatch => $c);

# Delayed response
Expand Down
12 changes: 6 additions & 6 deletions lib/Mojolicious/Routes/Route.pm
@@ -1,10 +1,10 @@
package Mojolicious::Routes::Route;
use Mojo::Base -base;

use Carp 'croak';
use Carp ();
use Mojo::Util;
use Mojolicious::Routes::Pattern;
use Scalar::Util qw(blessed weaken);
use Scalar::Util ();

has [qw(inline parent partial)];
has 'children' => sub { [] };
Expand All @@ -14,18 +14,18 @@ sub AUTOLOAD {
my $self = shift;

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

# Call shortcut with current route
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 $shortcut = $self->root->shortcuts->{$method};
return $self->$shortcut(@_);
}

sub add_child {
my ($self, $route) = @_;
weaken $route->remove->parent($self)->{parent};
Scalar::Util::weaken $route->remove->parent($self)->{parent};
push @{$self->children}, $route;
return $self;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojolicious/Validator/Validation.pm
@@ -1,8 +1,8 @@
package Mojolicious::Validator::Validation;
use Mojo::Base -base;

use Carp 'croak';
use Scalar::Util 'blessed';
use Carp ();
use Scalar::Util ();

has [qw(csrf_token topic validator)];
has [qw(input output)] => sub { {} };
Expand All @@ -11,10 +11,10 @@ sub AUTOLOAD {
my $self = shift;

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

croak qq{Can't locate object method "$method" via package "$package"}
Carp::croak qq{Can't locate object method "$method" via package "$package"}
unless $self->validator->checks->{$method};
return $self->check($method => @_);
}
Expand Down

0 comments on commit 6a06ad6

Please sign in to comment.