[Catalyst-commits] r12324 - in trunk/examples/SmallBoard: . lib lib/SmallBoard/Controller lib/SmallBoard/Schema/Result lib/SmallBoard/Script root/src root/src/board t

dhoss at dev.catalyst.perl.org dhoss at dev.catalyst.perl.org
Sun Dec 13 03:23:46 GMT 2009


Author: dhoss
Date: 2009-12-13 03:23:46 +0000 (Sun, 13 Dec 2009)
New Revision: 12324

Added:
   trunk/examples/SmallBoard/lib/SmallBoard/Controller/Board.pm
   trunk/examples/SmallBoard/lib/SmallBoard/Schema/Result/Thread.pm
   trunk/examples/SmallBoard/root/src/board/
   trunk/examples/SmallBoard/root/src/board/create.tt2
   trunk/examples/SmallBoard/t/controller_Board.t
Removed:
   trunk/examples/SmallBoard/lib/SmallBoard/Schema/Result/Board.pm
Modified:
   trunk/examples/SmallBoard/lib/SmallBoard.pm
   trunk/examples/SmallBoard/lib/SmallBoard/Script/Deploy.pm
   trunk/examples/SmallBoard/root/src/index.tt2
   trunk/examples/SmallBoard/root/src/wrapper
   trunk/examples/SmallBoard/smallboard.db
Log:
can now create threads

Added: trunk/examples/SmallBoard/lib/SmallBoard/Controller/Board.pm
===================================================================
--- trunk/examples/SmallBoard/lib/SmallBoard/Controller/Board.pm	                        (rev 0)
+++ trunk/examples/SmallBoard/lib/SmallBoard/Controller/Board.pm	2009-12-13 03:23:46 UTC (rev 12324)
@@ -0,0 +1,72 @@
+package SmallBoard::Controller::Board;
+
+use strict;
+use warnings;
+use parent 'Catalyst::Controller';
+
+=head1 NAME
+
+SmallBoard::Controller::Board - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+    my ( $self, $c ) = @_;
+
+    $c->res->redirect( $c->uri_for_action('board/create'));
+}
+
+sub board_base : Chained('/') PathPart('board') CaptureArgs(0) {}
+
+sub load_threads : Chained('board_base') PathPart('') CaptureArgs(1) {
+    my ($self, $c, $thread_id) = @_;
+
+	my $thread = $c->model('Board')->find($thread_id);
+
+	if ($thread_id) {
+	    $c->stash( thread => $thread );
+	} else {
+	    $c->error("No such thread");
+		$c->detach;
+	}
+}
+
+sub view : Chained('load_threads') PathPart('view') Args(0) {}
+
+sub create : Chained('board_base') PathPart('new') Args(0) {
+    my ($self, $c) = @_;
+
+    ## fancy form stuff would go here, but I'm lazy
+	if ( $c->req->param('submitted') ) {
+		my $params = $c->req->params;
+        delete $params->{$_} for qw/submitted submit/;
+	    my $entry = $c->model('Board::Thread')->create($params) or $c->error("Error creating thread parent: $!");
+		$c->msg("Created new thread!");
+	}
+	
+}
+	
+
+=head1 AUTHOR
+
+Devin Austin
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;

Deleted: trunk/examples/SmallBoard/lib/SmallBoard/Schema/Result/Board.pm
===================================================================
--- trunk/examples/SmallBoard/lib/SmallBoard/Schema/Result/Board.pm	2009-12-13 00:26:59 UTC (rev 12323)
+++ trunk/examples/SmallBoard/lib/SmallBoard/Schema/Result/Board.pm	2009-12-13 03:23:46 UTC (rev 12324)
@@ -1,19 +0,0 @@
-package SmallBoard::Schema::Result::Board;
-use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/ Tree::Ordered::MatPath Core /);
-__PACKAGE__->table ('nested');
-__PACKAGE__->add_columns (
-  id => { data_type => 'int', is_auto_increment => 1 },
-  name => { data_type => 'varchar' },
-  parent_id => { data_type => 'int', is_nullable => 1 },
-  path => { data_type => 'varchar' },
-);
-
-__PACKAGE__->set_primary_key ('id');
-
-__PACKAGE__->has_many ('children', __PACKAGE__, 'parent_id');
-__PACKAGE__->belongs_to ('parent', __PACKAGE__, 'parent_id');
-
-__PACKAGE__->position_column ('path');
-__PACKAGE__->grouping_column ('parent_id');
-1;

