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

Mailing List Archive: Catalyst: Dev

Developing action_uri() for Catalyst 5.80

 

 

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


jgottshall at capwiz

May 28, 2008, 12:50 PM

Post #1 of 22 (5668 views)
Permalink
Developing action_uri() for Catalyst 5.80

After reviewing the list archives (both users and dev), it appears that
there is some interest in developing an action_uri() method that would
Do The Right Thing given a private path and any necessary captures. I've
been given a tuit at $work to do some dev on this, so that I can pass it
along to my programmers as a "best practice", especially in template
construction. This being my first attempt at a contrib to this project,
I'm gonna need a little help to get going, though.

Background: I raised this question on the cat users list about a year
and half ago, in the context of getting URIs for Chained actions:

http://www.gossamer-threads.com/lists/catalyst/users/12260

At that point, mst affirmed that it was a point of interest and invited
me onto the dev list (sorry it took me so long!) And interestingly, it
looks like Ash had put out an RFC for the same thing a few months
earlier on the dev list, but that thread seems to have been warnocked
(or talked out on IRC?):

http://www.gossamer-threads.com/lists/catalyst/dev/10213

Anyway, the most concrete work so far seems to have been done by Simon
Elliott in his '07 Advent Calendar entry:

http://catalyst.perl.org/calendar/2007/13

And mst has recently suggested that something like this is worth
considering for the 5.80 release:

http://www.gossamer-threads.com/lists/catalyst/dev/17578#17578

So, I guess now I need a nudge in the right direction. Should I go ahead
and rustle up a first run at the code and post it here for comments?

Thanks for your patience as I get acclimated to the dev process!

Jason

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


ash_cpan at firemirror

May 29, 2008, 3:04 AM

Post #2 of 22 (5555 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On 28 May 2008, at 20:50, Jason Gottshall wrote:

> After reviewing the list archives (both users and dev), it appears
> that
> there is some interest in developing an action_uri() method that would
> Do The Right Thing given a private path and any necessary captures.
> I've
> been given a tuit at $work to do some dev on this, so that I can
> pass it
> along to my programmers as a "best practice", especially in template
> construction. This being my first attempt at a contrib to this
> project,
> I'm gonna need a little help to get going, though.
>
> Background: I raised this question on the cat users list about a year
> and half ago, in the context of getting URIs for Chained actions:
>
> http://www.gossamer-threads.com/lists/catalyst/users/12260
>
> At that point, mst affirmed that it was a point of interest and
> invited
> me onto the dev list (sorry it took me so long!) And interestingly, it
> looks like Ash had put out an RFC for the same thing a few months
> earlier on the dev list, but that thread seems to have been warnocked
> (or talked out on IRC?):

I forget what happened to the thread. I think Matt's response was die
if something invalid is passed.

The reason i did an RFC is cos i have had an uri_for_action sitting in
MyApp.pm for about 2 years now :)

Here is my code. It probably only works well for chained actions :) Oh
and there aren't really any tests for it other than my app still works.

sub uri_for_action {
my $c = shift;
my $priv_path = shift;

my $orig_path = $priv_path;

my $action;
# Action object
if (blessed($priv_path) && $priv_path->isa('Catalyst::Action') ) {
$action = $priv_path;
}
# Relative action paths
elsif ($priv_path =~ s!^\./!!) {
$action = $c->controller->action_for($priv_path);
} else {
$priv_path = $c->namespace . "/$priv_path" unless $priv_path =~
m[^/];
$action = $c->dispatcher->get_action_by_path($priv_path);
}

croak "Invalid action path $orig_path" unless $action;

if ($action && (my ($chain) = @{$action->attributes->{Chained} ||
[] }) ) {
my @actions = ($action);

my @captures;

while ($chain ne '/') {
my $action = $c->dispatcher->get_action_by_path($chain);
die "Unable to find action in chain: $chain" unless
$action;

unshift @actions, $action;
($chain) = @{$action->attributes->{Chained}};
}


my @captures_in = splice @_;
@captures_in = @{$captures_in[0]} if (ref
$captures_in[0]||'') eq 'ARRAY';

foreach my $action (@actions) {
last unless exists $action->attributes->{CaptureArgs};
my $cap_args = $action->attributes->{CaptureArgs}[0];
carp("Not enough captures passed to uri_for_action")
unless $cap_args <= scalar @captures_in;

push @captures, splice(@captures_in, 0, $cap_args);
}

@_ = \@captures;
push @_, @captures_in if scalar @captures_in;

}
$c->uri_for($action, @_);
}

