[Catalyst-commits] r6303 - in trunk/Catalyst-Controller-PathArgs: . examples examples/MyApp/lib/MyApp/Controller examples/MyApp/lib/MyApp/Controller/Book lib/Catalyst/Controller

zby at dev.catalyst.perl.org zby at dev.catalyst.perl.org
Mon Apr 23 11:23:27 GMT 2007


Author: zby
Date: 2007-04-23 11:23:22 +0100 (Mon, 23 Apr 2007)
New Revision: 6303

Added:
   trunk/Catalyst-Controller-PathArgs/examples/
   trunk/Catalyst-Controller-PathArgs/examples/MyApp/
   trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book.pm
   trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book/Edition.pm
   trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Root.pm
Removed:
   trunk/Catalyst-Controller-PathArgs/MyApp/
   trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book.pm
   trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book/Edition.pm
   trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Root.pm
Modified:
   trunk/Catalyst-Controller-PathArgs/Makefile.PL
   trunk/Catalyst-Controller-PathArgs/lib/Catalyst/Controller/PathArgs.pm
Log:
MyApp moved to examples


Modified: trunk/Catalyst-Controller-PathArgs/Makefile.PL
===================================================================
--- trunk/Catalyst-Controller-PathArgs/Makefile.PL	2007-04-19 20:07:50 UTC (rev 6302)
+++ trunk/Catalyst-Controller-PathArgs/Makefile.PL	2007-04-23 10:23:22 UTC (rev 6303)
@@ -6,9 +6,10 @@
 WriteMakefile(
     NAME         => 'Catalyst::Controller::PathArgs',
     VERSION_FROM => 'lib/Catalyst/Controller/PathArgs.pm', # finds \$VERSION
-    AUTHOR       => 'HASH(0x60d210) (a.u.thor at a.galaxy.far.far.away)',
+    AUTHOR       => 'Zbigniew Lukasiak',
     ABSTRACT     => 'Module abstract (<= 44 characters) goes here',
     PREREQ_PM    => {
                      'Test::Simple' => 0.44,
+                     'Catalyst::Runtime' => 5.7007,
                     },
 );

Copied: trunk/Catalyst-Controller-PathArgs/examples/MyApp (from rev 6298, trunk/Catalyst-Controller-PathArgs/MyApp)

Deleted: trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book/Edition.pm
===================================================================
--- trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book/Edition.pm	2007-04-18 15:13:36 UTC (rev 6298)
+++ trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book/Edition.pm	2007-04-23 10:23:22 UTC (rev 6303)
@@ -1,14 +0,0 @@
-package MyApp::Controller::Book::Edition;
-
-use base 'Catalyst::Controller::PathArgs';
-use strict;
-use warnings;
-
-sub view : PathArgs(0) EndPoint {
-    my ( $self, $c, $id ) = @_;
-    my $text = $c->stash->{edition};
-    $c->res->body( ">$text<" );
-}
-
-1;
-

Copied: trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book/Edition.pm (from rev 6301, trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book/Edition.pm)
===================================================================
--- trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book/Edition.pm	                        (rev 0)
+++ trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book/Edition.pm	2007-04-23 10:23:22 UTC (rev 6303)
@@ -0,0 +1,26 @@
+package MyApp::Controller::Book::Edition;
+
+use base 'Catalyst::Controller::PathArgs';
+use strict;
+use warnings;
+
+sub view : PathArgs(0) EndPoint {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book::Edition controller's chained view action. ";
+    $out .= "The book with id = " . $c->stash->{book}->{id} . " is on the stash. ";
+    $out .= "It's edition with id = " . $c->stash->{edition}->{id} . " is on the stash. ";
+    $out .= 'It\'s text is "' . $c->stash->{edition}->{text} . '" .';
+    $c->response->body( $out );
+}
+
+sub chained_index : PathPart('') PathArgs(0) EndPoint {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book::Edition controller's chained index action. ";
+    $out .= "The book with id = " . $c->stash->{book}->{id} . " is on the stash. ";
+    $out .= "It's edition with id = " . $c->stash->{edition}->{id} . " is on the stash.";
+    $c->response->body( $out );
+}
+
+
+1;
+