Added: trunk/examples/SmallBoard/lib/SmallBoard/Schema/Result/Thread.pm
===================================================================
--- trunk/examples/SmallBoard/lib/SmallBoard/Schema/Result/Thread.pm	                        (rev 0)
+++ trunk/examples/SmallBoard/lib/SmallBoard/Schema/Result/Thread.pm	2009-12-13 03:23:46 UTC (rev 12324)
@@ -0,0 +1,20 @@
+package SmallBoard::Schema::Result::Thread;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ Tree::Ordered::MatPath Core /);
+__PACKAGE__->table ('nested');
+__PACKAGE__->add_columns (
+  thread_id => { data_type => 'int', is_auto_increment => 1 },
+  title => { data_type => 'varchar' },
+  content => { data_type => 'text' },
+  parent_id => { data_type => 'int', is_nullable => 1 },
+  path => { data_type => 'varchar' },
+);
+
+__PACKAGE__->set_primary_key ('thread_id');
+
+__PACKAGE__->has_many ('children', __PACKAGE__, 'parent_id');
+__PACKAGE__->belongs_to ('parent', __PACKAGE__, 'parent_id');
+
+__PACKAGE__->position_column ('path');
+__PACKAGE__->grouping_column ('parent_id');
+1;

Modified: trunk/examples/SmallBoard/lib/SmallBoard/Script/Deploy.pm
===================================================================
--- trunk/examples/SmallBoard/lib/SmallBoard/Script/Deploy.pm	2009-12-13 00:26:59 UTC (rev 12323)
+++ trunk/examples/SmallBoard/lib/SmallBoard/Script/Deploy.pm	2009-12-13 03:23:46 UTC (rev 12324)
@@ -2,13 +2,15 @@
 
 use Moose;
 use MooseX::Types::Moose qw/Str/;
+use SmallBoard::Schema;
 use namespace::autoclean;
 with 'Catalyst::ScriptRole';
-extends 'SmallBoard::Schema';
+
 has dsn => (
     traits        => [qw(Getopt)],
     isa           => Str,
 	is            => 'ro',
+	required      => 1,
 	documentation => "dsn for your database"
 );
 
@@ -16,6 +18,7 @@
     traits        => [qw(Getopt)],
 	isa           => Str,
 	is            => 'ro',
+	required      => 1,
 	documentation => "username for your database",
 );
 
@@ -29,18 +32,29 @@
 
 has schema => (
     traits        => [qw(NoGetopt)],
-	isa           => "SmallBoard::Schema",
+	isa           => 'SmallBoard::Schema',
 	is            => "ro",
-	default       => sub { my $self = shift; $self->connect($self->dsn, $self->user, $self->password);  },
+	default       => sub { my $self = shift;  SmallBoard::Schema->connect($self->dsn, $self->user, $self->password);  },
 );
 
 sub run {
-    my $self = shift;
+    my ($self) = @_;
 	$self->_getopt_full_usage if !$self->ARGV->[0];
-
+    print "Deploying...\n";
+	print $_ . ":" .$self->$_ ."\n" for qw/ dsn user password /;
 	$self->schema->deploy or die "Can't deploy: $!";
+	print "Deployed successfully!\n";
 }
 
+sub _application_args {
+    my ($self) = shift;
+    return (
+	    {
+	     map { $_ => $self->$_ } qw/ dsn user password /
+        }
+    );
+}
+
 __PACKAGE__->meta->make_immutable;
 
 1;

