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

Mailing List Archive: Catalyst: Users

Why no extra attributes on Private actions?

 

 

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


moseley at hank

Jan 22, 2008, 9:29 AM

Post #1 of 16 (1963 views)
Permalink
Why no extra attributes on Private actions?

In Catalyst::Controller register_actions() there's this code:

my $attrs = $self->_parse_attrs( $c, $method, @{ $cache->[1] } );
if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
$c->log->debug( 'Bad action definition "'
. join( ' ', @{ $cache->[1] } )
. qq/" for "$class->$method"/ )
if $c->debug;
next;
}

Why are no other attributes allowed if the action include the
"Private" attribute?


This came up because I'm using "SSL" to indicate actions that require
SSL:

sub secret : Local SSL {}


But, it would also be handy to be able to protect all actions below
a give controller via:

sub auto : Private SSL { 1 }


--
Bill Moseley
moseley [at] hank


_______________________________________________
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/


jon at jrock

Jan 22, 2008, 9:44 AM

Post #2 of 16 (1883 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Tue, 2008-01-22 at 09:29 -0800, Bill Moseley wrote:
> This came up because I'm using "SSL" to indicate actions that require
> SSL:
>
> sub secret : Local SSL {}
>
>
> But, it would also be handy to be able to protect all actions below
> a give controller via:
>
> sub auto : Private SSL { 1 }


I don't think this is a great idea, but if you insist, feel free to
override register_actions. (Personally I would use the ACL plugin to
implement the "only dispatchable to if SSL" logic.)

Regards,
Jonathan Rockway
Attachments: signature.asc (0.18 KB)


claco at chrislaco

Jan 22, 2008, 9:53 AM

Post #3 of 16 (1879 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

Bill Moseley wrote:
> In Catalyst::Controller register_actions() there's this code:
>
> my $attrs = $self->_parse_attrs( $c, $method, @{ $cache->[1] } );
> if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
> $c->log->debug( 'Bad action definition "'
> . join( ' ', @{ $cache->[1] } )
> . qq/" for "$class->$method"/ )
> if $c->debug;
> next;
> }
>
> Why are no other attributes allowed if the action include the
> "Private" attribute?
>
>
> This came up because I'm using "SSL" to indicate actions that require
> SSL:
>
> sub secret : Local SSL {}
>
>
> But, it would also be handy to be able to protect all actions below
> a give controller via:
>
> sub auto : Private SSL { 1 }
>
>

Why not just leave off Private altogether?

I did that with index/default all the time until I weend myself off of
them for Chained for just that reason.

Now, about the sub named 'index' being a special name that does evil
when you do sub index : Chained because is the most appropriate
name...... that's another story...

-=Chris
Attachments: signature.asc (0.18 KB)


moseley at hank

Jan 22, 2008, 10:27 AM

Post #4 of 16 (1885 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Tue, Jan 22, 2008 at 11:44:39AM -0600, Jonathan Rockway wrote:
>
> On Tue, 2008-01-22 at 09:29 -0800, Bill Moseley wrote:
> > This came up because I'm using "SSL" to indicate actions that require
> > SSL:
> >
> > sub secret : Local SSL {}
> >
> >
> > But, it would also be handy to be able to protect all actions below
> > a give controller via:
> >
> > sub auto : Private SSL { 1 }
>
>
> I don't think this is a great idea, but if you insist, feel free to
> override register_actions. (Personally I would use the ACL plugin to
> implement the "only dispatchable to if SSL" logic.)

I should know better to provide context with the question as then I
get an answer to the context instead of the question. ;)

Yes, perhaps the ACL plug is a better approach, but I'm curious why no
other attributes are allowed with Private -- what problem does that
bit of code I quoted solve?


BTW -- what specifically did you think of when you said you don't
think it's a great idea? Just that personally you would do it a
different way or that it was a fragile approach and if so in what way?




--
Bill Moseley
moseley [at] hank


_______________________________________________
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/


dbix-class at trout

Jan 22, 2008, 9:57 PM

