List Info

Thread: RFC: action_uri




RFC: action_uri
user name
2006-10-02 11:33:09
Hello

$c->uri_for($c->controller('Foo::Bar')->action_for(
'baz'), bla ) is used
a lot, and it's the correct way of specifying an URI for a
certain
action.

Would this alternative syntax be acceptable:
$c->action_uri('Foo::Bar->baz', bla); ?


I also thought of: $c->uri_for([qw/Foo::Bar, baz/], bla);
but action_uri seems cleaner.

Better naming suggestions are welcome 
I will prepare the patch according to your feedback.

Thanks,
-- 
Bogdan Lucaciu


_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

RFC: action_uri
user name
2006-10-02 12:23:30
* Bogdan Lucaciu <bogdanwiz.ro> [2006-10-02
13:35]:
> Would this alternative syntax be acceptable:
> $c->action_uri('Foo::Bar->baz', bla); ?

Hiding special syntax inside a string is a bad idea. Just
pass
two parameters.

    $c->action_uri_for( 'Foo::Bar' => baz => bla );

It is also conceivable to shift the problem around:

   
$c->controller('Foo::Bar')->action_for('baz')->uri_
for($c, bla);

As long as the original, but a bit more convenient, and
might be
useful in its own right in some contexts.

But I don’t like any of these options. They mix too many
different responsibilities. Hmm… I think a method on `$c`
much
like `controller` would be the cleanest approach:

    $c->uri_for($c->action_for('Foo::Bar', 'baz'),
bla);

Hmm, come to think of it, both `action_uri_for` and
`action_for`
should probably be added.


Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/&g
t;

_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

RFC: action_uri
user name
2006-10-02 13:21:34
A. Pagaltzis wrote:
> * Bogdan Lucaciu <bogdanwiz.ro> [2006-10-02
13:35]:
>> Would this alternative syntax be acceptable:
>> $c->action_uri('Foo::Bar->baz', bla); ?
> 
> Hiding special syntax inside a string is a bad idea.
Just pass
> two parameters.
> 
>     $c->action_uri_for( 'Foo::Bar' => baz =>
bla );

Or use the action private path -

$c->action_uri('/foo/bar/baz', $blah);

with

$c->action_uri([ 'Foo::Bar' => 'baz' ], $blah);

as a synonym.

> It is also conceivable to shift the problem around:
> 
>    
$c->controller('Foo::Bar')->action_for('baz')->uri_
for($c, bla);
> 
> As long as the original, but a bit more convenient, and
might be
> useful in its own right in some contexts.
> 
> But I don’t like any of these options. They mix too
many
> different responsibilities. Hmm… I think a method on
`$c` much
> like `controller` would be the cleanest approach:
> 
>     $c->uri_for($c->action_for('Foo::Bar',
'baz'), bla);
> 
> Hmm, come to think of it, both `action_uri_for` and
`action_for`
> should probably be added.

Not sure I agree if you're going to do it like that - it
hard-codes the 
concept of actions only existing under controllers, which
while "usual" 
practice isn't required to be the case.

-- 
      Matt S Trout       Offering custom development,
consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class
and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for
more information

+ Help us build a better perl ORM: http://dbix
-class.shadowcatsystems.co.uk/ +

_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

RFC: action_uri
user name
2006-10-02 16:12:55
>    
$c->controller('Foo::Bar')->action_for('baz')->uri_
for($c, bla);

This is my favorite, although I would write:

   
$c->controller('Foo::Bar')->action('baz')->uri({key
=> "value"});

Basically I have two questions in my mind after reading your
proposed
syntax:

1) Why is there a distinction between controller and action
(controller
is just controller, action is action_for)
2) Why pass another Catalyst context to uri_for at the end?
(and again,
why the _for?)

I think I partially understand 1.  Theoretically, action_for
runs the
URI matching rules against the actions inside the
controller; i.e. baz
would map to action quux if quux looks like

    sub quux : LocalRegex('...') {}

I think 99% of the time people want that to happen, rather
than to refer
to the subroutine Foo::Bar::quux directly.

BTW, how does (will?) uri_for map Regex actions to URIs? 
Isn't that NP
complete?  (Haven't tried it.)

Regards,
Jonathan Rockway

-- 
package JAPH;use Catalyst
qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca
Rockway][$_].[split //,
";$;"]->[$_].q; ;for
1..4;$,=~s;^.;;;$,});$;->setup;

_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

RFC: action_uri
user name
2006-10-02 16:51:49
Jonathan Rockway wrote:
>>    
$c->controller('Foo::Bar')->action_for('baz')->uri_
for($c, bla);
> 
> This is my favorite, although I would write:
> 
>    
$c->controller('Foo::Bar')->action('baz')->uri({key
=> "value"});
> 
> Basically I have two questions in my mind after reading
your proposed
> syntax:
> 
> 1) Why is there a distinction between controller and
action (controller
> is just controller, action is action_for)

Because otherwise anybody with a controller method called
"action" would have 
been fucked trying to use it.

And given action_for was added for 5.70 I didn't fancy our
chances of nobody 
having such a method already 

-- 
      Matt S Trout       Offering custom development,
consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class
and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for
more information

+ Help us build a better perl ORM: http://dbix
-class.shadowcatsystems.co.uk/ +

_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

RFC: action_uri
user name
2006-10-02 18:44:46
--- Bogdan Lucaciu <bogdanwiz.ro> wrote:

