--- Webpacus/lib/Webpacus.pm 2005/11/22 12:57:41 98 +++ Webpacus/lib/Webpacus.pm 2006/01/08 13:58:19 358 @@ -10,15 +10,16 @@ # Static::Simple: will serve static files from the applications root directory # use Catalyst qw/-Debug - Static::Simple Prototype - Unicode::Encoding Config::YAML + FillInForm + SubRequest + Static::Simple + StackTrace /; # FormValidator -# FillInForm -our $VERSION = '0.01'; +our $VERSION = '0.31-dev'; # # Configure the application @@ -56,6 +57,26 @@ sub default : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'index.tt'; + + my $site_name = shift @{ $c->req->args }; + + 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 = shift @{ $c->req->args }) { + $c->log->debug( "site: $site_name, action: $action" ); + $c->internal_redirect( $action, $c->stash ); + } 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 @@ -65,19 +86,58 @@ sub end : Private { my ( $self, $c ) = @_; - # Forward to View unless response body is already defined - $c->forward('View::TT') unless $c->response->body; + $c->stash->{webpacus_version} = $VERSION; + + if ($c->response->body) { + $c->log->debug("at end body exists, we won't touch it!"); + } else { + $c->fillform( $c->req->params ); + + 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}); + } + + # 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 ); +# $c->log->debug( $c->response->body ); + } -# $c->fillform; # defaults to $c->req->parameters } +=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 -Dobrica Pavlinusic,,, +Dobrica Pavlinusic, C<< >> =head1 LICENSE