Re: [Catalyst] Catalyst action attributes

2009-07-14 Thread Toby Corkindale

Tomas Doran wrote:


On 13 Jul 2009, at 07:50, Toby Corkindale wrote:


Devin Austin wrote:
Check this out: 
http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Attributes 
and 
http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Action_classes 



Thanks, although I had already read that before posting.

As far as I can see, there is no way to pass parameters to the 
ActionClass. Have I missed something?


The action class is passed the attributes when it is constructed in its 
arguments.


However - before we get into this, I recommend you write an ActionRole 
(ala Catalyst::Controller::ActionRole) instead of an action class, as 
you can use multiple actionroles together (which is not the case with 
action classes).


Simple example of some prior art you can steal to get you going:

http://search.cpan.org/~bobtfish/Catalyst-ActionRole-FindViewByIsa-0.02/lib/Catalyst/ActionRole/FindViewByIsa.pm 


Thanks, that's great.

So to summarise, the best practice way of passing parameters to these 
attribute-handlers is by using more attributes, that you *don't* 
specifically handle, but access via $c-action-attributes-{..}


I think that's right?

Cheers,
Toby

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


Re: [Catalyst] Catalyst action attributes

2009-07-13 Thread Toby Corkindale

Toby Corkindale wrote:

Hi,
I wondered if anyone could point me towards a working example of 
creating custom action attribute handlers for Catalyst?


eg. The contents of Catalyst::Controller::SecretAgent in the example below:


package MyApp::Controller::M;
use parent 'Catalyst::Controller::SecretAgent';
# Provides Vehicle() and Gimmick() actions.

sub bond : Vehicle('Aston Martin') {
  my ($self, $c) = @_;
  # ...
}

sub maxwell_smart : Gimmick('Shoe-phone') {
  My ($self, $c) = @_;
  #...
}

1;



I should clarify what I'm after..
I'd still like to be able to specify regular DispatchType attributes 
against the routines (eg. Local, Chained, etc), but I'd also like to 
have my own methods called against the other attributes I've specified.


