Skip to content

Commit

Permalink
s/\$app/$p/g in the import method for perl golf
Browse files Browse the repository at this point in the history
  • Loading branch information
beppu committed Sep 28, 2010
1 parent 00a8dbd commit 858d1a7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/Squatting.pm
Expand Up @@ -20,9 +20,8 @@ require Squatting::View;
# use App ':views'
# use App @PLUGINS
sub import {
my $m = shift;
my $p = (caller)[0];
my $app = $p;
my $m = shift;
my $p = (caller)[0];

if (@_) {
return $m->load_components(grep /::/, @_);
Expand All @@ -37,8 +36,8 @@ sub import {
if (@args && ref($args[-1]) eq 'HASH') {
$input = pop(@args);
}
my $c = ${$app."::Controllers::C"}{$controller};
croak "$controller controller not found in '\%$app\::Controllers::C" unless $c;
my $c = ${$p."::Controllers::C"}{$controller};
croak "$controller controller not found in '\%$p\::Controllers::C" unless $c;
my $arity = @args;
my $path = first { my @m = /\(.*?\)/g; $arity == @m } @{$c->urls};
croak "couldn't find a matching URL path" unless $path;
Expand All @@ -58,10 +57,10 @@ sub import {
};

# ($controller, \@regex_captures) = D($path) # Return controller and captures for a path
*{$app."::D"} = sub {
*{$p."::D"} = sub {
no warnings 'once';
my $url = uri_unescape($_[0]);
my $C = \@{$app.'::Controllers::C'};
my $C = \@{$p.'::Controllers::C'};
my ($c, @regex_captures);
for $c (@$C) {
for (@{$c->urls}) {
Expand All @@ -72,10 +71,10 @@ sub import {
}
}
($Squatting::Controller::r404, []);
} unless exists ${$app."::"}{D};
} unless exists ${$p."::"}{D};

*{$p."::Controllers::C"} = sub {
Squatting::Controller->new(@_, app => $app);
Squatting::Controller->new(@_, app => $p);
};
*{$p."::Views::V"} = sub {
Squatting::View->new(@_);
Expand Down

0 comments on commit 858d1a7

Please sign in to comment.