RE: [Catalyst] Dispatching based on path and host/domain

2008-04-23 Thread Curtis Fletcher
 Write an Action Class.
 
 You can put whatever you want in the match() method. In your case,
 
 return 0 if grep { $c-req-host =~ /$_/ } 
 @{$self-attributes-{Domain}||[]}

I gave this a go (in principle it looks ideal), but the documentation on
Catalyst::Action is pretty sparse and only talks about replacing the
execute method. I'm assuming that if ActionClass-match() returns
false the dispatcher assumes the method doesn't match, I gave that a
quick test:

package Catalyst::Action::Domain;
use strict;
use warnings;
use base 'Catalyst::Action';
sub match
{
my $self = shift;
my ($c) = @_;
return 0;
};

package MyAPP::Controller::Admin::Website1::Abstract
sub index :Local
{
}

sub edit :Local :ActionClass('Domain')
{
}

http://mydomain.com/admin/website1/abstract/edit bounced me right back
to the default controller, I was kind of expecting it to behave like
NEXT in that it would fail to match
http://mydomain.com/admin/website1/abstract/edit but would then match
http://mydomain.com/admin/website1/abstract setting the first arg to
'edit'. Ah this may be specific to index as a not-really action it
doesn't accept parameters the way I thought it did 

E.G.
http://mydomain.com/admin/website1/abstract/iamnotamethod

Does not dispatch to MyAPP::Controller::Admin::Website1::Abstract-index
with ARGS being ('iamnotamethod') I think I answered my own question,
but there's no harm in having the result in the archives no? (especially
if I'm wrong)
(Also, Did someone say that index was a hack? And that we should use
base instead?)

Dumping out the Action Object I can see:
'attributes' =
{
'ActionClass' =
[
'Catalyst::Action::Domain'
],
'Path' =
[
'admin/website1/abstract/edit'
]
}

But I can't seem to find anywhere that this structure is set up, given
the code in your Action example how would you go about setting the
'Domain' key in the attributes class from the Controller the Action is
used in, apologies if this is a question with an obvious answer.

Finally isn't $c-req-host the hostname of the connecting client? I
ended up mangling $c-req-base at the moment though I'm not sure that's
the best way to go.

Really finally, has anyone thought of putting together a flowchart of
the Classes/methods involved in a Catalyst request response if it's been
done I'd love to look at it and if not if might be a good exercise for
me.

Thanks again for the really sterling help/suggestions.


___
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] Dispatching based on path and host/domain

2008-04-23 Thread Matt S Trout
On Wed, Apr 23, 2008 at 12:22:36PM +0100, Curtis Fletcher wrote:
  Write an Action Class.
  
  You can put whatever you want in the match() method. In your case,
  
  return 0 if grep { $c-req-host =~ /$_/ } 
  @{$self-attributes-{Domain}||[]}
 
 I gave this a go (in principle it looks ideal), but the documentation on
 Catalyst::Action is pretty sparse and only talks about replacing the
 execute method. I'm assuming that if ActionClass-match() returns
 false the dispatcher assumes the method doesn't match, I gave that a
 quick test:
 
 package Catalyst::Action::Domain;
 use strict;
 use warnings;
 use base 'Catalyst::Action';
 sub match
 {
   my $self = shift;
   my ($c) = @_;
   return 0;
 };
 
 package MyAPP::Controller::Admin::Website1::Abstract
 sub index :Local
 {
 }
 
 sub edit :Local :ActionClass('Domain')
 {
 }
 
 http://mydomain.com/admin/website1/abstract/edit bounced me right back
 to the default controller, I was kind of expecting it to behave like
 NEXT in that it would fail to match
 http://mydomain.com/admin/website1/abstract/edit but would then match
 http://mydomain.com/admin/website1/abstract setting the first arg to
 'edit'. Ah this may be specific to index as a not-really action it
 doesn't accept parameters the way I thought it did 
 
 E.G.
 http://mydomain.com/admin/website1/abstract/iamnotamethod
 
 Does not dispatch to MyAPP::Controller::Admin::Website1::Abstract-index
 with ARGS being ('iamnotamethod') I think I answered my own question,
 but there's no harm in having the result in the archives no? (especially
 if I'm wrong)
 (Also, Did someone say that index was a hack? And that we should use
 base instead?)

index is basically a degenerate form of :Path :Args(0)

If you'd wanted abstract/edit to match, you want :Path :Args(1) or no
:Args restriction.
 
 Dumping out the Action Object I can see:
 'attributes' =
 {
   'ActionClass' =
   [
   'Catalyst::Action::Domain'
   ],
   'Path' =
   [
   'admin/website1/abstract/edit'
   ]
 }
 
 But I can't seem to find anywhere that this structure is set up, given
 the code in your Action example how would you go about setting the
 'Domain' key in the attributes class from the Controller the Action is
 used in, apologies if this is a question with an obvious answer.

:Local is a shortcut for :Path($controller-path_prefix.'/'.$method_name)

Those values came straight off the attributes - you'd set the Domain key
just by using :Domain('foobar.com') exactly as you did in your original
example (which is where I got the key name from :)

 Finally isn't $c-req-host the hostname of the connecting client? I
 ended up mangling $c-req-base at the moment though I'm not sure that's
 the best way to go.

