]>
Dogcows Code - chaz/chatty/blob - lib/Chatty/Controller/Chat.pm
1 package Chatty
::Controller
::Chat
;
3 use namespace
::autoclean
;
5 BEGIN { extends
'Catalyst::Controller' }
7 #__PACKAGE__->config(namespace => 'room');
9 use Chatty
::Form
::RoomCreate
;
11 has 'roomcreate_form' => (
12 isa
=> 'Chatty::Form::RoomCreate',
15 default => sub { Chatty
::Form
::RoomCreate-
>new }
20 Chatty::Controller::Chat - Catalyst Controller
30 Base action for chat rooms. Sets up the model.
34 sub room
:Chained
(/) :CaptureArgs
(0) {
36 $c->detach('/access_denied') if !$c->user_exists;
41 List the current list of chat rooms.
45 sub list
:Chained
(room
) :Args
(0) {
48 $c->stash(rooms
=> [$c->model('DB::Room')->all]);
50 my $form = Chatty
::Form
::RoomCreate-
>new(action
=>
51 $c->uri_for_action('/chat/create'));
52 $c->stash(form
=> $form);
57 Create a new chat room.
61 sub create
:Chained
(room
) :Args
(0) {
64 $c->stash(form
=> $self->roomcreate_form);
66 my $new_room = $c->model('DB::Room')->new_result({});
67 $self->roomcreate_form->process(
69 params
=> $c->req->params
72 if (!$self->roomcreate_form->is_valid) {
73 if ($c->req->method eq 'POST') {
74 $c->stash->{error
} = "The form has a validation error. Try again...";
79 $c->flash->{message
} = "Your new room was created!";
80 $c->res->redirect($c->uri_for_action('/chat/view', $new_room->id));
89 sub view
:Chained
(room
) :PathPart
('') :Args
(1) {
90 my ($self, $c, $room) = @_;
92 $c->stash(room
=> $c->model('DB::Room')->find($room));
93 $c->detach('/missing') if !$c->stash->{room
};
95 my $name = $c->user->obj->username;
97 my $msg = $c->req->param('msg');
100 $c->model('Meteor')->addMessage($room, "$name: $msg");
101 $c->stash->{json
} = \
1;
102 $c->forward('View::JSON');
106 $c->model('Meteor')->addMessage($room, "** $name has entered **");
115 This library is free software. You can redistribute it and/or modify
116 it under the same terms as Perl itself.
120 __PACKAGE__-
>meta->make_immutable;
This page took 0.040246 seconds and 4 git commands to generate.