[Catalyst-commits] r8921 - in trunk/examples/CatalystAdvent/root/2008: . pen

zarquon at dev.catalyst.perl.org zarquon at dev.catalyst.perl.org
Thu Dec 18 21:33:43 GMT 2008


Author: zarquon
Date: 2008-12-18 21:33:43 +0000 (Thu, 18 Dec 2008)
New Revision: 8921

Added:
   trunk/examples/CatalystAdvent/root/2008/18.pod
Removed:
   trunk/examples/CatalystAdvent/root/2008/pen/WrapCGI.pod
Log:
day 18

Copied: trunk/examples/CatalystAdvent/root/2008/18.pod (from rev 8920, trunk/examples/CatalystAdvent/root/2008/pen/WrapCGI.pod)
===================================================================
--- trunk/examples/CatalystAdvent/root/2008/18.pod	                        (rev 0)
+++ trunk/examples/CatalystAdvent/root/2008/18.pod	2008-12-18 21:33:43 UTC (rev 8921)
@@ -0,0 +1,110 @@
+=head1 WrapCGI: CGI.pm in your Catalyst app.
+
+L<Catalyst::Controller::WrapCGI> allows you to use CGI.pm directly in
+your Catalyst controller.
+
+A huge benefit of this is quick porting of a legacy CGI.pm application
+directly into a Catalyst skeleton in an almost cut and paste fashion.
+You B<still> have the full power of the Catalyst framework and you
+don't lose any of your CGI application's functionality.
+
+
+To demonstrate a quick WrapCGI application, we're going to write a
+pastebot using WrapCGI, Acme::Bleach (to keep our code clean :-) ) and
+for giggles, translate our application's output with
+Catalyst::Plugin::Acme::LOLCAT.
+
+=head2 Packing list
+
+=over 12
+
+=item C<Catalyst::Controller::WrapCGI>
+
+=item C<Acme::Bleach>
+
+=item C<Catalyst::Plugin::Acme::LOLCAT>
+
+=item C<Moose> Don't freak out, this is simply to create an accessor :-)
+
+=back
+
+Install, and we'll move on.
+
+=head2 Getting Started
+
+This article assumes you are familiar with creating a Catalyst
+application skeleton, so we're going to skip that part in this
+article.
+
+Your first step (after creating your application) is to create a
+controller called Paste.  You should also know how to do this, but for
+the sake of sanity, here's what it looks like:
+
+    perl script/myapp_create.pl controller Paste
+
+Next, open up this new controller in your favorite text editor and add
+the following lines:
+
+    use Moose;
+    use parent 'Catalyst::Controller::WrapCGI';
+
+    use CGI qw/:html3/;
+
+    has 'cgi' => (is =>'rw', isa =>'CGI', default => sub { CGI->new });
+
+If you're not familiar with Moose at all, you should get to be :-).
+All this line is saying is "create an accessor called 'cgi' that when
+called with $self->cgi defaults to an anonymous sub that creates a new
+CGI object".  Easy as pie :-)
+
+Add the following lines to your controller after you've absorbed up to
+here:
+
+ sub index :Path('/cgi-bin/paste.cgi')  {
+     my ( $self, $c ) = @_;
+     my $q = $self->cgi;
+     $self->cgi_to_response( $c, sub {  
+
+         print $q->header, $q->start_html('Clean your code!'),
+               $q->h1('Paste your code here'),
+               $q->start_form(
+                  -name   => 'paste',
+                  -action => $c->uri_for('/cgi-bin/bleachit.cgi'),
+               ),
+               $q->textarea (
+                 -name => 'code',
+                 -rows => '10',
+                 -cols => '80'
+               ),
+               $q->br,
+               $q->submit(
+                 -name    => 'translate',
+                 -value   => 'Paste it!',
+               ),
+               $q->end_form,
+               $q->end_html;
+     });
+
+ }
+
+ sub paste : Path("/cgi-bin/bleachit.cgi") {
+     my ($self, $c) = @_;
+     my $q = $self->cgi;
+
+     $self->cgi_to_response( $c, sub {
+
+         my $code = $q->param('code');
+         my $cleaned_string = eval "use Acme::Bleach; $code" . "";
+  
+         print $q->header, $q->start_html('Cleaned code'),
+         $q->h1("Your code, cleaned:"),
+         $q->pre($cleaned_string),
+         $q->end_html;
+     });
+
+ }
+
+
+That's *it*.  That's how WrapCGI integrates CGI into Catalyst.  
+
+Tada!