__END__

-ash



_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


pagaltzis at gmx

May 29, 2008, 3:41 AM

Post #3 of 22 (5541 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

* Ash Berlin <ash_cpan [at] firemirror> [2008-05-29 12:10]:
> Here is my code. It probably only works well for chained
> actions :) Oh and there aren't really any tests for it other
> than my app still works.

That’s a lot of stuff and much of it has a faint whiff of being
in the wrong place, although being that I know the Cat internals
only selectively so far, I can’t be sure.

For reference, here is what I have in MyApp.pm:

sub uri_for {
my $self = shift;
my ( $path ) = @_;

if ( not Scalar::Util::blessed( $path ) and 'ARRAY' eq ref $path ) {
unshift @_, $self->dispatcher->get_action_by_path( shift @$path );
}

my $uri = $self->NEXT::uri_for( @_ );

return $uri;
}

This exploits the fact that an unblessed arrayref as the first
argument to Catalyst’s `uri_for` is an error to provide the
following syntactic sugar:

# before
$c->uri_for( $c->dispatcher->get_action_by_path( '/foo/bar'), [ 23 ] )

# after
$c->uri_for( [ '/foo/bar', 23 ] )

As is it doesn’t deal with things like relative actions paths and
the like at all, but those things seem to me to properly belong
in a method like `get_action_by_path`, rather than buried inside
a URI construction method where application code cannot use it
for any other purpose. (Eg. `get_action_by_path` could take an
optional second argument that could be a controller instance or
namespace, which would mean “if not absolute, resolve the path
relative to this controller or namespace.”)

--
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


jgottshall at capwiz

Jun 6, 2008, 1:21 PM

Post #4 of 22 (5514 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

I'd like to establish consensus on the calling signature (and method
name) for action_uri(). Based on the code I've seen from others (and my
own bias), here's one option:

$c->action_uri('/private/path/to/action', \@captures_if_any,
\%query_params);

Thoughts?

Jason



_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


jshirley at gmail

Jun 6, 2008, 1:56 PM

Post #5 of 22 (5504 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On Fri, Jun 6, 2008 at 1:21 PM, Jason Gottshall <jgottshall [at] capwiz> wrote:
> I'd like to establish consensus on the calling signature (and method
> name) for action_uri(). Based on the code I've seen from others (and my
> own bias), here's one option:
>
> $c->action_uri('/private/path/to/action', \@captures_if_any,
> \%query_params);
>
> Thoughts?
>
> Jason
>

My only thought is to not use strings to denote action paths.
$c->controller('MyController')->action_for('action') has served me
better.

I may be in the minority on this, but I generally dislike using
stringified private paths. It also seems if you pass in an $action
object, rather than a scalar string, it can help the dispatcher.

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


ash_cpan at firemirror

Jun 6, 2008, 2:18 PM

Post #6 of 22 (5515 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On 6 Jun 2008, at 21:56, J. Shirley wrote:

> On Fri, Jun 6, 2008 at 1:21 PM, Jason Gottshall
> <jgottshall [at] capwiz> wrote:
>> I'd like to establish consensus on the calling signature (and method
>> name) for action_uri(). Based on the code I've seen from others
>> (and my
>> own bias), here's one option:
>>
>> $c->action_uri('/private/path/to/action', \@captures_if_any,
>> \%query_params);

