forked from jshirley/CatalystX-StyleGuide
/
Root.pm
100 lines (69 loc) · 1.97 KB
/
Root.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package StyleGuide::Controller::Root;
use Moose;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller' }
#
# Sets the actions in this controller to be registered with no prefix
# so they function identically to actions created in MyApp.pm
#
__PACKAGE__->config(namespace => '');
=head1 NAME
StyleGuide::Controller::Root - Root Controller for StyleGuide
=head1 DESCRIPTION
[enter your description here]
=head1 METHODS
=head2 index
The root page (/)
=cut
sub setup : Chained('/') PathPart('') CaptureArgs(0) {
my ( $self, $c ) = @_;
my $design = $c->req->cookie('design');
if ( not $design ) {
$design = $c->view('StyleGuide')->default_style
} else {
$c->stash->{design} = $design->value;
}
}
sub index : Chained('setup') PathPart('') Args(0) {
my ( $self, $c ) = @_;
}
sub guide : Chained('setup') Args {
my ( $self, $c, $layout ) = @_;
if ( $layout ) {
if ( -f $c->path_to("root/guide", "$layout.tt") ) {
$c->stash->{template} = "guide/$layout.tt";
}
}
}
sub switch : Chained('setup') Args(0) {
my ( $self, $c ) = @_;
$c->stash->{designs} = $c->view('StyleGuide')->designs;
$c->log->_dump($c->stash->{designs}) if $c->debug;
if ( $c->req->method eq 'POST' and my $design = $c->req->params->{design} ) {
if ( $c->view('StyleGuide')->get_design($design) ) {
$c->res->cookies->{design} = { value => $design };
}
$c->res->redirect($c->req->uri);
}
$c->forward( $c->view('TT') );
}
=head2 default
Standard 404 error page
=cut
sub default : Private {
my ( $self, $c ) = @_;
$c->response->body( 'Page not found' );
$c->response->status(404);
}
=head2 end
Attempt to render a view, if needed.
=cut
sub end : ActionClass('RenderView') {}
=head1 AUTHOR
Jay Shirley
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
__PACKAGE__->meta->make_immutable;
1;