/[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 455 - (hide annotations)
Sun May 7 21:45:50 2006 UTC (18 years ago) by dpavlin
File size: 3123 byte(s)
 r569@llin:  dpavlin | 2006-05-07 23:47:56 +0200
 fix utf8 flag on all $c->request->params before C:P:FillInForm gets it. I don't know
 why I have to do this by hand, and it seems fishy... (but it works)

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 399 Dumper
20 dpavlin 93 /;
21 dpavlin 97 # FormValidator
22 dpavlin 83
23 dpavlin 455 use Encode qw/is_utf8 decode/;
24 dpavlin 83
25 dpavlin 455 our $VERSION = '0.37-dev';
26    
27 dpavlin 83 #
28     # Configure the application
29     #
30 dpavlin 93 __PACKAGE__->config(
31     name => 'Webpacus',
32     config_file => 'config.yml',
33     );
34 dpavlin 83
35     #
36     # Start the application
37     #
38     __PACKAGE__->setup;
39    
40     =head1 NAME
41    
42     Webpacus - Catalyst based application
43    
44     =head1 SYNOPSIS
45    
46     script/webpacus_server.pl
47    
48     =head1 DESCRIPTION
49    
50     Catalyst based application.
51    
52     =head1 METHODS
53    
54     =over 4
55    
56     =item default
57    
58     =cut
59    
60     sub default : Private {
61     my ( $self, $c ) = @_;
62     $c->stash->{template} = 'index.tt';
63 dpavlin 358
64 dpavlin 422 my $site_name = shift @{ $c->req->args } || '';
65 dpavlin 358
66 dpavlin 359 $c->log->debug("trying site name: $site_name");
67    
68 dpavlin 358 if (my $sites_root = $c->config->{sites_root}) {
69     my $site_path = $c->path_to('root', $sites_root, $site_name);
70    
71     if (-e $site_path) {
72     $c->stash->{site} = $site_name;
73 dpavlin 359 if (my $action = join('/', @{ $c->req->args })) {
74 dpavlin 358 $c->log->debug( "site: $site_name, action: $action" );
75 dpavlin 399 # do a subrequest
76     $c->res->body( $c->subreq( $action, $c->stash, @{ $c->req->args } ) );
77 dpavlin 358 } else {
78     $c->log->debug( "site: $site_name" );
79     }
80     } else {
81     $c->log->debug( "can't find site $site_name in $site_path");
82     }
83     } else {
84     $c->log->warn("sites_root not defined in config");
85     }
86 dpavlin 83 }
87    
88     =item end
89    
90     =cut
91    
92     sub end : Private {
93     my ( $self, $c ) = @_;
94    
95 dpavlin 139 $c->stash->{webpacus_version} = $VERSION;
96    
97 dpavlin 228 if ($c->response->body) {
98     $c->log->debug("at end body exists, we won't touch it!");
99     } else {
100 dpavlin 358 if (my $site_name = $c->stash->{site}) {
101     my $template_path = $c->path_to('root', $c->config->{sites_root}, $site_name, $c->stash->{template});
102     if (-e $template_path) {
103     $c->stash->{template} = $c->config->{sites_root} . "/$site_name/" . $c->stash->{template};
104     } else {
105     $c->log->warn("can't find $template_path, fallback to default");
106     }
107 dpavlin 399 $c->log->debug("using template " . $c->stash->{template});
108    
109     $c->stash->{site_url} = "/$site_name/";
110    
111 dpavlin 405 #$c->log->dumper( $c->stash, 'stash' );
112 dpavlin 399
113 dpavlin 358 }
114    
115 dpavlin 270 # Forward to View unless response body is already defined
116     $c->forward('View::TT');
117 dpavlin 100
118 dpavlin 455 # oh, turn utf8 flag for all parametars (why do I need to do this?)
119     my $utf8_params;
120     map {
121     $utf8_params->{$_} = decode('UTF-8', $c->request->params->{$_});
122     } keys %{ $c->request->params };
123 dpavlin 387
124 dpavlin 455 # and fill-in form with new UTF-8 encoded params (to prevent double-escape of UTF-8)
125     $c->fillform( $utf8_params );
126    
127 dpavlin 270 $c->response->{body} =~ s#\Qnew Ajax.Autocompleter(\E#new WebPAC.Suggest(#gs;
128     $c->response->{body} =~ s#\Qnew Ajax.Updater(\E#new WebPAC.Updater(#gs;
129    
130     # $c->log->debug( $c->response->body );
131 dpavlin 228 }
132 dpavlin 97
133 dpavlin 83 }
134    
135     =back
136    
137     =head1 AUTHOR
138    
139 dpavlin 203 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
140 dpavlin 83
141     =head1 LICENSE
142    
143     This library is free software, you can redistribute it and/or modify
144     it under the same terms as Perl itself.
145    
146     =cut
147    
148     1;

  ViewVC Help
Powered by ViewVC 1.1.26