How (if at all) are you differentiating between captures and
arguments. I.e. take the following

sub base : Chained('/') CaptureArgs(2) { }

sub my_action : Chained('base') Args(3) { }

Currently to get the url /base/1/43/my_action/a/b/c you'd have to do

$c->uri_for($c->action('my_action'), [1, 43], 'a', 'b', 'c');

Which is... less than ideal. I'd much rather see captures and argument
just handled as @params. Thus:

$c->action_uri('/my_action', 1,43 'a',' 'b', 'c');

or

$c->action_uri('/my_action', 1,43 'a',' 'b', 'c', { query =>
'param' } );


Is my vote. Oh and make sure that if you pass an invalid path, number
of captures or args that you die with an error rather than just
blowing up. Returning undef is more hassle than its worth IMO.

>>
>>
>> Thoughts?
>>
>> Jason
>>
>
> My only thought is to not use strings to denote action paths.
> $c->controller('MyController')->action_for('action') has served me
> better.
>
> I may be in the minority on this, but I generally dislike using
> stringified private paths. It also seems if you pass in an $action
> object, rather than a scalar string, it can help the dispatcher.

All well and good in principle - but I think its more verbose then it
needs to be. If you don't want to user the / seperated private path
that is common everywhere, why not take msts suggestion (?) and make
'MyController->action' work as a private path?

-ash

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


pagaltzis at gmx

Jun 6, 2008, 5:47 PM

Post #7 of 22 (5503 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

* J. Shirley <jshirley [at] gmail> [2008-06-06 23:00]:
> My only thought is to not use strings to denote action paths.
> $c->controller('MyController')->action_for('action') has served
> me better.

Better how? You’re still passing strings, the only difference is
you’re passing two of them using a much more verbose syntax.

I’m not particularly wedded to the specific syntax, though, as
far as I care it might just as well be `MyController::action` or
`MyController->action` instead of `/mycontroller/action`, per the
recent discussion elsewhere.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


jshirley at gmail

Jun 7, 2008, 8:51 AM

Post #8 of 22 (5501 views)
Permalink
Re: Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On Fri, Jun 6, 2008 at 5:47 PM, Aristotle Pagaltzis <pagaltzis [at] gmx> wrote:
> * J. Shirley <jshirley [at] gmail> [2008-06-06 23:00]:
>> My only thought is to not use strings to denote action paths.
>> $c->controller('MyController')->action_for('action') has served
>> me better.
>
> Better how? You're still passing strings, the only difference is
> you're passing two of them using a much more verbose syntax.
>
> I'm not particularly wedded to the specific syntax, though, as
> far as I care it might just as well be `MyController::action` or
> `MyController->action` instead of `/mycontroller/action`, per the
> recent discussion elsewhere.
>
> Regards,
> --
> Aristotle Pagaltzis // <http://plasmasturm.org/>
>

I'm not sure I understand your point. If you're saying that it is all
the same to uri_for, you are wrong.
$c->controller('Foo')->action_for('action') isa Catalyst::Action
object, which stringifies to $action->reverse. This, combined with
the special handling in uri_for for Catalyst::Action objects make it
superior.

If you are saying that $c->controller("Foo")->action_for('bar') is the
same as '/foo/bar' then... well, I am just glad we don't work on the
same code bases :)

But, regardless of all the above, I should correct and clarify my
statement that I like the admittedly verbose
$c->controller('Foo')->action_for('bar') syntax. Instead, I dislike
passing strings. As long as the $path bit is a Catalyst::Action
object, I think any solution is fine.

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


pagaltzis at gmx

Jun 7, 2008, 9:09 AM

Post #9 of 22 (5495 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