I meant $c-req-uri-host, sorry.

 Really finally, has anyone thought of putting together a flowchart of
 the Classes/methods involved in a Catalyst request response if it's been
 done I'd love to look at it and if not if might be a good exercise for
 me.

http://dev.catalyst.perl.org/wiki/FlowChart

shows the action dispatching order. Another one that maps out the
relationships of the classes would rock; feel free to barrage me with
questions (you get a free pass for stupid questions if you're writing docs
or equivalent material :)

-- 
  Matt S Trout   Need help with your Catalyst or DBIx::Class project?
   Technical Directorhttp://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@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] TT custom virtual methods available to all pages.

2008-04-23 Thread Felix Antonius Wilhelm Ostmann

i love such liddle funktions as FILTER :)

in View::TT

__PACKAGE__-config(
   {
   CATALYST_VAR = 'catalyst',
   ...
   FILTERS = {
   yesno = sub {
   $_[0] ? 'yes' : 'no';
   },
   onoff = sub {
   $_[0] ? 'on' : 'off';
   },
   },
   },
);


so i can write in the template

Newsletter: [% user.newsletter | yesno %]


or your mk_hash:

[% somedata | mk_hash %]


Rajeev Cyrus schrieb:

Greetings.

One of my TT pages required some massaging of data that I decided to 
do via referencing a subroutine in a template variable, eg:

$c-stash-{mk_hash} = \mk_hash;

I would like to use this stashed variable on all of my templates so my 
question is:
Where is the best place to initialize and set this variable? Where 
should i declare the mk_hash method? Is there some way I can configure 
catalyst to set certain template variables when the application starts?


Thanks!

-Rajeev Cyrus



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





--
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--
Websuche   Search   Technology   GmbH  Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:+49 541 40666-22
Email: [EMAIL PROTECTED] - Website: www.websuche.de
--
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin: Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--


___
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] Dispatching based on path and host/domain

2008-04-23 Thread Matt S Trout
On Wed, Apr 23, 2008 at 03:25:47PM +0100, Curtis Fletcher wrote:
  -Original Message-
  From: Matt S Trout [mailto:[EMAIL PROTECTED] 
  Sent: 23 April 2008 14:34
  To: The elegant MVC web framework
  Subject: Re: [Catalyst] Dispatching based on path and host/domain
  
  :Local is a shortcut for 
  :Path($controller-path_prefix.'/'.$method_name)
  
  Those values came straight off the attributes - you'd set the 
  Domain key
  just by using :Domain('foobar.com') exactly as you did in 
  your original
  example (which is where I got the key name from :)
 
 And the light comes on because someone is finally home!
 I was thinking that :Local :Path etc were shortcuts to defining an
 ActionClass not attributes to the (mostly) default ActionClass. Bingo it
 all makes sense now. Many thanks.

Right. The ActionClass affects how the action itself gets to make its choices.

Things like :Path and :Chained indicate that whatever aciton object is
constructed should be registered with a particular dispatch type.

We just happen to only have one attribute namespace because that's how many
perl has :)
 
 Digging around, is it a sane thing to have:
 
 __PACKAGE__-_action_class('Catalyst::Action::MyAction');
 
 At the top of a controller if I want all of the methods to use the same
 non-default ActionClass? I'm nervous about using anything that starts
 with _

It starts with _ because you should never call it from -outside- the class.

You're fine calling it on your own class.

Doc patch to make this clear very welcome.
 
 On a related note: While I was looking for information about setting a
 default ActionClass I came across the ActionClass info in
 http://search.cpan.org/~mstrout/Catalyst-Manual-5.701004/lib/Catalyst/Ma
 nual/ExtendingCatalyst.pod I wish I'd found that at the start, maybe
 I'll put together a patch for the Catalyst::Action and
 Catalyst::Manual::Actions pod that points people back there for info
 about using match (does that sound like a good thing to do?)

Yes please!

-- 
  Matt S Trout   Need help with your Catalyst or DBIx::Class project?
   Technical Directorhttp://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@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] TT custom virtual methods available to all pages.

2008-04-23 Thread Matt S Trout
On Wed, Apr 23, 2008 at 09:45:15AM -0500, Rajeev Cyrus wrote:
 Greetings.
 
 One of my TT pages required some massaging of data that I decided to  
 do via referencing a subroutine in a template variable, eg:
 $c-stash-{mk_hash} = \mk_hash;
 
 I would like to use this stashed variable on all of my templates so my  
 question is:
 Where is the best place to initialize and set this variable? Where  
 should i declare the mk_hash method? Is there some way I can configure  
 catalyst to set certain template variables when the application starts?

package MyApp::View::TT;

use base qw(Catalyst::View::TT);

__PACKAGE__-config(
  ...
);

use Moose;

around template_vars = sub {
  my $orig = shift;
  my $self = shift;
  return (mk_hash = sub { ... }, $self-$orig(@_));
};

no Moose;

1;

-- 
  Matt S Trout   Need help with your Catalyst or DBIx::Class project?
   Technical Directorhttp://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@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/