> Hello
> 
>
$c->uri_for($c->controller('Foo::Bar')->action_for(
'baz'),
> bla ) is used
> a lot, and it's the correct way of specifying an URI
> for a certain
> action.
> 
> Would this alternative syntax be acceptable:
> $c->action_uri('Foo::Bar->baz', bla); ?
> 
> 
> I also thought of: $c->uri_for([qw/Foo::Bar, baz/],
> bla);
> but action_uri seems cleaner.
> 
> Better naming suggestions are welcome 
> I will prepare the patch according to your feedback.
> 

I'd try to make sure the default values work properly,
I do:

$c->controller->action_for('action_name') 

A lot when the current controller is the one I need
the action for.  Saves a lot of typing and I don't
think it increases imbiguity too much.  Catalyst is
reasonable consistent here $c->action defaults to the
current action as well.

So something like...

$c->action_uri;  #this actions URI
$c->action_uri->( '.'=>'action_name'); #current
controller, get the action for 'action_name'

The for completeness and to ease automation tools I'd
like:

$c->action_uri->('.'=>'.');

as meaning the same as $c->action_uri.


You'd need all the other goodies that $c->uri_for has,
such an easy way to reference capture chains and 
query parameters.  I have this kind of thing a lot:

$c->uri_for($c->controller->action_for('list'),
$c->captures->[0..1],
$c->request->query_parameters);

Not sure the new syntax would save me a lot of typing,
but it might make some people who where like me and
didn't realize that Catalyst had this really cool
feature until someone on the mailing list mentioned it
specifically to me.

--john


> Thanks,
> -- 
> Bogdan Lucaciu
> 
> 
> _______________________________________________
> Catalyst-dev mailing list
> Catalyst-devlists.rawmode.org
>
http://lists.rawmode.org/mailman/listinfo/catalyst-dev
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 

_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

RFC: action_uri
user name
2006-10-02 19:05:04
John Napiorkowski wrote:
> --- Bogdan Lucaciu <bogdanwiz.ro> wrote:
> 
>> Hello
>>
>>
>
$c->uri_for($c->controller('Foo::Bar')->action_for(
'baz'),
>> bla ) is used
>> a lot, and it's the correct way of specifying an
URI
>> for a certain
>> action.
>>
>> Would this alternative syntax be acceptable:
>> $c->action_uri('Foo::Bar->baz', bla); ?
>>
>>
>> I also thought of: $c->uri_for([qw/Foo::Bar,
baz/],
>> bla);
>> but action_uri seems cleaner.
>>
>> Better naming suggestions are welcome 
>> I will prepare the patch according to your
feedback.
>>
> 
> I'd try to make sure the default values work properly,
> I do:
> 
> $c->controller->action_for('action_name') 

If you're actually in the controller,
$self->action_for('name') seems like 
even less typing.

-- 
      Matt S Trout       Offering custom development,
consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class
and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for
more information

+ Help us build a better perl ORM: http://dbix
-class.shadowcatsystems.co.uk/ +

_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

RFC: action_uri
user name
2006-10-02 19:17:53
* Jonathan Rockway <jonjrock.us> [2006-10-02
18:15]:
> 2) Why pass another Catalyst context to uri_for at the
end?
> (and again, why the _for?)

The existing `uri_for` does its job by asking the
dispatcher.
I didn’t see a way of getting at the dispatcher instance
from
within an ::Action instance. My familiarity with the
internals
at this point is minor, though, so it may well be
unnecessary.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/&g
t;

_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

RFC: action_uri
user name
2006-10-02 23:33:59
--- Matt S Trout <dbix-classtrout.me.uk> wrote:

> John Napiorkowski wrote:
> > --- Bogdan Lucaciu <bogdanwiz.ro> wrote:
> > 
> >> Hello
> >>
> >>
> >
>
$c->uri_for($c->controller('Foo::Bar')->action_for(
'baz'),
> >> bla ) is used
> >> a lot, and it's the correct way of specifying
an
> URI
> >> for a certain
> >> action.
> >>
> >> Would this alternative syntax be acceptable:
> >> $c->action_uri('Foo::Bar->baz', bla); ?
> >>
> >>
> >> I also thought of:
$c->uri_for([qw/Foo::Bar,
> baz/],
> >> bla);
> >> but action_uri seems cleaner.
> >>
> >> Better naming suggestions are welcome 
> >> I will prepare the patch according to your
> feedback.
> >>
> > 
> > I'd try to make sure the default values work
> properly,
> > I do:
> > 
> > $c->controller->action_for('action_name') 
> 
> If you're actually in the controller,
> $self->action_for('name') seems like 
> even less typing.
> 

Thanks for the tip, learn something every time I read
the mailing list  -john

> -- 
>       Matt S Trout       Offering custom
> development, consultancy and support
>    Technical Director    contracts for Catalyst,
> DBIx::Class and BAST. Contact
> Shadowcat Systems Ltd.  mst (at)
> shadowcatsystems.co.uk for more information
> 
> + Help us build a better perl ORM:
> http://dbix
-class.shadowcatsystems.co.uk/ +
> 
> _______________________________________________
> Catalyst-dev mailing list
> Catalyst-devlists.rawmode.org
>
http://lists.rawmode.org/mailman/listinfo/catalyst-dev
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection
around 
http://mail.yahoo.com 

_______________________________________________
Catalyst-dev mailing list
Catalyst-devlists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev

[1-9]

about | contact  Other archives ( Real Estate discussion Medical topics )