* J. Shirley <jshirley [at] gmail> [2008-06-07 17:55]:
> On Fri, Jun 6, 2008 at 5:47 PM, Aristotle Pagaltzis <pagaltzis [at] gmx> wrote:
> > * J. Shirley <jshirley [at] gmail> [2008-06-06 23:00]:
> >> My only thought is to not use strings to denote action
> >> paths. $c->controller('MyController')->action_for('action')
> >> has served me better.
> >
> > Better how? You're still passing strings, the only difference
> > is you're passing two of them using a much more verbose
> > syntax.
> >
> > I'm not particularly wedded to the specific syntax, though,
> > as far as I care it might just as well be
> > `MyController::action` or `MyController->action` instead of
> > `/mycontroller/action`, per the recent discussion elsewhere.
>
> I'm not sure I understand your point. If you're saying that it
> is all the same to uri_for, you are wrong.
> $c->controller('Foo')->action_for('action') isa
> Catalyst::Action object, which stringifies to $action->reverse.
> This, combined with the special handling in uri_for for
> Catalyst::Action objects make it superior.
>
> If you are saying that $c->controller("Foo")->action_for('bar')
> is the same as '/foo/bar' then... well, I am just glad we don't
> work on the same code bases :)
>
> But, regardless of all the above, I should correct and clarify
> my statement that I like the admittedly verbose
> $c->controller('Foo')->action_for('bar') syntax. Instead, I
> dislike passing strings. As long as the $path bit is a
> Catalyst::Action object, I think any solution is fine.

I utilize `$c->dispatcher->get_action_by_path` so I pass in a
string, and an action object comes out.

You utilize `$c->controller` and `$ctrl->action_for` so you pass
in two strings in sequence, and an action object comes out.

In what way is the latter preferrable to the former?

(There is one way: private paths use non-Perl syntax, which as I
said I’m not particularly enthused about.)

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


dbix-class at trout

Jun 8, 2008, 10:34 AM

Post #10 of 22 (5491 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On Fri, Jun 06, 2008 at 04:21:01PM -0400, Jason Gottshall wrote:
> I'd like to establish consensus on the calling signature (and method
> name) for action_uri(). Based on the code I've seen from others (and my
> own bias), here's one option:
>
> $c->action_uri('/private/path/to/action', \@captures_if_any,
> \%query_params);

$c->action_uri($action_obj, \@captures, \@args, \%query)

$c->action_uri([ $controller_name, $action_name ], \@captures, \@args, \%query)
(calls $c->controller($controller_name)->action_for($action_name) to get obj)

$c->action_uri($action_name, @captures, \@args, \%query)
(calls $c->controller->action_for($action_name) to get obj)

Note that this implementation would allow us to extend $action_name to allow
either a /foo/bar, foo:bar, foo.bar or Foo->bar syntax later, but we don't
have to provide one in the first cut, which gets round most of the worrying.

Notice that there's no real DWIMing on signatures here beyond the initial
part - the arg list is -always- four elements (though presumably later
ones can be left off).

The thing that I wonder about though is: Do we not want to provide some
mechanism to say "the same captures as the current request -plus- this one"
or "-less- this one" or "-except- with this different last one" or similar?
(and same for args)

--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


pagaltzis at gmx

Jun 8, 2008, 12:17 PM

Post #11 of 22 (5486 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

* Matt S Trout <dbix-class [at] trout> [2008-06-08 19:35]:
> The thing that I wonder about though is: Do we not want to
> provide some mechanism to say "the same captures as the current
> request -plus- this one" or "-less- this one" or "-except- with
> this different last one" or similar? (and same for args)

For query params all you need to do is load URI::QueryParam, then
the URI object you get back has methods like `query_param_delete`
and `query_param_append`. I rely on that quite extensively for
some parts of my app.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


dbix-class at trout

Jun 9, 2008, 8:17 AM