Deleted: trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book.pm
===================================================================
--- trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book.pm	2007-04-18 15:13:36 UTC (rev 6298)
+++ trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book.pm	2007-04-23 10:23:22 UTC (rev 6303)
@@ -1,14 +0,0 @@
-package MyApp::Controller::Book;
-
-use base 'Catalyst::Controller::PathArgs';
-use strict;
-use warnings;
-
-sub edition : PathArgs(1) {
-    my ( $self, $c, $id ) = @_;
-    my $edition = $c->stash->{book}->{$id};
-    $c->stash->{edition} = $edition;
-}
-
-1;
-

Copied: trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book.pm (from rev 6301, trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Book.pm)
===================================================================
--- trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book.pm	                        (rev 0)
+++ trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Book.pm	2007-04-23 10:23:22 UTC (rev 6303)
@@ -0,0 +1,34 @@
+package MyApp::Controller::Book;
+
+use base 'Catalyst::Controller::PathArgs';
+use strict;
+use warnings;
+
+sub edition : PathArgs(1) {
+    my ( $self, $c, $id ) = @_;
+    my $edition = $c->stash->{book}->{$id};
+    $c->stash->{edition} = $edition;
+}
+
+sub edition_mascarade: PathPart('edition') PathArgs(0) EndPoint {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book controller's edition_mascarade action with 0 params.";
+    $out .= "The book with id = " . $c->stash->{book}->{id} . " is on stash";
+    $c->response->body( $out );
+}
+
+sub index : Private {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book controller's index action.";
+    $c->response->body( $out );
+}
+
+sub chained_index : PathPart('') PathArgs(0) EndPoint {
+    my ( $self, $c ) = @_;
+    my $out = "This is the MyApp::Controller::Book controller's chained index action.";
+    $out .= "The book with id = " . $c->stash->{book}->{id} . " is on stash";
+    $c->response->body( $out );
+}
+
+1;
+

Deleted: trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Root.pm	2007-04-18 15:13:36 UTC (rev 6298)
+++ trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Root.pm	2007-04-23 10:23:22 UTC (rev 6303)
@@ -1,60 +0,0 @@
-package MyApp::Controller::Root;
-
-use strict;
-use warnings;
-use base 'Catalyst::Controller::PathArgs';
-
-#
-# Sets the actions in this controller to be registered with no prefix
-# so they function identically to actions created in MyApp.pm
-#
-__PACKAGE__->config->{namespace} = '';
-
-=head1 NAME
-
-MyApp::Controller::Root - Root Controller for MyApp
-
-=head1 DESCRIPTION
-
-[enter your description here]
-
-=head1 METHODS
-
-=cut
-
-=head2 default
-
-=cut
-
-sub default : Private {
-    my ( $self, $c ) = @_;
-
-    # Hello World
-    $c->response->body( $c->welcome_message );
-}
-
-our $books = {
-1 => {
-1 => 'Book 1 Edition 1',
-2 => 'Book 1 Edition 2',
-3 => 'Book 1 Edition 3',
-},
-2 => {
-1 => 'Book 2 Edition 1',
-2 => 'Book 2 Edition 2',
-3 => 'Book 2 Edition 3',
-},
-3 => {
-1 => 'Book 3 Edition 1',
-2 => 'Book 3 Edition 2',
-3 => 'Book 3 Edition 3',
-}
-};
-
-sub book : PathArgs(1) {
-    my ( $self, $c, $id ) = @_;
-    my $book = $books->{$id};
-    $c->stash->{book} = $book;
-}
-
-1;