Post #5 of 16 (1876 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Tue, Jan 22, 2008 at 12:53:49PM -0500, Christopher H. Laco wrote:
> Bill Moseley wrote:
> >In Catalyst::Controller register_actions() there's this code:
> >
> > my $attrs = $self->_parse_attrs( $c, $method, @{ $cache->[1] } );
> > if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
> > $c->log->debug( 'Bad action definition "'
> > . join( ' ', @{ $cache->[1] } )
> > . qq/" for "$class->$method"/ )
> > if $c->debug;
> > next;
> > }
> >
> >Why are no other attributes allowed if the action include the
> >"Private" attribute?
> >
> >
> >This came up because I'm using "SSL" to indicate actions that require
> >SSL:
> >
> > sub secret : Local SSL {}
> >
> >
> >But, it would also be handy to be able to protect all actions below
> >a give controller via:
> >
> > sub auto : Private SSL { 1 }
> >
> >
>
> Why not just leave off Private altogether?
>
> I did that with index/default all the time until I weend myself off of
> them for Chained for just that reason.
>
> Now, about the sub named 'index' being a special name that does evil
> when you do sub index : Chained because is the most appropriate
> name...... that's another story...

I foresee index and default going the fuck away for 5.80 unless you're in
compat mode.

Hate hate hate hate hate hate HATE.

(and :Private can fucking die while we're there too, probably we'll move to
recommending :Action which is what I tend to use to get around Private's
odd behaviour)

--
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/

_______________________________________________
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/


edencardim at gmail

Aug 15, 2009, 4:28 PM

Post #6 of 16 (1701 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Sat, Aug 15, 2009 at 3:44 PM, Bill Moseley<moseley [at] hank> wrote:
> Why does Catalyst::Controller not allow additional attributes on Private
> actions?
>
> Marcus added this code in r5558 back in November of 2006.
>
>   5558     marcus         if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
>   5558     marcus             $c->log->debug( 'Bad action definition "'
>
> Yes, I asked[1] this same question a year an a half ago and Jonathan was
> nice enough to recommend overriding register_actions if I wanted different
> behavior. But, that didn't answer my question. Unfortunately, there's no
> comments in the code, and the svn log for that change offers no hints.
>
> Is there a specific reason that Private actions may not have additional
> attributes?

You can achieve the same effect by using the :Action tag instead, as
mst suggested in reply to the same thread:
http://www.mail-archive.com/catalyst [at] lists/msg01413.html

--
Eden Cardim Need help with your Catalyst or DBIx::Class project?
Code Monkey http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://edenc.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
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/


moseley at hank

Aug 16, 2009, 10:40 AM

Post #7 of 16 (1687 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Sat, Aug 15, 2009 at 4:28 PM, Eden Cardim <edencardim [at] gmail> wrote:

>
> > Is there a specific reason that Private actions may not have additional
> > attributes?
>
> You can achieve the same effect by using the :Action tag instead, as
> mst suggested in reply to the same thread:
> http://www.mail-archive.com/catalyst [at] lists/msg01413.html



Yes, I read that back then. That wasn't my question, though. My question
was *why* Private actions cannot have additional attributes?
Why is there code to explicitly prevent additional attributes on Private
methods? Especially since there's a work-around by simply using :Action (or
just any attribute) to make a method into an action.

Perhaps only Marcus might be able to answer that if he added that code.

Further, if *any* attribute can make a method into an action, is there
chance at some point that only a pre-defined set of attribute values would
be valid? Not sure there is any reason to do this, but for example might
want to have sub attributes on methods that are *not* actions, too.




BTW -- :Action is mentioned in the docs at:

http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/Intro.pod#Controllers

But, the text says:

Note that you can also supply attributes via the Controller's config so long
> as you have at least one attribute on a subref to be exported (:Action is
> commonly used for this) - for example the following is equivalent to the
> same controller above:
>

That doesn't sound correct. I think just listing the method in config
"actions" is enough. That is,

__PACKAGE__->config( actions => { foo => { Path => 'bar' } } );
> sub foo {}
>

will work because configured "actions" method names are just pushed onto the
list of method names returned by
$meta->get_nearest_methods_with_attributes. No ":Action" (or any attribute)
required.




--
Bill Moseley
moseley [at] hank


onken at houseofdesign

Aug 17, 2009, 1:47 AM

Post #8 of 16 (1682 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

>
> __PACKAGE__->config( actions => { foo => { Path => 'bar' } } );
> sub foo {}

This has been introduced in 5.80006. The Catalyst-Manual just didn't
catch up with the changes.

cheers,

moritz

_______________________________________________
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/


moseley at hank