Modified: trunk/examples/SmallBoard/lib/SmallBoard.pm
===================================================================
--- trunk/examples/SmallBoard/lib/SmallBoard.pm	2009-12-13 00:26:59 UTC (rev 12323)
+++ trunk/examples/SmallBoard/lib/SmallBoard.pm	2009-12-13 03:23:46 UTC (rev 12324)
@@ -16,6 +16,7 @@
 	-Debug
     ConfigLoader
     Static::Simple
+	+CatalystX::FeedbackMessages
 /;
 
 extends 'Catalyst';

Added: trunk/examples/SmallBoard/root/src/board/create.tt2
===================================================================
--- trunk/examples/SmallBoard/root/src/board/create.tt2	                        (rev 0)
+++ trunk/examples/SmallBoard/root/src/board/create.tt2	2009-12-13 03:23:46 UTC (rev 12324)
@@ -0,0 +1,7 @@
+<form method="POST" action="[% c.uri_for_action("board/create") %]">
+<input type="hidden" name="submitted" value=1 />
+<p>Title: <input type="text" name="title" /></p>
+<p>Content:</p>
+<textarea name="content" rows="10" cols="45">
+</textarea>
+<p><input type="submit" name="submit" value="Post" />

Modified: trunk/examples/SmallBoard/root/src/index.tt2
===================================================================
--- trunk/examples/SmallBoard/root/src/index.tt2	2009-12-13 00:26:59 UTC (rev 12323)
+++ trunk/examples/SmallBoard/root/src/index.tt2	2009-12-13 03:23:46 UTC (rev 12324)
@@ -1 +1,3 @@
 <h2>SMALLBOARD IS SMALL</h2>
+|<a href="[% c.uri_for_action("board/create") %]">create a new thread</a> | 
+<p>Recent threads:</p>

Modified: trunk/examples/SmallBoard/root/src/wrapper
===================================================================
--- trunk/examples/SmallBoard/root/src/wrapper	2009-12-13 00:26:59 UTC (rev 12323)
+++ trunk/examples/SmallBoard/root/src/wrapper	2009-12-13 03:23:46 UTC (rev 12324)
@@ -8,6 +8,10 @@
 			           <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 					           <title>[% title || "SMALLBOARD" %]</title>
 			   </head>
-			   <body>[% content %]</body>
+			   <body>
+			   [% FOR message IN messages %]
+			     [% message %]
+			   [% END %]
+			   [% content %]</body>
 			   </html>
 [% END %]

Modified: trunk/examples/SmallBoard/smallboard.db
===================================================================
--- trunk/examples/SmallBoard/smallboard.db	2009-12-13 00:26:59 UTC (rev 12323)
+++ trunk/examples/SmallBoard/smallboard.db	2009-12-13 03:23:46 UTC (rev 12324)
@@ -1 +1,8 @@
-S
\ No newline at end of file
+SQLite format 3   @                                                                          
   è Gè                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ]5{indexnested_idx_parent_idnestedCREATE INDEX nested_idx_parent_id ON nested (parent_id)6‚GtablenestednestedCREATE TABLE nested (
+  thread_id INTEGER PRIMARY KEY NOT NULL,
+  title varchar NOT NULL,
+  content text NOT NULL,
+  parent_id int,
+  path varchar NOT NULL
+)
   ï ï                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       testtest1
+   û û                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
\ No newline at end of file

Added: trunk/examples/SmallBoard/t/controller_Board.t
===================================================================
--- trunk/examples/SmallBoard/t/controller_Board.t	                        (rev 0)
+++ trunk/examples/SmallBoard/t/controller_Board.t	2009-12-13 03:23:46 UTC (rev 12324)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+BEGIN { use_ok 'Catalyst::Test', 'Board' }
+BEGIN { use_ok 'SmallBoard::Controller::Board' }
+
+ok( request('/board')->is_success, 'Request should succeed' );
+
+
+
+done_testing();




More information about the Catalyst-commits mailing list