Copied: trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Root.pm (from rev 6301, trunk/Catalyst-Controller-PathArgs/MyApp/lib/MyApp/Controller/Root.pm)
===================================================================
--- trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Root.pm	                        (rev 0)
+++ trunk/Catalyst-Controller-PathArgs/examples/MyApp/lib/MyApp/Controller/Root.pm	2007-04-23 10:23:22 UTC (rev 6303)
@@ -0,0 +1,61 @@
+package MyApp::Controller::Root;
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller::PathArgs';
+
+#
+# Sets the actions in this controller to be registered with no prefix
+# so they function identically to actions created in MyApp.pm
+#
+__PACKAGE__->config->{namespace} = '';
+
+=head1 NAME
+
+MyApp::Controller::Root - Root Controller for MyApp
+
+=head1 DESCRIPTION
+
+[enter your description here]
+
+=head1 METHODS
+
+=cut
+
+=head2 default
+
+=cut
+
+sub index : Private {
+    my ( $self, $c ) = @_;
+    $c->response->body( "This is the MyApp::Controller::Root controller's index action" );
+}
+
+our $books = {
+1 => {
+id => 1,
+1 => { id => 1, text => 'Book 1 Edition 1' },
+2 => { id => 2, text => 'Book 1 Edition 2' },
+3 => { id => 3, text => 'Book 1 Edition 3' },
+},
+2 => { 
+id =>  2,
+1 => { id => 1, text => 'Book 2 Edition 1' },
+2 => { id => 2, text => 'Book 2 Edition 2' },
+3 => { id => 3, text => 'Book 2 Edition 3' },
+},
+3 => { 
+id =>  3,
+1 => { id => 1, text => 'Book 3 Edition 1' },
+2 => { id => 2, text => 'Book 3 Edition 2' },
+3 => { id => 3, text => 'Book 3 Edition 3' },
+}
+};
+
+sub book : PathArgs(1) {
+    my ( $self, $c, $id ) = @_;
+    my $book = $books->{$id};
+    $c->stash->{book} = $book;
+}
+
+1;

Modified: trunk/Catalyst-Controller-PathArgs/lib/Catalyst/Controller/PathArgs.pm
===================================================================
--- trunk/Catalyst-Controller-PathArgs/lib/Catalyst/Controller/PathArgs.pm	2007-04-19 20:07:50 UTC (rev 6302)
+++ trunk/Catalyst-Controller-PathArgs/lib/Catalyst/Controller/PathArgs.pm	2007-04-23 10:23:22 UTC (rev 6303)
@@ -1,7 +1,7 @@
 package Catalyst::Controller::PathArgs;
 use strict;
 use base 'Catalyst::Controller';
-use NEXT;
+use Class::C3;
 
 our $VERSION = '0.1';
 
@@ -18,7 +18,7 @@
             $attributes->{CaptureArgs} = [ $args_num->[0] ];
         }
     }
-    return $self->NEXT::create_action( %args );
+    return $self->next::method( %args );
 }
 
 
@@ -56,6 +56,9 @@
 EndPoint is needed to declare an ation as the end of the chain (in theory this
 should be computable - but for now I don't see any easy way to do that).
 
+This package uses L<Class::C3> this means that you cannot use NEXT in classes
+based on it - but C3 looks like a good replacement for NEXT.
+
 To declare that the book subroutine is the root chained action with one argument you
 need to declare it in the Root controller with:
 
@@ -73,17 +76,19 @@
 
   sub view : PathArgs(0) EndPoint {
 
-You can also mix PathArgs with PathPart.  For example if you wanted to have an
-action responding for the address "/book/$book_id/edition" you
-would need a subroutine called 'edition' in the Book controller, but there is
-already one routine called 'edition' in that controller.  What you can do in
-that case is make a sub with a different name and declare that from the outside
-it's name should be really 'edition':
+You can also mix PathArgs with PathPart (new in Catalyst 5.7007).  For example
+if you wanted to have an action responding for the address
+"/book/$book_id/edition" you would need a subroutine called 'edition' in the
+Book controller, but there is already one routine called 'edition' in that
+controller.  What you can do in that case is make a sub with a different name
+and declare that from the outside it's name should be really 'edition':
 
   sub edition_mascarade: PathPart('edition') PathArgs(0) EndPoint {
 
 yeah - you need to add EndPoint there as well.
 
+An example is included in the example directory of this distribution.
+
 Internally PathArgs and EndPoint are converted to 'Chained(.)' and appriopriate 
 CaptureArgs or Args attributes.  For more sophisticated chaining you might need
 to use L<Catalyst::DispatchType::Chained> directly.




More information about the Catalyst-commits mailing list