Deleted: trunk/examples/CatalystAdvent/root/2008/pen/WrapCGI.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2008/pen/WrapCGI.pod	2008-12-18 21:32:55 UTC (rev 8920)
+++ trunk/examples/CatalystAdvent/root/2008/pen/WrapCGI.pod	2008-12-18 21:33:43 UTC (rev 8921)
@@ -1,110 +0,0 @@
-=head1 WrapCGI: CGI.pm in your Catalyst app.
-
-L<Catalyst::Controller::WrapCGI> allows you to use CGI.pm directly in
-your Catalyst controller.
-
-A huge benefit of this is quick porting of a legacy CGI.pm application
-directly into a Catalyst skeleton in an almost cut and paste fashion.
-You B<still> have the full power of the Catalyst framework and you
-don't lose any of your CGI application's functionality.
-
-
-To demonstrate a quick WrapCGI application, we're going to write a
-pastebot using WrapCGI, Acme::Bleach (to keep our code clean :-) ) and
-for giggles, translate our application's output with
-Catalyst::Plugin::Acme::LOLCAT.
-
-=head2 Packing list
-
-=over 12
-
-=item C<Catalyst::Controller::WrapCGI>
-
-=item C<Acme::Bleach>
-
-=item C<Catalyst::Plugin::Acme::LOLCAT>
-
-=item C<Moose> Don't freak out, this is simply to create an accessor :-)
-
-=back
-
-Install, and we'll move on.
-
-=head2 Getting Started
-
-This article assumes you are familiar with creating a Catalyst
-application skeleton, so we're going to skip that part in this
-article.
-
-Your first step (after creating your application) is to create a
-controller called Paste.  You should also know how to do this, but for
-the sake of sanity, here's what it looks like:
-
-    perl script/myapp_create.pl controller Paste
-
-Next, open up this new controller in your favorite text editor and add
-the following lines:
-
-    use Moose;
-    use parent 'Catalyst::Controller::WrapCGI';
-
-    use CGI qw/:html3/;
-
-    has 'cgi' => (is =>'rw', isa =>'CGI', default => sub { CGI->new });
-
-If you're not familiar with Moose at all, you should get to be :-).
-All this line is saying is "create an accessor called 'cgi' that when
-called with $self->cgi defaults to an anonymous sub that creates a new
-CGI object".  Easy as pie :-)
-
-Add the following lines to your controller after you've absorbed up to
-here:
-
- sub index :Path('/cgi-bin/paste.cgi')  {
-     my ( $self, $c ) = @_;
-     my $q = $self->cgi;
-     $self->cgi_to_response( $c, sub {  
-
-         print $q->header, $q->start_html('Clean your code!'),
-               $q->h1('Paste your code here'),
-               $q->start_form(
-                  -name   => 'paste',
-                  -action => $c->uri_for('/cgi-bin/bleachit.cgi'),
-               ),
-               $q->textarea (
-                 -name => 'code',
-                 -rows => '10',
-                 -cols => '80'
-               ),
-               $q->br,
-               $q->submit(
-                 -name    => 'translate',
-                 -value   => 'Paste it!',
-               ),
-               $q->end_form,
-               $q->end_html;
-     });
-
- }
-
- sub paste : Path("/cgi-bin/bleachit.cgi") {
-     my ($self, $c) = @_;
-     my $q = $self->cgi;
-
-     $self->cgi_to_response( $c, sub {
-
-         my $code = $q->param('code');
-         my $cleaned_string = eval "use Acme::Bleach; $code" . "";
-  
-         print $q->header, $q->start_html('Cleaned code'),
-         $q->h1("Your code, cleaned:"),
-         $q->pre($cleaned_string),
-         $q->end_html;
-     });
-
- }
-
-
-That's *it*.  That's how WrapCGI integrates CGI into Catalyst.  
-
-Tada!




More information about the Catalyst-commits mailing list