Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial take on admin crud

  • Loading branch information...
commit 38bbf774ad1c28db68086ec6d310d98078b0578b 1 parent dec3d93
Breno G. de Oliveira authored December 23, 2010

Showing 1 changed file with 81 additions and 0 deletions. Show diff stats Hide diff stats

  1. 81  lib/perlgamedev/Controller/Admin.pm
81  lib/perlgamedev/Controller/Admin.pm
... ...
@@ -0,0 +1,81 @@
  1
+package perlgamedev::Controller::Admin;
  2
+use Moose;
  3
+use namespace::autoclean;
  4
+
  5
+BEGIN {extends 'Catalyst::Controller'; }
  6
+
  7
+=head1 NAME
  8
+
  9
+perlgamedev::Controller::Admin - Catalyst Controller
  10
+
  11
+=head1 DESCRIPTION
  12
+
  13
+Catalyst Controller.
  14
+
  15
+=head1 METHODS
  16
+
  17
+=cut
  18
+
  19
+
  20
+=head2 index
  21
+
  22
+Main admin interface to create and delete games
  23
+
  24
+=cut
  25
+
  26
+sub index :Path :Args(0) {
  27
+    my ( $self, $c ) = @_;
  28
+
  29
+    $c->stash( games => [ $c->model('DB::Game')->all ] );
  30
+}
  31
+
  32
+=head2 create
  33
+
  34
+Create a new game
  35
+
  36
+=cut
  37
+
  38
+sub create :Local :Args(0) {
  39
+    my ( $self, $c ) = @_;
  40
+
  41
+
  42
+    my $game = $c->model('DB::Game')->create({
  43
+        name => $c->req->param('name'),
  44
+        info => $c->req->param('info'),
  45
+        license => $c->req->param('license'),
  46
+        url     => $c->req->param('url'),
  47
+    });
  48
+
  49
+    $c->flash( message => 'Game created successfully!' );
  50
+    $c->res->redirect( $c->uri_for( $self->action_for('index') ) );
  51
+}
  52
+
  53
+sub delete :Local :Args(0) {
  54
+    my ( $self, $c ) = @_;
  55
+    my $id = $c->req->param('game');
  56
+
  57
+    $c->log->debug( "looking up id '$id' for deletion" );
  58
+    my $game = $c->model('DB::Game')->find( $id )
  59
+        or $c->detach('/error_404');
  60
+
  61
+    $c->log->debug('removing entry ' . $game->id);
  62
+    $game->delete;
  63
+
  64
+    $c->flash( message => 'Game deleted successfully!' );
  65
+    $c->res->redirect( $c->uri_for( $self->action_for('index') ) );
  66
+}
  67
+
  68
+=head1 AUTHOR
  69
+
  70
+garu,,,
  71
+
  72
+=head1 LICENSE
  73
+
  74
+This library is free software. You can redistribute it and/or modify
  75
+it under the same terms as Perl itself.
  76
+
  77
+=cut
  78
+
  79
+__PACKAGE__->meta->make_immutable;
  80
+
  81
+1;

0 notes on commit 38bbf77

Please sign in to comment.
Something went wrong with that request. Please try again.