[Catalyst-commits] r6634 - in trunk/examples/CatPaste: . lib/CatPaste/Controller lib/CatPaste/Model lib/CatPaste/Schema root/paste

jshirley at dev.catalyst.perl.org jshirley at dev.catalyst.perl.org
Thu Aug 9 21:59:22 GMT 2007


Author: jshirley
Date: 2007-08-09 21:59:22 +0100 (Thu, 09 Aug 2007)
New Revision: 6634

Modified:
   trunk/examples/CatPaste/Makefile.PL
   trunk/examples/CatPaste/lib/CatPaste/Controller/Root.pm
   trunk/examples/CatPaste/lib/CatPaste/Model/IKC.pm
   trunk/examples/CatPaste/lib/CatPaste/Schema/Paste.pm
   trunk/examples/CatPaste/root/paste/root.tt
   trunk/examples/CatPaste/root/paste/view.tt
Log:
Fixing Makefile, adding author and ip_address logging and graceful failing if IKC can't connect

Modified: trunk/examples/CatPaste/Makefile.PL
===================================================================
--- trunk/examples/CatPaste/Makefile.PL	2007-08-09 09:36:13 UTC (rev 6633)
+++ trunk/examples/CatPaste/Makefile.PL	2007-08-09 20:59:22 UTC (rev 6634)
@@ -8,6 +8,7 @@
 requires 'DBD::SQLite';
 requires 'XML::Feed';
 requires 'Syntax::Highlight::Engine::Kate';
+requires 'POE::Component::IKC::ClientLite';
 
 requires 'Catalyst::Plugin::ConfigLoader';
 requires 'Catalyst::Plugin::Static::Simple';

Modified: trunk/examples/CatPaste/lib/CatPaste/Controller/Root.pm
===================================================================
--- trunk/examples/CatPaste/lib/CatPaste/Controller/Root.pm	2007-08-09 09:36:13 UTC (rev 6633)
+++ trunk/examples/CatPaste/lib/CatPaste/Controller/Root.pm	2007-08-09 20:59:22 UTC (rev 6634)
@@ -83,9 +83,10 @@
 sub post : Chained('base') PathPart('post') Args(0) {
     my ( $self, $c ) = @_;
     
-    my $paste : Param;
-    my $title : Param;
-    my $type  : Param;
+    my $paste  : Param;
+    my $title  : Param;
+    my $type   : Param;
+    my $author : Param;
 
     unless ( $c->req->method eq 'POST' and $paste ) {
         $c->res->redirect( $c->uri_for( $c->controller->action_for('root' ) ) );
@@ -100,6 +101,8 @@
             category_pk1 => $c->model('Schema::Category')
                 ->find_or_create({ label => 'General' })->pk1,
             title    => $title || 'Untitled Paste',
+            author   => $author || 'Anonymous Coward',
+            ip_address => $c->req->address,
             type     => exists $VALID_TYPES_HASH{$type} ?
                 $type : 'Plain'
         });

Modified: trunk/examples/CatPaste/lib/CatPaste/Model/IKC.pm
===================================================================
--- trunk/examples/CatPaste/lib/CatPaste/Model/IKC.pm	2007-08-09 09:36:13 UTC (rev 6633)
+++ trunk/examples/CatPaste/lib/CatPaste/Model/IKC.pm	2007-08-09 20:59:22 UTC (rev 6634)
@@ -4,6 +4,7 @@
 use warnings;
 use base 'Catalyst::Model';
 
+use Carp;
 use POE::Component::IKC::ClientLite;
 
 __PACKAGE__->mk_accessors( qw/remote/ );
@@ -30,7 +31,8 @@
         name => $self->{name} . "_$$",
         timeout => 10
     ) );
-    die "Couldn't create IKC client\n"
+
+    carp "Couldn't create IKC client, IKC notification disabled\n"
         unless $self->remote;
 
     return $self;
@@ -38,6 +40,8 @@
 
 sub notify {
     my ( $self, $message ) = @_;
+    return undef unless $self->remote;
+
     $self->remote->post( $self->{channel}, $message );
 }
 

Modified: trunk/examples/CatPaste/lib/CatPaste/Schema/Paste.pm
===================================================================
--- trunk/examples/CatPaste/lib/CatPaste/Schema/Paste.pm	2007-08-09 09:36:13 UTC (rev 6633)
+++ trunk/examples/CatPaste/lib/CatPaste/Schema/Paste.pm	2007-08-09 20:59:22 UTC (rev 6634)
@@ -24,9 +24,11 @@
 __PACKAGE__->add_columns(
     pk1   => { data_type => 'integer', size => 16, is_auto_increment => 1 },
     category_pk1 => { data_type => 'integer', size => 16 },
-    title => { data_type => 'varchar', size => 255 },
-    type  => { data_type => 'varchar', size => 25  },
-    t_created => { data_type => 'datetime', set_on_create => 1 }
+    author       => { data_type => 'varchar', size => 255 },
+    ip_address   => { data_type => 'varchar', size => 255 },
+    title        => { data_type => 'varchar', size => 255 },
+    type         => { data_type => 'varchar', size => 25  },
+    t_created    => { data_type => 'datetime', set_on_create => 1 }
 );
 
 __PACKAGE__->set_primary_key('pk1');

Modified: trunk/examples/CatPaste/root/paste/root.tt
===================================================================
--- trunk/examples/CatPaste/root/paste/root.tt	2007-08-09 09:36:13 UTC (rev 6633)
+++ trunk/examples/CatPaste/root/paste/root.tt	2007-08-09 20:59:22 UTC (rev 6634)
@@ -2,6 +2,10 @@
 <fieldset class="paste">
     <legend>Paste It</legend>
     <div>
+        <label for="author">Your Name: </label>
+        <input type="text" id="author" name="author" size="40"/>
+    </div>
+    <div>
         <label for="title">Title: </label>
         <input type="text" id="title" name="title" size="40"/>
     </div>

Modified: trunk/examples/CatPaste/root/paste/view.tt
===================================================================
--- trunk/examples/CatPaste/root/paste/view.tt	2007-08-09 09:36:13 UTC (rev 6633)
+++ trunk/examples/CatPaste/root/paste/view.tt	2007-08-09 20:59:22 UTC (rev 6634)
@@ -1,5 +1,5 @@
 [% page.stylesheets.push('kate.css') %]
-<h2>[% paste.title %] ([% paste.type %])</h2>
+<h2>[% paste.title %] ([% paste.type %]) from [% paste.author %] ([% paste.ip_address %])</h2>
 <div class="contents">
  <pre>[% paste.contents(c, c.req.params.no_highlight) %]</pre>
 </div>




More information about the Catalyst-commits mailing list