]>
Dogcows Code - chaz/chatty/blob - lib/Chatty/Controller/Chat.pm
73fe2744e99c32ecfcfba61b6a222feabad8857c
1 package Chatty
::Controller
::Chat
;
3 use namespace
::autoclean
;
5 BEGIN { extends
'Catalyst::Controller' }
7 #__PACKAGE__->config(namespace => 'room');
9 use Chatty
::Form
::RoomCreate
;
10 use Chatty
::Form
::MessageCreate
;
12 has 'roomcreate_form' => (
13 isa
=> 'Chatty::Form::RoomCreate',
16 default => sub { Chatty
::Form
::RoomCreate-
>new }
19 has 'messagecreate_form' => (
20 isa
=> 'Chatty::Form::MessageCreate',
23 default => sub { Chatty
::Form
::MessageCreate-
>new }
28 Chatty::Controller::Chat - Catalyst Controller
38 Base action for chat rooms. Sets up the model.
42 sub room
:Chained
(/) :CaptureArgs
(0) {
44 $c->detach('/access_denied') if !$c->user_exists;
49 List the current list of chat rooms.
53 sub list
:Chained
(room
) :Args
(0) {
56 $c->stash(rooms
=> [$c->model('DB::Room')->all]);
58 my $form = Chatty
::Form
::RoomCreate-
>new(action
=>
59 $c->uri_for_action('/chat/create'));
60 $c->stash(form
=> $form);
65 Create a new chat room.
69 sub create
:Chained
(room
) :Args
(0) {
72 $c->stash(form
=> $self->roomcreate_form);
74 my $new_room = $c->model('DB::Room')->new_result({});
75 $self->roomcreate_form->process(
77 params
=> $c->req->params
80 if (!$self->roomcreate_form->is_valid) {
81 if ($c->req->method eq 'POST') {
82 $c->stash->{error
} = "The form has a validation error. Try again...";
87 $c->flash->{message
} = "Your new room was created!";
88 $c->res->redirect($c->uri_for_action('/chat/view', $new_room->id));
97 sub view
:Chained
(room
) :PathPart
('') :Args
(1) {
98 my ($self, $c, $room) = @_;
100 $c->stash(room
=> $c->model('DB::Room')->find($room));
101 $c->detach('/missing') if !$c->stash->{room
};
103 $c->stash(messages
=> [$c->model('DB::Message')->search(room
=> $room)]);
105 $c->stash(form
=> $self->messagecreate_form);
107 my $new_message = $c->model('DB::Message')->new_result({
108 author
=> $c->user->obj->id,
109 room
=> $c->stash->{room
}->id
111 $self->messagecreate_form->process(
112 item
=> $new_message,
113 params
=> $c->req->params
116 if (!$self->messagecreate_form->is_valid) {
117 if ($c->req->method eq 'POST') {
118 $c->stash->{error
} = "The form has a validation error. Try again...";
123 $c->res->redirect($c->uri_for_action('/chat/view', $c->stash->{room
}->id));
132 This library is free software. You can redistribute it and/or modify
133 it under the same terms as Perl itself.
137 __PACKAGE__-
>meta->make_immutable;
This page took 0.041471 seconds and 3 git commands to generate.