Post #12 of 22 (5475 views)
Permalink
Re: Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On Sun, Jun 08, 2008 at 09:17:59PM +0200, Aristotle Pagaltzis wrote:
> * Matt S Trout <dbix-class [at] trout> [2008-06-08 19:35]:
> > The thing that I wonder about though is: Do we not want to
> > provide some mechanism to say "the same captures as the current
> > request -plus- this one" or "-less- this one" or "-except- with
> > this different last one" or similar? (and same for args)
>
> For query params all you need to do is load URI::QueryParam, then
> the URI object you get back has methods like `query_param_delete`
> and `query_param_append`. I rely on that quite extensively for
> some parts of my app.

But I'm talking about captures and args, neither of which is a query param.

--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


pagaltzis at gmx

Jun 9, 2008, 11:09 AM

Post #13 of 22 (5472 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

* Matt S Trout <dbix-class [at] trout> [2008-06-09 17:20]:
> On Sun, Jun 08, 2008 at 09:17:59PM +0200, Aristotle Pagaltzis wrote:
> > * Matt S Trout <dbix-class [at] trout> [2008-06-08 19:35]:
> > > The thing that I wonder about though is: Do we not want to
> > > provide some mechanism to say "the same captures as the
> > > current request -plus- this one" or "-less- this one" or
> > > "-except- with this different last one" or similar? (and
> > > same for args)
> >
> > For query params all you need to do is load URI::QueryParam,
> > then the URI object you get back has methods like
> > `query_param_delete` and `query_param_append`. I rely on that
> > quite extensively for some parts of my app.
>
> But I'm talking about captures and args, neither of which is a
> query param.

Oh! I thought that by args you meant query params, since I tend
to think of captures and args as the same thing, and you had
already mentioned captures.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


jgottshall at capwiz

Jun 9, 2008, 11:14 AM

Post #14 of 22 (5462 views)
Permalink
RE: Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On Monday, June 09, 2008 11:17 AM, Matt S Trout <dbix-class [at] trout>
wrote:

> On Sun, Jun 08, 2008 at 09:17:59PM +0200, Aristotle Pagaltzis wrote:
>> * Matt S Trout <dbix-class [at] trout> [2008-06-08 19:35]:
>>> The thing that I wonder about though is: Do we not want to
>>> provide some mechanism to say "the same captures as the current
>>> request -plus- this one" or "-less- this one" or "-except- with
>>> this different last one" or similar? (and same for args)
>>
>> For query params all you need to do is load URI::QueryParam, then
>> the URI object you get back has methods like `query_param_delete`
>> and `query_param_append`. I rely on that quite extensively for
>> some parts of my app.
>
> But I'm talking about captures and args, neither of which is
> a query param.

But why not a similar mechanism for captures args? What if
$c->req->captures and $c->req->args returned objects that implemented
basic list manipulation? Then, using methods provided by List::oo as an
example, you could do things like:

# one more capture, one less arg
$c->action_uri($action, $c->req->captures->ipush(123),
$c->req->args->ipop);

# swap out last capture (or arg)
$c->action_uri($action, $c->req->captures->ipop->ipush(123));
# also written as:
$c->action_uri($action, $c->req->captures->isplice(-1, 1, 123));

Jason

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


jgottshall at capwiz

Jun 9, 2008, 12:06 PM

Post #15 of 22 (5471 views)
Permalink
RE: Developing action_uri() for Catalyst 5.80 [In reply to]

On Friday, June 06, 2008 5:19 PM, Ash Berlin <ash_cpan [at] firemirror>
wrote:

> Oh and make sure that if you pass an invalid path, number
> of captures or args that you die with an error rather than just
> blowing up. Returning undef is more hassle than its worth IMO.

You're referring to the fact that uri_for() returns undef in these
situations? So action_uri() should include a re-implementation of the
underlying logic of uri_for() rather than delegating to it. Am I
interpreting that correctly?

Jason

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


ash_cpan at firemirror

Jun 9, 2008, 2:49 PM

Post #16 of 22 (5472 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On 9 Jun 2008, at 20:06, Jason Gottshall wrote:

> On Friday, June 06, 2008 5:19 PM, Ash Berlin <ash_cpan [at] firemirror>
> wrote:
>
>> Oh and make sure that if you pass an invalid path, number
>> of captures or args that you die with an error rather than just
>> blowing up. Returning undef is more hassle than its worth IMO.
>
> You're referring to the fact that uri_for() returns undef in these
> situations? So action_uri() should include a re-implementation of the
> underlying logic of uri_for() rather than delegating to it. Am I
> interpreting that correctly?
>
> Jason

It would be different logic anyway. It can be done without duplicating
code by checking the format/number of params before you hand off to
the dispatcher (which is what generates urls for actions)

-ash

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


catalyst at fadetoblack

Jun 10, 2008, 7:33 AM

Post #17 of 22 (5453 views)
Permalink
Re: Re: Developing action_uri() for Catalyst 5.80 [In reply to]

> * Matt S Trout <dbix-class [at] trout> [2008-06-08 19:35]:
>> The thing that I wonder about though is: Do we not want to
>> provide some mechanism to say "the same captures as the current
>> request -plus- this one" or "-less- this one" or "-except- with
>> this different last one" or similar? (and same for args)
>
> But why not a similar mechanism for captures args? What if
> $c->req->captures and $c->req->args returned objects that implemented
> basic list manipulation? Then, using methods provided by List::oo as an
> example, you could do things like:

They're a little verbose. Essentially though they're just a different way of
passing a listref/hashref into the method.

I'd certainly say you want these:

$c->action_uri($action_obj, \@captures, \@args, \%query) # Wot Matt said

$c->action_uri($action, undef, undef, undef); #use same caps/args/query as
current
$c->action_uri($action); #ditto

$c->action_uri($action, [], [], {}); # blank caps/args/query

As far as an interface to allow add/amend/remove. It would be fairly easy
for hashes as setting a key/value would either amend or create the pair, and
setting undef as a value could be the trigger to delete a pair. That would
work fine for the query, however I think trying to design an interface to do
something similar for the two lists would be uglier than just directly
altering the list itself.

Carl


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


dbix-class at trout

Jun 10, 2008, 8:34 AM

Post #18 of 22 (5457 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On Mon, Jun 09, 2008 at 03:06:21PM -0400, Jason Gottshall wrote:
> On Friday, June 06, 2008 5:19 PM, Ash Berlin <ash_cpan [at] firemirror>
> wrote:
>
> > Oh and make sure that if you pass an invalid path, number
> > of captures or args that you die with an error rather than just
> > blowing up. Returning undef is more hassle than its worth IMO.
>
> You're referring to the fact that uri_for() returns undef in these
> situations? So action_uri() should include a re-implementation of the
> underlying logic of uri_for() rather than delegating to it. Am I
> interpreting that correctly?

action_uri should be calling the dispatcher's uri_for_action method
directly, I think, and throw an exception on undef.

--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


jgottshall at capitoladvantage

Jun 10, 2008, 12:19 PM

Post #19 of 22 (5444 views)
Permalink
Re: Re: Developing action_uri() for Catalyst 5.80 [In reply to]

Carl Johnstone wrote:
> $c->action_uri($action, undef, undef, undef); #use same caps/args/query
> as current
> $c->action_uri($action); #ditto
>
> $c->action_uri($action, [], [], {}); # blank caps/args/query

Hmm, I'm not sure I like the idea of the default being to repeat the
current caps/args/query. I'd have thought it makes more sense to assume
there are NO caps/args/query if they're not supplied, since it's easy
enough to grab the current sets from the request object and pass them
along if that's what you really want. But I'm willing to hear arguments
that the goal of action_uri() should be to simplify the creation of URIs
that are in some way related to the current path.

Jason

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


jgottshall at capitoladvantage

Jun 10, 2008, 12:40 PM

Post #20 of 22 (5449 views)
Permalink
Re: Developing action_uri() for Catalyst 5.80 [In reply to]

