Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use more marcus-proof AUTOLOAD pattern everywhere
  • Loading branch information
kraih committed Oct 6, 2011
1 parent d1cf14a commit 387f3f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/Mojo/DOM.pm
Expand Up @@ -10,12 +10,15 @@ use Carp 'croak';
use Mojo::Collection;
use Mojo::DOM::CSS;
use Mojo::DOM::HTML;
use Scalar::Util 'blessed';

sub AUTOLOAD {
my $self = shift;

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

# Search children
my $children = $self->children($method);
Expand Down
7 changes: 5 additions & 2 deletions lib/Mojolicious/Routes.pm
@@ -1,13 +1,14 @@
package Mojolicious::Routes;
use Mojo::Base -base;

use Carp 'croak';
use Mojo::Cache;
use Mojo::Exception;
use Mojo::Loader;
use Mojo::Util 'camelize';
use Mojolicious::Routes::Match;
use Mojolicious::Routes::Pattern;
use Scalar::Util 'weaken';
use Scalar::Util qw/blessed weaken/;

has [qw/block inline parent partial namespace/];
has cache => sub { Mojo::Cache->new };
Expand All @@ -24,9 +25,11 @@ sub AUTOLOAD {

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

# Call shortcut
Carp::croak(qq/Can't locate object method "$method" via package "$package"/)
croak qq/Can't locate object method "$method" via package "$package"/
unless my $shortcut = $self->shortcuts->{$method};
return $self->$shortcut(@_);
}
Expand Down

0 comments on commit 387f3f4

Please sign in to comment.