--- Webpacus/lib/Webpacus.pm 2005/12/14 23:04:13 244 +++ Webpacus/lib/Webpacus.pm 2006/01/21 23:27:16 378 @@ -15,10 +15,11 @@ FillInForm SubRequest Static::Simple + StackTrace /; # FormValidator -our $VERSION = '0.18-dev'; +our $VERSION = '0.32-dev'; # # Configure the application @@ -56,6 +57,31 @@ sub default : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'index.tt'; + + my $site_name = shift @{ $c->req->args }; + + $c->log->debug("trying site name: $site_name"); + + if (my $sites_root = $c->config->{sites_root}) { + my $site_path = $c->path_to('root', $sites_root, $site_name); + + if (-e $site_path) { + $c->stash->{site} = $site_name; + if (my $action = join('/', @{ $c->req->args })) { + $c->log->debug( "site: $site_name, action: $action" ); + # TODO can I really change base like this? + $c->stash->{base} = "/$site_name/" . $c->stash->{base} + unless ($c->stash->{base} =~ m#^/\Q$site_name\E/#); + $c->internal_redirect( $action, $c->stash, @{ $c->req->args } ); + } else { + $c->log->debug( "site: $site_name" ); + } + } else { + $c->log->debug( "can't find site $site_name in $site_path"); + } + } else { + $c->log->warn("sites_root not defined in config"); + } } =item end @@ -70,17 +96,48 @@ if ($c->response->body) { $c->log->debug("at end body exists, we won't touch it!"); } else { - $c->fillform( $c->req->parameters ); + $c->fillform( $c->req->params ); - # Forward to View unless response body is already defined - $c->forward('View::TT'); + if (my $site_name = $c->stash->{site}) { + my $template_path = $c->path_to('root', $c->config->{sites_root}, $site_name, $c->stash->{template}); + if (-e $template_path) { + $c->stash->{template} = $c->config->{sites_root} . "/$site_name/" . $c->stash->{template}; + } else { + $c->log->warn("can't find $template_path, fallback to default"); + } + $c->log->debug("using template ", $c->stash->{template}); + } - $c->response->{body} =~ s#\Qnew Ajax.Autocompleter(\E#new Ajax.Suggest(#gs; -# $c->log->debug( $c->response->body ); + # Forward to View unless response body is already defined + $c->forward('View::TT'); + + $c->response->{body} =~ s#\Qnew Ajax.Autocompleter(\E#new WebPAC.Suggest(#gs; + $c->response->{body} =~ s#\Qnew Ajax.Updater(\E#new WebPAC.Updater(#gs; + +# $c->log->debug( $c->response->body ); } } +=item internal_redirect + + $c->internal_redirect( $action, @args ); + +=cut + +sub internal_redirect { + my ( $c, $action, @args ) = @_; + + unless ( defined $action ) { + $action = $c->action->namespace; + } else { + $action = join '/', $c->action->namespace, $action unless $action =~ m!^/!; + } + $c->res->body( $c->subreq( $action, @args ) ); + return; +} + + =back =head1 AUTHOR