Aug 17, 2009, 6:57 AM

Post #9 of 16 (1668 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Sun, Aug 16, 2009 at 10:40 AM, Bill Moseley <moseley [at] hank> wrote:

>
>
> On Sat, Aug 15, 2009 at 4:28 PM, Eden Cardim <edencardim [at] gmail> wrote:
>
>>
>> > Is there a specific reason that Private actions may not have additional
>> > attributes?
>>
>> You can achieve the same effect by using the :Action tag instead, as
>> mst suggested in reply to the same thread:
>> http://www.mail-archive.com/catalyst [at] lists/msg01413.html
>
>
>
> My question was *why* Private actions cannot have additional attributes?
>

I'm just after a bit more flexibility. Perhaps that limitation could be
based on what dispatch types are available (i.e. don't allow Private with
any other dispatch types such as Path) which would allow user-defined
attributes on Private methods. Perhaps a better question is if there is
any thought about only creating actions if the method has one or more of a
defined set of attributes instead of just any attribute? I'm not clear if
the intent is that any method with attributes becomes an action or if only a
limited set of attributes should make a method an action.


Sorry, I know this is not a very important issues. At work we have been
kicking around some ideas for a new ACL system that uses method attributes
and this limiation came up again. But, it's easy to work around it.

Thanks,

--
Bill Moseley
moseley [at] hank


edencardim at gmail

Aug 17, 2009, 8:14 AM

Post #10 of 16 (1668 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Mon, Aug 17, 2009 at 10:57 AM, Bill Moseley<moseley [at] hank> wrote:
> I'm just after a bit more flexibility.  Perhaps that limitation could be
> based on what dispatch types are available (i.e. don't allow Private with
> any other dispatch types such as Path) which would allow user-defined
> attributes on Private methods.   Perhaps a better question is if there is
> any thought about only creating actions if the method has one or more of a
> defined set of attributes instead of just any attribute?  I'm not clear if
> the intent is that any method with attributes becomes an action or if only a
> limited set of attributes should make a method an action.
> Sorry, I know this is not a very important issues.  At work we have been
> kicking around some ideas for a new ACL system that uses method attributes
> and this limiation came up again.  But, it's easy to work around it.

I don't understand your obsession over :Private. A method tagged with
:Action, or any other attribute that doesn't make it use one of the
available dispatch types is effectively *the same thing* as a Private
action, except it doesn't restrict the use of other attributes, is
this not what you want? Personally, I've dumped most uses of method
attributes altogether, in favor of the config-based scheme, except for
a few cases of chaining, so I'd vouch for dumping :Private as well.

--
Eden Cardim Need help with your Catalyst or DBIx::Class project?
Code Monkey http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://edenc.vox.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
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/


paulm at paulm

Aug 17, 2009, 8:29 AM

Post #11 of 16 (1677 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Mon, Aug 17, 2009 at 4:14 PM, Eden Cardim<edencardim [at] gmail> wrote:
> On Mon, Aug 17, 2009 at 10:57 AM, Bill Moseley<moseley [at] hank> wrote:
>> I'm just after a bit more flexibility.  Perhaps that limitation could be
>> based on what dispatch types are available (i.e. don't allow Private with
>> any other dispatch types such as Path) which would allow user-defined
>> attributes on Private methods.   Perhaps a better question is if there is
>> any thought about only creating actions if the method has one or more of a
>> defined set of attributes instead of just any attribute?  I'm not clear if
>> the intent is that any method with attributes becomes an action or if only a
>> limited set of attributes should make a method an action.
>> Sorry, I know this is not a very important issues.  At work we have been
>> kicking around some ideas for a new ACL system that uses method attributes
>> and this limiation came up again.  But, it's easy to work around it.
>
> I don't understand your obsession over :Private. A method tagged with
> :Action, or any other attribute that doesn't make it use one of the
> available dispatch types is effectively *the same thing* as a Private
> action, except it doesn't restrict the use of other attributes, is
> this not what you want? Personally, I've dumped most uses of method

This appears to be a DRY violation, then.

> attributes altogether, in favor of the config-based scheme, except for
> a few cases of chaining, so I'd vouch for dumping :Private as well.
>
> --
>   Eden Cardim       Need help with your Catalyst or DBIx::Class project?
>  Code Monkey                    http://www.shadowcat.co.uk/catalyst/
>  Shadowcat Systems Ltd.  Want a managed development or deployment platform?
> http://edenc.vox.com/            http://www.shadowcat.co.uk/servers/
>
> _______________________________________________
> 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/
>

