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.36-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; |