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

Contents of /Webpacus/lib/Webpacus.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 399 - (show annotations)
Sun Feb 19 12:37:27 2006 UTC (18 years, 2 months ago) by dpavlin
File size: 2799 byte(s)
 r461@llin:  dpavlin | 2006-02-19 13:46:03 +0100
 each site now uses default index which is named same as site, added site_url to view,
 refactor site handling

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

  ViewVC Help
Powered by ViewVC 1.1.26