Squatting
view release on metacpan or search on metacpan
lib/Squatting.pm view on Meta::CPAN
# XXX - deprecated | use App ':controllers'
# XXX - deprecated | use App ':views'
# use App @PLUGINS
#
# No longer have to : use base 'Squatting';
# Simply saying : use Squatting;
# will muck with the calling packages @ISA.
sub import {
my $m = shift;
my $p = (caller)[0];
if ($m ne 'Squatting') {
return $m->load_components(grep /::/, @_);
}
push @{$p.'::ISA'}, 'Squatting';
# $url = R('Controller', @args, { cgi => vars }) # Generate URLs with the routing function
*{$p."::Controllers::R"} = *{$p."::Views::R"} = *{$p."::R"} = sub {
my ($controller, @args) = @_;
lib/squatting.pl view on Meta::CPAN
my$app=$self->app;if(defined($vn)){$view=${$app."::Views::V"}{$vn};
}else{$view=${$app."::Views::V"}[0]}
$view->headers=$self->headers;$view->$template($self->v)}
sub redirect{my($self,$l,$s)=@_;$self->headers->{Location}=$l||'/';
$self->status=$s||302}my$not_found=sub{$_[0]->status=404;
$_[0]->env->{REQUEST_PATH}." not found."};
our$r404=Squatting::Controller->new(R404=>[],
get=>$not_found,post=>$not_found,app=>'Squatting');
package Squatting;
use base"Class::C3::Componentised";use List::Util"first";use URI::Escape;
use Carp;our$VERSION='0.60';sub import{my$m=shift;my$p=(caller)[0];my$app=$p;
$app=~s/::Controllers$//;$app=~s/::Views$//;if(UNIVERSAL::isa($app,'Squatting')
){*{$p."::R"}=sub{my($controller,@args)=@_;my$input;if(@args && ref($args[-1])
eq'HASH'){$input=pop(@args)}my$c=${$app."::Controllers::C"}{$controller};
croak"$controller controller not found"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;
while($path=~/\(.*?\)/){
$path=~s{\(.*?\)}{uri_escape(+shift(@args),"^A-Za-z0-9\-_.!~*â()/")}e}
if($input){$path.="?".join('&'=>map{my$k=$_;ref($input->{$_})eq'ARRAY'
?map{"$k=".uri_escape($_)}@{$input->{$_}}:"$_=".uri_escape($input->{$_})
( run in 1.331 second using v1.01-cache-2.11-cpan-a3c8064c92c )