/[webpac2]/Webpacus/lib/Webpacus.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Webpacus/lib/Webpacus.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 187 by dpavlin, Sun Nov 27 22:10:36 2005 UTC revision 387 by dpavlin, Sun Jan 22 12:06:49 2006 UTC
# Line 10  use warnings; Line 10  use warnings;
10  # Static::Simple: will serve static files from the applications root directory  # Static::Simple: will serve static files from the applications root directory
11  #  #
12  use Catalyst qw/-Debug  use Catalyst qw/-Debug
         Static::Simple  
13          Prototype          Prototype
14          Config::YAML          Config::YAML
15          FillInForm          FillInForm
16            SubRequest
17            Static::Simple
18            StackTrace
19  /;  /;
20  #       FormValidator  #       FormValidator
21    
22  our $VERSION = '0.07-dev';  our $VERSION = '0.32-dev';
23    
24  #  #
25  # Configure the application  # Configure the application
# Line 55  Catalyst based application. Line 57  Catalyst based application.
57  sub default : Private {  sub default : Private {
58      my ( $self, $c ) = @_;      my ( $self, $c ) = @_;
59      $c->stash->{template} = 'index.tt';      $c->stash->{template} = 'index.tt';
60    
61            my $site_name = shift @{ $c->req->args };
62    
63            $c->log->debug("trying site name: $site_name");
64    
65            if (my $sites_root = $c->config->{sites_root}) {
66                    my $site_path = $c->path_to('root', $sites_root, $site_name);
67    
68                    if (-e $site_path) {
69                            $c->stash->{site} = $site_name;
70                            if (my $action = join('/', @{ $c->req->args })) {
71                                    $c->log->debug( "site: $site_name, action: $action" );
72                                    # TODO can I really change base like this?
73                                    $c->stash->{base} = "/$site_name/" . $c->stash->{base}
74                                            unless ($c->stash->{base} =~ m#^/\Q$site_name\E/#);
75                                    $c->internal_redirect( $action, $c->stash, @{ $c->req->args } );
76                            } else {
77                                    $c->log->debug( "site: $site_name" );
78                            }
79                    } else {
80                            $c->log->debug( "can't find site $site_name in $site_path");
81                    }
82            } else {
83                    $c->log->warn("sites_root not defined in config");
84            }
85  }  }
86    
87  =item end  =item end
# Line 66  sub end : Private { Line 93  sub end : Private {
93    
94      $c->stash->{webpacus_version} = $VERSION;      $c->stash->{webpacus_version} = $VERSION;
95    
96      # Forward to View unless response body is already defined      if ($c->response->body) {
97      $c->forward('View::TT') unless $c->response->body;          $c->log->debug("at end body exists, we won't touch it!");
98        } else {
99                    if (my $site_name = $c->stash->{site}) {
100                            my $template_path = $c->path_to('root', $c->config->{sites_root}, $site_name, $c->stash->{template});
101                            if (-e $template_path) {
102                                    $c->stash->{template} = $c->config->{sites_root} . "/$site_name/" . $c->stash->{template};
103                            } else {
104                                    $c->log->warn("can't find $template_path, fallback to default");
105                            }
106                            $c->log->debug("using template ", $c->stash->{template});
107                    }
108    
109                    # Forward to View unless response body is already defined
110                    $c->forward('View::TT');
111    
112      $c->fillform; # defaults to $c->req->parameters                  $c->fillform( $c->req->params );
113    
114  #    $c->log->debug( $c->response->body );                  $c->response->{body} =~ s#\Qnew Ajax.Autocompleter(\E#new WebPAC.Suggest(#gs;
115                    $c->response->{body} =~ s#\Qnew Ajax.Updater(\E#new WebPAC.Updater(#gs;
116    
117    #               $c->log->debug( $c->response->body );
118        }
119    
120  }  }
121    
122    =item internal_redirect
123    
124      $c->internal_redirect( $action, @args );
125    
126    =cut
127    
128    sub internal_redirect {
129            my ( $c, $action, @args ) = @_;
130    
131            unless ( defined $action ) {
132                    $action = $c->action->namespace;
133            } else {
134                    $action = join '/', $c->action->namespace, $action unless $action =~ m!^/!;
135            }                                  
136            $c->res->body( $c->subreq( $action, @args ) );
137            return;
138    }
139    
140    
141  =back  =back
142    
143  =head1 AUTHOR  =head1 AUTHOR
144    
145  Dobrica Pavlinusic,,,  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
146    
147  =head1 LICENSE  =head1 LICENSE
148    

Legend:
Removed from v.187  
changed lines
  Added in v.387

  ViewVC Help
Powered by ViewVC 1.1.26