/[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

Annotation of /Webpacus/lib/Webpacus.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 359 - (hide annotations)
Sun Jan 8 14:52:24 2006 UTC (18 years, 4 months ago) by dpavlin
File size: 3221 byte(s)
 r386@llin:  dpavlin | 2006-01-08 15:52:38 +0100
 fixed sites testing, completed tests (which fail for a reason :-), minor tweaks to
 localisaion

1 dpavlin 83 package Webpacus;
2    
3     use strict;
4     use warnings;
5    
6     #
7     # Set flags and add plugins for the application
8     #
9     # -Debug: activates the debug mode for very useful log messages
10     # Static::Simple: will serve static files from the applications root directory
11     #
12 dpavlin 93 use Catalyst qw/-Debug
13     Prototype
14     Config::YAML
15 dpavlin 100 FillInForm
16 dpavlin 207 SubRequest
17 dpavlin 228 Static::Simple
18 dpavlin 348 StackTrace
19 dpavlin 93 /;
20 dpavlin 97 # FormValidator
21 dpavlin 83
22 dpavlin 358 our $VERSION = '0.31-dev';
23 dpavlin 83
24     #
25     # Configure the application
26     #
27 dpavlin 93 __PACKAGE__->config(
28     name => 'Webpacus',
29     config_file => 'config.yml',
30     );
31 dpavlin 83
32     #
33     # Start the application
34     #
35     __PACKAGE__->setup;
36    
37     =head1 NAME
38    
39     Webpacus - Catalyst based application
40    
41     =head1 SYNOPSIS
42    
43     script/webpacus_server.pl
44    
45     =head1 DESCRIPTION
46    
47     Catalyst based application.
48    
49     =head1 METHODS
50    
51     =over 4
52    
53     =item default
54    
55     =cut
56    
57     sub default : Private {
58     my ( $self, $c ) = @_;
59     $c->stash->{template} = 'index.tt';
60 dpavlin 358
61     my $site_name = shift @{ $c->req->args };
62    
63 dpavlin 359 $c->log->debug("trying site name: $site_name");
64    
65 dpavlin 358 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 dpavlin 359 if (my $action = join('/', @{ $c->req->args })) {
71 dpavlin 358 $c->log->debug( "site: $site_name, action: $action" );
72 dpavlin 359 # 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 dpavlin 358 } 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 dpavlin 83 }
86    
87     =item end
88    
89     =cut
90    
91     sub end : Private {
92     my ( $self, $c ) = @_;
93    
94 dpavlin 139 $c->stash->{webpacus_version} = $VERSION;
95    
96 dpavlin 228 if ($c->response->body) {
97     $c->log->debug("at end body exists, we won't touch it!");
98     } else {
99 dpavlin 270 $c->fillform( $c->req->params );
100 dpavlin 97
101 dpavlin 358 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 dpavlin 270 # Forward to View unless response body is already defined
112     $c->forward('View::TT');
113 dpavlin 100
114 dpavlin 270 $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 dpavlin 228 }
119 dpavlin 97
120 dpavlin 83 }
121    
122 dpavlin 358 =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 dpavlin 83 =back
142    
143     =head1 AUTHOR
144    
145 dpavlin 203 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
146 dpavlin 83
147     =head1 LICENSE
148    
149     This library is free software, you can redistribute it and/or modify
150     it under the same terms as Perl itself.
151    
152     =cut
153    
154     1;

  ViewVC Help
Powered by ViewVC 1.1.26