The first method I tried was:
  package Catalyst::Controller::SecretAgent;
  use strict / use warnings
  use parent 'Catalyst::Controller';
  use attributes __PACKAGE__ = \set_vehicle, Vehicle;
  sub set_vehicle { # do something }
  ...

but I think that messes up catalyst's own handling of attributes.

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


Re: [Catalyst] Catalyst action attributes

2009-07-13 Thread Devin Austin
Check this out:
http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Attributesand
http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Action_classes


On Mon, Jul 13, 2009 at 12:27 AM, Toby Corkindale 
toby.corkind...@strategicdata.com.au wrote:

 Toby Corkindale wrote:

 Hi,
 I wondered if anyone could point me towards a working example of creating
 custom action attribute handlers for Catalyst?

 eg. The contents of Catalyst::Controller::SecretAgent in the example
 below:


 package MyApp::Controller::M;
 use parent 'Catalyst::Controller::SecretAgent';
 # Provides Vehicle() and Gimmick() actions.

 sub bond : Vehicle('Aston Martin') {
  my ($self, $c) = @_;
  # ...
 }

 sub maxwell_smart : Gimmick('Shoe-phone') {
  My ($self, $c) = @_;
  #...
 }

 1;



 I should clarify what I'm after..
 I'd still like to be able to specify regular DispatchType attributes
 against the routines (eg. Local, Chained, etc), but I'd also like to have my
 own methods called against the other attributes I've specified.

 The first method I tried was:
  package Catalyst::Controller::SecretAgent;
  use strict / use warnings
  use parent 'Catalyst::Controller';
  use attributes __PACKAGE__ = \set_vehicle, Vehicle;
  sub set_vehicle { # do something }
  ...

 but I think that messes up catalyst's own handling of attributes.


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




-- 
Devin Austin
http://www.codedright.net
http://www.dreamhost.com/r.cgi?326568/hosting.html - Host with DreamHost!
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst action attributes

2009-07-13 Thread Toby Corkindale

Devin Austin wrote:
Check this out: 
http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Attributes 
and 
http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Action_classes


Thanks, although I had already read that before posting.

As far as I can see, there is no way to pass parameters to the 
ActionClass. Have I missed something?


On Mon, Jul 13, 2009 at 12:27 AM, Toby Corkindale 
toby.corkind...@strategicdata.com.au 
mailto:toby.corkind...@strategicdata.com.au wrote:


Toby Corkindale wrote:

Hi,
I wondered if anyone could point me towards a working example of
creating custom action attribute handlers for Catalyst?

eg. The contents of Catalyst::Controller::SecretAgent in the
example below:


package MyApp::Controller::M;
use parent 'Catalyst::Controller::SecretAgent';
# Provides Vehicle() and Gimmick() actions.

sub bond : Vehicle('Aston Martin') {
 my ($self, $c) = @_;
 # ...
}

sub maxwell_smart : Gimmick('Shoe-phone') {
 My ($self, $c) = @_;
 #...
}

1;



I should clarify what I'm after..
I'd still like to be able to specify regular DispatchType attributes
against the routines (eg. Local, Chained, etc), but I'd also like to
have my own methods called against the other attributes I've specified.

The first method I tried was:
 package Catalyst::Controller::SecretAgent;
 use strict / use warnings
 use parent 'Catalyst::Controller';
 use attributes __PACKAGE__ = \set_vehicle, Vehicle;
 sub set_vehicle { # do something }
 ...

but I think that messes up catalyst's own handling of attributes.


___
List: Catalyst@lists.scsys.co.uk mailto:Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/




--
Devin Austin
http://www.codedright.net
http://www.dreamhost.com/r.cgi?326568/hosting.html - Host with DreamHost!




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



--
Strategic Data Pty Ltd
Ph: 03 9340 9000

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


Re: [Catalyst] Catalyst action attributes

2009-07-13 Thread Devin Austin
Try this:

sub post_chain_root : Chained('/') CaptureArgs(0) {

my ($self, $c) = @_;

foreach my $action (@{$c-action-chain}) {
my $role = $action-attributes-{RequiresRole}[0];
next unless $role;
## test role here...
}

}


That's a bit of code that you can put in the root of a Chained chain and do
something like

sub create_new_post : RequiresRole('can_post') {

# ...

}
HTH.


On Mon, Jul 13, 2009 at 12:50 AM, Toby Corkindale 
toby.corkind...@strategicdata.com.au wrote:

 Devin Austin wrote:

 Check this out:
 http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Attributeshttp://search.cpan.org/%7Ehkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Attributesand
 http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Action_classeshttp://search.cpan.org/%7Ehkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Action_classes


 Thanks, although I had already read that before posting.

 As far as I can see, there is no way to pass parameters to the ActionClass.
 Have I missed something?

  On Mon, Jul 13, 2009 at 12:27 AM, Toby Corkindale 
 toby.corkind...@strategicdata.com.au mailto:
 toby.corkind...@strategicdata.com.au wrote:

Toby Corkindale wrote:

Hi,
I wondered if anyone could point me towards a working example of
creating custom action attribute handlers for Catalyst?

eg. The contents of Catalyst::Controller::SecretAgent in the
example below:


package MyApp::Controller::M;
use parent 'Catalyst::Controller::SecretAgent';
# Provides Vehicle() and Gimmick() actions.

sub bond : Vehicle('Aston Martin') {
 my ($self, $c) = @_;
 # ...
}

sub maxwell_smart : Gimmick('Shoe-phone') {
 My ($self, $c) = @_;
 #...
}

1;



I should clarify what I'm after..
I'd still like to be able to specify regular DispatchType attributes
against the routines (eg. Local, Chained, etc), but I'd also like to
have my own methods called against the other attributes I've specified.

The first method I tried was:
 package Catalyst::Controller::SecretAgent;
 use strict / use warnings
 use parent 'Catalyst::Controller';
 use attributes __PACKAGE__ = \set_vehicle, Vehicle;
 sub set_vehicle { # do something }
 ...

but I think that messes up catalyst's own handling of attributes.


___
List: Catalyst@lists.scsys.co.uk mailto:Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive:
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/




 --
 Devin Austin
 http://www.codedright.net
 http://www.dreamhost.com/r.cgi?326568/hosting.html - Host with DreamHost!


 

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



 --
 Strategic Data Pty Ltd
 Ph: 03 9340 9000


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




-- 
Devin Austin
http://www.codedright.net
http://www.dreamhost.com/r.cgi?326568/hosting.html - Host with DreamHost!
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst action attributes

2009-07-13 Thread Tomas Doran


On 13 Jul 2009, at 07:50, Toby Corkindale wrote:


Devin Austin wrote:
Check this out: http://search.cpan.org/~hkclark/Catalyst- 
Manual-5.8000/lib/Catalyst/Manual/ExtendingCatalyst.pod#Attributes  
and http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/ 
Catalyst/Manual/ExtendingCatalyst.pod#Action_classes


Thanks, although I had already read that before posting.

As far as I can see, there is no way to pass parameters to the  
ActionClass. Have I missed something?


The action class is passed the attributes when it is constructed in  
its arguments.


However - before we get into this, I recommend you write an  
ActionRole (ala Catalyst::Controller::ActionRole) instead of an  
action class, as you can use multiple actionroles together (which is  
not the case with action classes).


Simple example of some prior art you can steal to get you going:

http://search.cpan.org/~bobtfish/Catalyst-ActionRole- 
FindViewByIsa-0.02/lib/Catalyst/ActionRole/FindViewByIsa.pm


Cheers
t0m


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


[Catalyst] Catalyst action attributes

2009-07-12 Thread Toby Corkindale

Hi,
I wondered if anyone could point me towards a working example of 
creating custom action attribute handlers for Catalyst?


eg. The contents of Catalyst::Controller::SecretAgent in the example below:


package MyApp::Controller::M;
use parent 'Catalyst::Controller::SecretAgent';
# Provides Vehicle() and Gimmick() actions.

sub bond : Vehicle('Aston Martin') {
  my ($self, $c) = @_;
  # ...
}

sub maxwell_smart : Gimmick('Shoe-phone') {
  My ($self, $c) = @_;
  #...
}

1;

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


Re: [Catalyst] Action attributes

2009-06-14 Thread Илья
Hi,

 A patch that let you do something like

 __PACKAGE__-config(
  Dispatcher = {
action_attributes = {
  allow = \...@list
}
  }
 );

 in MyApp.pm (preferably with the built in ones already in the list) to
 turn on strict checking would seem fine to me.

thank you. I will try to add this one!

Ilya

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


Re: [Catalyst] Action attributes

2009-06-08 Thread Matt S Trout
On Sat, Jun 06, 2009 at 02:35:53PM +1100, Илья wrote:
 Hi there,
 we use Catalyst about year and one thing make a lot of pain. When you
 make typo in action attribute name Catalyst silently eat it. For
 example:
 
 sub foo : Loacal Arg(1) {
 
 }
 
 will be work, but Arg(1) just do nothing.
 
 Now we use few additional attributes and I add trivial check in
 Our::Catalyst::Action:
 
 my @correct_names = qw
 Path
 Private
 Global
 Local
 Regex
 LocalRexgex
 Args
 Chained
 CaptureArgs
 PathPart
 
 Method
 Secure
 UnSecure
 RestrictTo
 Crumb
 Test
;
 
 foreach my $name (keys %$attrs) {
 unless ( first { $name eq $_ } @correct_names ) {
 die Wrong trait (attribute) $name!;
 }
 }
 
 so it is work for us, but mb better to add something like this in
 Catalyst itself? I can make patch if this helps.

A patch that let you do something like

__PACKAGE__-config(
  Dispatcher = {
action_attributes = {
  allow = \...@list
}
  }
);

in MyApp.pm (preferably with the built in ones already in the list) to
turn on strict checking would seem fine to me.

Then the dispatcher could check the actions when each one is registered with
it.

-- 
Matt S Trout Catalyst and DBIx::Class consultancy with a clue
 Technical Director  and a commit bit: http://shadowcat.co.uk/catalyst/
 Shadowcat Systems Limited
  mst (@) shadowcat.co.ukhttp://shadowcat.co.uk/blog/matt-s-trout/

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


[Catalyst] Action attributes

2009-06-05 Thread Илья
Hi there,
we use Catalyst about year and one thing make a lot of pain. When you
make typo in action attribute name Catalyst silently eat it. For
example:

sub foo : Loacal Arg(1) {

}

will be work, but Arg(1) just do nothing.

Now we use few additional attributes and I add trivial check in
Our::Catalyst::Action:

my @correct_names = qw
Path
Private
Global
Local
Regex
LocalRexgex
Args
Chained
CaptureArgs
PathPart

Method
Secure
UnSecure
RestrictTo
Crumb
Test
   ;

foreach my $name (keys %$attrs) {
unless ( first { $name eq $_ } @correct_names ) {
die Wrong trait (attribute) $name!;
}
}

so it is work for us, but mb better to add something like this in
Catalyst itself? I can make patch if this helps.

Excuse my ugly English, plz.

Ilya

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