/[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 97 by dpavlin, Tue Nov 22 12:57:35 2005 UTC revision 378 by dpavlin, Sat Jan 21 23:27:16 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
         Unicode::Encoding  
14          Config::YAML          Config::YAML
15            FillInForm
16            SubRequest
17            Static::Simple
18            StackTrace
19  /;  /;
20  #       FormValidator  #       FormValidator
 #       FillInForm  
21    
22  our $VERSION = '0.01';  our $VERSION = '0.32-dev';
23    
24  #  #
25  # Configure the application  # Configure the application
26  #  #
27  __PACKAGE__->config(  __PACKAGE__->config(
28          name => 'Webpacus',          name => 'Webpacus',
         encoding => 'ISO-8859-2',  
29          config_file => 'config.yml',          config_file => 'config.yml',
30  );  );
31    
# Line 57  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 default : Private { Line 91  sub default : Private {
91  sub end : Private {  sub end : Private {
92      my ( $self, $c ) = @_;      my ( $self, $c ) = @_;
93    
94      # Forward to View unless response body is already defined      $c->stash->{webpacus_version} = $VERSION;
95      $c->forward('View::TT') unless $c->response->body;  
96        if ($c->response->body) {
97            $c->log->debug("at end body exists, we won't touch it!");
98        } else {
99                    $c->fillform( $c->req->params );
100    
101                    if (my $site_name = $c->stash->{site}) {
102                            my $template_path = $c->path_to('root', $c->config->{sites_root}, $site_name, $c->stash->{template});
103                            if (-e $template_path) {
104                                    $c->stash->{template} = $c->config->{sites_root} . "/$site_name/" . $c->stash->{template};
105                            } else {
106                                    $c->log->warn("can't find $template_path, fallback to default");
107                            }
108                            $c->log->debug("using template ", $c->stash->{template});
109                    }
110    
111                    # Forward to View unless response body is already defined
112                    $c->forward('View::TT');
113    
114                    $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 );  #               $c->log->debug( $c->response->body );
118        }
119    
 #    $c->fillform; # defaults to $c->req->parameters  
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.97  
changed lines
  Added in v.378

  ViewVC Help
Powered by ViewVC 1.1.26