_______________________________________________
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/


moseley at hank

Aug 17, 2009, 9:20 AM

Post #12 of 16 (1680 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On Mon, Aug 17, 2009 at 8:14 AM, Eden Cardim <edencardim [at] gmail> wrote:

>
> I don't understand your obsession over :Private. A method tagged with
> :Action, or any other attribute that doesn't make it use one of the
> available dispatch types is effectively *the same thing* as a Private
> action, except it doesn't restrict the use of other attributes, is
> this not what you want? Personally, I've dumped most uses of method
> attributes altogether, in favor of the config-based scheme, except for
> a few cases of chaining, so I'd vouch for dumping :Private as well.


Sorry, it does sound like an obsession. And yes you are right there are
other approaches. It's not a big deal.


Obviously, the intent of Private is to have a forward-able action that
cannot be dispatched directly. It's a pretty basic part of Catalyst to have
actions that cannot be dispatched directly, so Private (or a way to express
the same thing) is useful. The implementation enforces this by prohibiting
any additional attributes instead of just prohibiting attributes handled by
different dispatch types. :Action just takes advantage of the
implementation details -- it's not a real action attribute at this time I
believe.

The issue that came up was I knew I could simply avoid using :Private to use
additional attributes, but then I didn't want to create an action for every
method that had attributes, either.

We are just investigating different approaches at this time, so it may turn
out that we go for the config-based approach as you noted. The people with
java experience seem to favor the config-based approach.

Anyway, I've moved on to obsessing about other things.


--
Bill Moseley
moseley [at] hank


bobtfish at bobtfish

Aug 17, 2009, 2:15 PM

Post #13 of 16 (1669 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On 15 Aug 2009, at 19:44, Bill Moseley wrote:
> Is there a specific reason that Private actions may not have
> additional attributes?

No, there is not.

At the time when that code was written, additional attributes (for
example, those used by Catalyst::Controller::ActionRole) weren't
supported / recommended.

They are now.

Removing that code, and replacing it with an error if you mixed
Private with dispatch attributes (e.g. : Private Local should go bang)
would be a very welcome patch.

Well volunteered.

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/


bobtfish at bobtfish

Aug 17, 2009, 2:19 PM

Post #14 of 16 (1665 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On 17 Aug 2009, at 09:47, Moritz Onken wrote:

>>
>> __PACKAGE__->config( actions => { foo => { Path => 'bar' } } );
>> sub foo {}
>
> This has been introduced in 5.80006. The Catalyst-Manual just didn't
> catch up with the changes.


No, it was not.

What gave you that impression?

http://www.catalystframework.org/calendar/2008/11

Cat 5.7015 was the current version at the time of writing, and I think
that worked for most (if not all) of the 5.70XX series.

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/


onken at houseofdesign

Aug 17, 2009, 2:50 PM

Post #15 of 16 (1668 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

Am 17.08.2009 um 23:19 schrieb Tomas Doran:

>
> On 17 Aug 2009, at 09:47, Moritz Onken wrote:
>
>>>
>>> __PACKAGE__->config( actions => { foo => { Path => 'bar' } } );
>>> sub foo {}
>>
>> This has been introduced in 5.80006. The Catalyst-Manual just
>> didn't catch up with the changes.
>
>
> No, it was not.
>
> What gave you that impression?
>
> http://www.catalystframework.org/calendar/2008/11
>
> Cat 5.7015 was the current version at the time of writing, and I
> think that worked for most (if not all) of the 5.70XX series.
>
> Cheers
> t0m

Until then it was necessary to add at least one attribute to the method.
The calendar uses :Local as attribute.

moritz

_______________________________________________
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

Aug 17, 2009, 2:57 PM

Post #16 of 16 (1668 views)
Permalink
Re: Why no extra attributes on Private actions? [In reply to]

On 17 Aug 2009, at 22:50, Moritz Onken wrote:
> Until then it was necessary to add at least one attribute to the
> method.
> The calendar uses :Local as attribute.

Aaaaaah, yes - my bad, you're totally correct, you needed to
sprinkle :Action around as decoration.. :)

++ Whoever fixed that...

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/

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.