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 |
|
|
if (my $sites_root = $c->config->{sites_root}) { |
64 |
|
|
my $site_path = $c->path_to('root', $sites_root, $site_name); |
65 |
|
|
|
66 |
|
|
if (-e $site_path) { |
67 |
|
|
$c->stash->{site} = $site_name; |
68 |
|
|
if (my $action = shift @{ $c->req->args }) { |
69 |
|
|
$c->log->debug( "site: $site_name, action: $action" ); |
70 |
|
|
$c->internal_redirect( $action, $c->stash ); |
71 |
|
|
} else { |
72 |
|
|
$c->log->debug( "site: $site_name" ); |
73 |
|
|
} |
74 |
|
|
} else { |
75 |
|
|
$c->log->debug( "can't find site $site_name in $site_path"); |
76 |
|
|
} |
77 |
|
|
} else { |
78 |
|
|
$c->log->warn("sites_root not defined in config"); |
79 |
|
|
} |
80 |
dpavlin |
83 |
} |
81 |
|
|
|
82 |
|
|
=item end |
83 |
|
|
|
84 |
|
|
=cut |
85 |
|
|
|
86 |
|
|
sub end : Private { |
87 |
|
|
my ( $self, $c ) = @_; |
88 |
|
|
|
89 |
dpavlin |
139 |
$c->stash->{webpacus_version} = $VERSION; |
90 |
|
|
|
91 |
dpavlin |
228 |
if ($c->response->body) { |
92 |
|
|
$c->log->debug("at end body exists, we won't touch it!"); |
93 |
|
|
} else { |
94 |
dpavlin |
270 |
$c->fillform( $c->req->params ); |
95 |
dpavlin |
97 |
|
96 |
dpavlin |
358 |
if (my $site_name = $c->stash->{site}) { |
97 |
|
|
my $template_path = $c->path_to('root', $c->config->{sites_root}, $site_name, $c->stash->{template}); |
98 |
|
|
if (-e $template_path) { |
99 |
|
|
$c->stash->{template} = $c->config->{sites_root} . "/$site_name/" . $c->stash->{template}; |
100 |
|
|
} else { |
101 |
|
|
$c->log->warn("can't find $template_path, fallback to default"); |
102 |
|
|
} |
103 |
|
|
$c->log->debug("using template ", $c->stash->{template}); |
104 |
|
|
} |
105 |
|
|
|
106 |
dpavlin |
270 |
# Forward to View unless response body is already defined |
107 |
|
|
$c->forward('View::TT'); |
108 |
dpavlin |
100 |
|
109 |
dpavlin |
270 |
$c->response->{body} =~ s#\Qnew Ajax.Autocompleter(\E#new WebPAC.Suggest(#gs; |
110 |
|
|
$c->response->{body} =~ s#\Qnew Ajax.Updater(\E#new WebPAC.Updater(#gs; |
111 |
|
|
|
112 |
|
|
# $c->log->debug( $c->response->body ); |
113 |
dpavlin |
228 |
} |
114 |
dpavlin |
97 |
|
115 |
dpavlin |
83 |
} |
116 |
|
|
|
117 |
dpavlin |
358 |
=item internal_redirect |
118 |
|
|
|
119 |
|
|
$c->internal_redirect( $action, @args ); |
120 |
|
|
|
121 |
|
|
=cut |
122 |
|
|
|
123 |
|
|
sub internal_redirect { |
124 |
|
|
my ( $c, $action, @args ) = @_; |
125 |
|
|
|
126 |
|
|
unless ( defined $action ) { |
127 |
|
|
$action = $c->action->namespace; |
128 |
|
|
} else { |
129 |
|
|
$action = join '/', $c->action->namespace, $action unless $action =~ m!^/!; |
130 |
|
|
} |
131 |
|
|
$c->res->body( $c->subreq( $action, @args ) ); |
132 |
|
|
return; |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
|
136 |
dpavlin |
83 |
=back |
137 |
|
|
|
138 |
|
|
=head1 AUTHOR |
139 |
|
|
|
140 |
dpavlin |
203 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
141 |
dpavlin |
83 |
|
142 |
|
|
=head1 LICENSE |
143 |
|
|
|
144 |
|
|
This library is free software, you can redistribute it and/or modify |
145 |
|
|
it under the same terms as Perl itself. |
146 |
|
|
|
147 |
|
|
=cut |
148 |
|
|
|
149 |
|
|
1; |