Ash Berlin wrote:
> On 9 Jun 2008, at 20:06, Jason Gottshall wrote:
>> On Friday, June 06, 2008 5:19 PM, Ash Berlin <ash_cpan [at] firemirror>
>> wrote:
>>
>>> Oh and make sure that if you pass an invalid path, number
>>> of captures or args that you die with an error rather than just
>>> blowing up. Returning undef is more hassle than its worth IMO.
>>
>> You're referring to the fact that uri_for() returns undef in these
>> situations? So action_uri() should include a re-implementation of the
>> underlying logic of uri_for() rather than delegating to it. Am I
>> interpreting that correctly?
>>
>> Jason
>
> It would be different logic anyway. It can be done without duplicating
> code by checking the format/number of params before you hand off to the
> dispatcher (which is what generates urls for actions)

Yes, of course, it should call $dispatcher->uri_for_action(). That does
make sense. Now, as I look at that method, it delegates to the
uri_for_action() method of the appropriate dispatch type, and that's
where the logic lives for validating caps/args, failing with an undef
rather than an exception. But I can't remedy that without breaking
back-compat.

I guess I could factor out the caps/args validation in the dispatch
type. That would allow $dispatch_type->uri_for_action() to continue to
return undef on validation failure, but action_uri() could call the same
routine and die appropriately. Unfortunately that does mean that
successful validation will happen twice; I'm not sure how to avoid that,
or even if it's worth worrying about.

Jason


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


dbix-class at trout

Jun 11, 2008, 12:55 PM

Post #21 of 22 (5430 views)
Permalink
Re: Re: Developing action_uri() for Catalyst 5.80 [In reply to]

On Mon, Jun 09, 2008 at 02:14:00PM -0400, Jason Gottshall wrote:
> On Monday, June 09, 2008 11:17 AM, Matt S Trout <dbix-class [at] trout>
> wrote:
>
> > On Sun, Jun 08, 2008 at 09:17:59PM +0200, Aristotle Pagaltzis wrote:
> >> * Matt S Trout <dbix-class [at] trout> [2008-06-08 19:35]:
> >>> The thing that I wonder about though is: Do we not want to
> >>> provide some mechanism to say "the same captures as the current
> >>> request -plus- this one" or "-less- this one" or "-except- with
> >>> this different last one" or similar? (and same for args)
> >>
> >> For query params all you need to do is load URI::QueryParam, then
> >> the URI object you get back has methods like `query_param_delete`
> >> and `query_param_append`. I rely on that quite extensively for
> >> some parts of my app.
> >
> > But I'm talking about captures and args, neither of which is
> > a query param.
>
> But why not a similar mechanism for captures args? What if
> $c->req->captures and $c->req->args returned objects that implemented
> basic list manipulation? Then, using methods provided by List::oo as an
> example, you could do things like:
>
> # one more capture, one less arg
> $c->action_uri($action, $c->req->captures->ipush(123),
> $c->req->args->ipop);
>
> # swap out last capture (or arg)
> $c->action_uri($action, $c->req->captures->ipop->ipush(123));
> # also written as:
> $c->action_uri($action, $c->req->captures->isplice(-1, 1, 123));

or you could just

use Moose::Autobox;

$c->req->captures->splice(...)

:)

--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


jgottshall at capitoladvantage

Jun 11, 2008, 12:58 PM

Post #22 of 22 (5429 views)
Permalink
Re: Re: Developing action_uri() for Catalyst 5.80 [In reply to]

Matt S Trout wrote:
> On Mon, Jun 09, 2008 at 02:14:00PM -0400, Jason Gottshall wrote:
>> $c->action_uri($action, $c->req->captures->isplice(-1, 1, 123));
>
> or you could just
>
> use Moose::Autobox;
>
> $c->req->captures->splice(...)
>
> :)

/me needs to attend some Moose sessions at YAPC!


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev

Catalyst dev 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.