Skip to content

Commit

Permalink
removed a few easter eggs
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 16, 2012
1 parent e8bcccb commit e23f582
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 33 deletions.
12 changes: 3 additions & 9 deletions lib/Mojolicious/Lite.pm
Expand Up @@ -25,8 +25,7 @@ sub import {
my $app = $class->new;

# Initialize routes
my $routes = $app->routes;
$routes->namespace('');
my $routes = $app->routes->namespace('');

# Default static and template class
$app->static->classes->[0] = $caller;
Expand All @@ -43,21 +42,16 @@ sub import {
*{"${caller}::group"} = sub (&) {
my $old = $root;
$_[0]->($root = $routes);
$routes = $root;
$root = $old;
($routes, $root) = ($root, $old);
};
*{"${caller}::helper"} = sub { $app->helper(@_) };
*{"${caller}::hook"} = sub { $app->hook(@_) };
*{"${caller}::plugin"} = sub { $app->plugin(@_) };
*{"${caller}::under"} = *{"${caller}::ladder"} =
sub { $routes = $root->under(@_) };
*{"${caller}::under"} = sub { $routes = $root->under(@_) };

# We are most likely the app in a lite environment
$ENV{MOJO_APP} ||= $app;

# Shagadelic!
*{"${caller}::shagadelic"} = sub { $app->start(@_) };

# Lite apps are strict!
Mojo::Base->import(-strict);
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -96,10 +96,7 @@ sub dispatch {
sub hide { push @{shift->hidden}, @_ }

sub route {
my $self = shift;
my $route = Mojolicious::Routes::Route->new(@_);
$self->add_child($route);
return $route;
shift->add_child(Mojolicious::Routes::Route->new(@_))->children->[-1];
}

sub _callback {
Expand Down
18 changes: 6 additions & 12 deletions lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -96,7 +96,7 @@ sub shape_match {
my $req = $self->reqs->{format};
return $result if !$detect || defined $req && !$req;
if ($$pathref =~ s|^/?$format||) { $result->{format} = $1 }
elsif ($req) { return if !$result->{format} }
elsif ($req) { return unless $result->{format} }

return $result;
}
Expand All @@ -105,9 +105,8 @@ sub _compile {
my $self = shift;

# Compile tree to regex
my $reqs = $self->reqs;
my $block = '';
my $regex = '';
my $block = my $regex = '';
my $reqs = $self->reqs;
my $optional = 1;
my $defaults = $self->defaults;
for my $token (reverse @{$self->tree}) {
Expand Down Expand Up @@ -161,10 +160,7 @@ sub _compile {
$regex = "$block$regex" if $block;

# Compile
$regex = qr/^$regex/s;
$self->regex($regex);

return $regex;
return $self->regex(qr/^$regex/s)->regex;
}

sub _compile_format {
Expand Down Expand Up @@ -222,15 +218,13 @@ sub _tokenize {

# Relaxed start (needs to be quoted)
elsif ($quoted && $char eq $relaxed_start && $state eq 'symbol') {
$state = 'relaxed';
$tree[-1]->[0] = 'relaxed';
$tree[-1]->[0] = $state = 'relaxed';
}

# Wildcard start (upgrade when quoted)
elsif ($char eq $wildcard_start) {
push @tree, ['symbol', ''] unless $quoted;
$state = 'wildcard';
$tree[-1]->[0] = 'wildcard';
$tree[-1]->[0] = $state = 'wildcard';
}

# Quote end
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -40,7 +40,7 @@ sub add_child {
# Inherit format detection from parents
$route->pattern->reqs->{format} //= 0
if defined first { defined $_ && !$_ }
map { $_->pattern->reqs->{format} } @{$self->_parents};
map { $_->pattern->reqs->{format} } @{$self->_stack};

return $self;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ sub render {
return $parent ? $parent->render($path, $values) : $path;
}

sub root { shift->_parents->[-1] }
sub root { shift->_stack->[-1] }

sub route {
my $self = shift;
Expand Down Expand Up @@ -272,7 +272,7 @@ sub _generate_route {
->via($methods)->to(\%defaults)->name($name);
}

sub _parents {
sub _stack {
my @parents = (shift);
while (my $parent = $parents[-1]->parent) { push @parents, $parent }
return \@parents;
Expand Down
3 changes: 1 addition & 2 deletions lib/ojo.pm
Expand Up @@ -39,9 +39,8 @@ sub import {
$UA->app(*{"${caller}::app"}->());

# Functions
*{"${caller}::Oo"} = *{"${caller}::b"} = \&b;
*{"${caller}::b"} = \&b;
*{"${caller}::c"} = \&c;
*{"${caller}::oO"} = sub { _request(@_) };
*{"${caller}::a"} =
sub { *{"${caller}::any"}->(@_) and return *{"${caller}::app"}->() };
*{"${caller}::d"} = sub { _request(DELETE => @_) };
Expand Down
4 changes: 1 addition & 3 deletions t/mojo/user_agent_online.t
Expand Up @@ -11,7 +11,7 @@ use Test::More;

plan skip_all => 'set TEST_ONLINE to enable this test (developer only!)'
unless $ENV{TEST_ONLINE};
plan tests => 108;
plan tests => 106;

# "So then I said to the cop, "No, you're driving under the influence...
# of being a jerk"."
Expand Down Expand Up @@ -148,8 +148,6 @@ is h('mojolicio.us')->code, 200, 'right status';
is p('mojolicio.us/lalalala')->code, 404, 'right status';
is g('http://mojolicio.us')->code, 200, 'right status';
is p('http://mojolicio.us')->code, 404, 'right status';
is oO('http://mojolicio.us')->code, 200, 'right status';
is oO(POST => 'http://mojolicio.us')->code, 404, 'right status';
my $res = f('search.cpan.org/search' => {query => 'mojolicious'});
like $res->body, qr/Mojolicious/, 'right content';
is $res->code, 200, 'right status';
Expand Down

0 comments on commit e23f582

Please sign in to comment.