Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Multiple Chain Actions

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


dwueppel at gmail

Jul 16, 2009, 8:30 AM

Post #1 of 4 (896 views)
Permalink
Multiple Chain Actions

So I've been trying to write this application that has some of the
functionality provided with a JSON interface. Originally I was using a
separate module to provide the JSON interface, but then realised that
all I was doing was forwarding all of the requests to other modules.

I then found that I could do what I wanted by using chaining and a new
view. So I created my own Catalyst::View::JSON module and used that to
provide a the JSON view of the interface. I was then going to add a
chain so that I could selectively choose which methods I would enable in
the JSON interface. I created a method like this:

sub json : Chained('/') ChainedArgs(0) {
my ($self, $c) = @_;

$c->stash->{view_method} = 'JSON';
}

I then check in my end method if I'm supposed to show the page as JSON
or my default method.

At any rate I got all of that to work and then I came up to a snag. The
big problem is that I want to be able to use the same code to perform
the action in either the JSON view or the regular view. The issue is
that I can't seem to figure out how to get a multiple rooted chain. So I
want to be able to have these URLs access the same method:

/json/object/ID_VALUE/action
/object/ID_VALUE/action

And then use the initial json chain to determine if I should show the
page or show the JSON output.

Is this something that is possible? Should I even be using Chaining for
this? Any help would be appreciated.

--
Derek Wueppelmann


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


bobtfish at bobtfish

Jul 16, 2009, 12:22 PM

Post #2 of 4 (840 views)
Permalink
Re: Multiple Chain Actions [In reply to]

On 16 Jul 2009, at 16:30, Derek Wueppelmann wrote:
>
> sub json : Chained('/') ChainedArgs(0) {
> my ($self, $c) = @_;
>
> Is this something that is possible? Should I even be using Chaining
> for
> this? Any help would be appreciated.

Call your top level path part root, then inherit (or apply as a role)
the rest of the chain parts.

e.g.

package MyApp::Stuff;
use Moose::Role -traits => 'MethodAttributes';

sub thingie : Chained('root') PathPart('thingie') Args(0) {}


package MyApp::Controller::Root;
with 'MyApp::Stuff';
sub root : Chained('/') PathPart('') CaptureArgs(0) {}

package MyApp::Controller::JSON;
with 'MyApp::Stuff';
sub root : Chained('/') PathPart('json') CaptureArgs(0) {}

Will give you:

/thingie
and
/json/thingie

Cheers
t0m


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alexander.hartmaier at t-systems

Jul 17, 2009, 9:29 AM

Post #3 of 4 (825 views)
Permalink
Re: Multiple Chain Actions [In reply to]

Why not use the same uri and check the Accept header?

Am Donnerstag, den 16.07.2009, 21:22 +0200 schrieb Tomas Doran:
> On 16 Jul 2009, at 16:30, Derek Wueppelmann wrote:
> >
> > sub json : Chained('/') ChainedArgs(0) {
> > my ($self, $c) = @_;
> >
> > Is this something that is possible? Should I even be using Chaining
> > for
> > this? Any help would be appreciated.
>
> Call your top level path part root, then inherit (or apply as a role)
> the rest of the chain parts.
>
> e.g.
>
> package MyApp::Stuff;
> use Moose::Role -traits => 'MethodAttributes';
>
> sub thingie : Chained('root') PathPart('thingie') Args(0) {}
>
>
> package MyApp::Controller::Root;
> with 'MyApp::Stuff';
> sub root : Chained('/') PathPart('') CaptureArgs(0) {}
>
> package MyApp::Controller::JSON;
> with 'MyApp::Stuff';
> sub root : Chained('/') PathPart('json') CaptureArgs(0) {}
>
> Will give you:
>
> /thingie
> and
> /json/thingie
>
> Cheers
> t0m
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
--
LG Alex


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


dwueppel at gmail

Jul 17, 2009, 1:53 PM

Post #4 of 4 (822 views)
Permalink
Re: Multiple Chain Actions [In reply to]

On Thu, 2009-07-16 at 20:22 +0100, Tomas Doran wrote:
> package MyApp::Controller::JSON;
> with 'MyApp::Stuff';
> sub root : Chained('/') PathPart('json') CaptureArgs(0) {}
>
> Will give you:
>
> /thingie
> and
> /json/thingie

This seems to be a decent option. However this will result in a fair
number of mostly empty modules being created. For example to get:

/object/$ID/update
/json/object/$ID/update

I would have to create a module that just contained:

package MyApp::Controller::JSON::Object;
with 'MyApp::ObjectStuff';

sub root : Chained('/') PathPart('json/object') CaptureArgs(0) {}

Since there will be nothing else to add to this, in most cases.

Is there a way to use multiple methods to achieve something similar.
Somting like this:

sub root : Chained('/json') PathPart('object') ChainedArgs(0) { ... }

sub update : Chained('root') PathPart('update') Args(0) {
$c->forward(...)
}

sub update_json : Chained('object') Args(0) {
$c->forward(...)
}

--
o) Derek Wueppelmann (o
(D . dwueppel [at] gmail D).
((` http://www.monkeynet.ca ( ) `



_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.