Re: [Catalyst] how to get controller path
On Tuesday 20 November 2007 18:22:54 Matt S Trout wrote: > On Tue, Nov 20, 2007 at 12:27:32PM +0530, Alok Sharma wrote: > > Given a path we have ways to get the uri using the method uri_for(path). > > Is there a possible way to get the controller path given the uri so I am > > able to do some thing like this > > $c->res->redirect(uri); $c->forward(controller_path(uri)); > > Why can't you start off with a controller action? > > my $action = $c->controller('Foo')->action_for('bar'); # > Controller::Foo->bar > > $c->res->redirect($c->uri_for($action)); > $c->forward($action->reverse); I was trying to write a module where the user asks for a particular URI but for certain reasons ( say session expired or not yet logged etc. ) has to be authenticated again and then user will be automatically redirected to the requested page,in a way furnishing something before actual request is processed. For this I saved the URI requested ( say as $path ) as a session variable, redirected to the authentication page ( say to the standard login page ). But the issue was to redirect to the page requested by the user for which I got back the URI path from the session variable, till here all fine. But without knowing the action for that URI name I cant forward to it. That is where I needed something like $c->forward(controller_path(uri)); Or is there another approach to this problem. On Tue, Nov 20, 2007 at 08:30:58AM -0600, Peter Karman wrote: > The Catalyst::Dispatcher seems to be the correct > place to interrogate the action map for any given URL, maybe with > get_action_by_path(). The dispatcher does produce the list of all the actions, but the process is complicated, if there is a way access the list of all actions that it produces then may be have to parse through the list to identify the right action. Regards Alok ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Shared Host Setup
On Nov 20, 2007, at 5:28 PM, Matt S Trout wrote: On Tue, Nov 20, 2007 at 04:34:54PM -0500, Jason Kohles wrote: 1. I run squid on my laptop, bound only to the localhost interface and with ACLs that only allow localhost to use it as a general-purpose proxy, then I login to the remote host with a port forward and run cpanp (or cpan) with a proxy configuration... ssh -R 3128:localhost:3128 server.address server% http_proxy=http://localhost:3128 cpanp 2. If I'm at a client site where my laptop won't have outgoing access either, then I run apache on the laptop, and use CPAN::Mini to make myself a local mirror of CPAN before I go... minicpan -l /var/www/html/minicpan -r http://some.cpan.mirror/ ssh -R 8080:localhost:80 server.address server% cpanp (and use http://localhost:8080/minicpan as the mirror address) the minicpan script is ass. But then it was written as an article, not as a highly efficient piece of code. Yeah, it's dog slow, but it's a wheel I didn't feel like re-inventing, and if you run it periodically (like nightly from cron) then it only has to download changes, which isn't quite so annoying. http://trout.me.uk/perl/mirror.sh.txt syncs a hell of a lot faster and makes two rsync connections rather than a vast number of HTTP requests. That's a decent approach too, which I may now use instead, since it's a better wheel I don't have to re-invent... :) 3. As a last resort, if the site is so paranoid that ssh forwarding is locked down too, then I still have a fallback... rsync -essh -avz /var/www/html/minicpan some.secure.host:minicpan Meh. CPAN doesn't delete anything from ~/.cpan/sources, ever, normally. So you start from an empty site_perl and an empty local::lib, wipe that, do a 'make installdeps' on your app, verify it (this being essential to ensuring you've got all the deps into Makefile.PL anyway), then you just rsync that up and the CPAN.pm on the far end has the exact set of tarballs it needs. Much more bandwidth efficient :) Maybe, but it's fairly uncommon for me to go through all this just for one app anyway, usually it's setting up development servers, which means it's nice to have a full CPAN mirror instead of just the dependencies for that one app. -- Jason Kohles, RHCA RHCDS RHCE [EMAIL PROTECTED] - http://www.jasonkohles.com/ "A witty saying proves nothing." -- Voltaire ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Shared Host Setup
On Tuesday 20 November 2007 03:34:54 pm Jason Kohles wrote: > CPAN::Mini only mirrors the most recent version of each module, so the > size is much smaller than you might expect (I believe a minicpan > mirror can still fit on a CD-ROM, although I haven't checked that > recently...) It just misses... the minicpan at work weighs in at 764MB at the moment. Technically you could get that on a CD, but not in data mode. :) Andrew ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Session/Authentication/Authorization for legacy + Cat
On 21 Nov 2007, at 11:13, Ashley Pond V wrote: Mail.app is either doing something squirrelly or my mail host is. I think it's your mail host (sent with mail.app ;-) ) ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Session/Authentication/Authorization for legacy + Cat
On Nov 20, 2007, at 2:29 PM, Matt S Trout wrote: On Tue, Nov 20, 2007 at 08:41:02PM -, Peter Edwards wrote: On Mon, Nov 19, 2007 at 11:03:24PM -0800, Ashley Pond V wrote: "Let Catalyst handle /login. Make legacy code get user out of session. That's a really good way so long as you can make the old app use a Catalyst session handler. Which in his case is true since he's sharing the sessions via CGI::Session. I do think this is the way to go. Nice. I also think we have have replaced mythology with popular culture, but that's OOT. In my prototype I found a pretty annoying interface transparency issue though. This is from an email I just sent the author of C::P:Session::CGISession. C::P:Session::CGISession, puts the data under our $SESSION_DATA_PARAMETER_NAME = '_catalyst_session'; for cross-compat with other Session hooks, but it hides it from the legacy store which is in the same level under _DATA. So the Cat manipulated session info is under $session->param("_catalyst_session") for the legacy code and the Cat code has no access to anything the legacy code sets in the session. # some data trimmed out for brevity '_DATA' => { 'rand_set_in_legacy' => '6.3108406432821', '_catalyst_session' => { 'rand_set_in_cat' => '16.4781763075979', }, '_SESSION_ID' => 'f15b8a17d0fc00a43601226837afd5e8', } So, this makes it pretty tricky to mix the two. I'd like to have the Cat::Plugin work at the same level as the vanilla CGI::Session; the "_DATA" store for all top level params. Of course for compatibility with other Cat stuff, the "_catalyst_session" would still work, it would just be a reference to the "_DATA." So I have a patch, I think, which makes it work on the same internal data hash for both the Cat and vanilla versions so they can use the same session transparently. I've offered it to the author, if he thinks it's a good change. On unrelated and deeply buried points I would also like to add for the record (again), that I never start a new thread by replying to an old message even though the list threads make it look that way. Mail.app is either doing something squirrelly or my mail host is. Also the (this archive seems to be stuck in September: http://www.mail-archive.com/[EMAIL PROTECTED]/ This one is up to date: http://lists.scsys.co.uk/pipermail/catalyst/ Thanks! -Ashley ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Shared Host Setup
On Tue, Nov 20, 2007 at 10:16:30AM -0800, Mesdaq, Ali wrote: > Someone said they were going to write a advent calendar entry for using > local::lib so I was waiting for that. But just wanted to share my > solution as an alternative because some shared hosts are big pains to > work with. Some don't even allow outbound connections So you rsync up ~/.cpan/sources off the dev box, end of problem. > so using cpan is not an option. I think you define 'not an option' differently to me :) You've spent this whole thread starting from the point of view of "X doesn't work" or "Y is impossible" or "Z is not an option". It's amazing where you can get when you start from "I don't know how to do this, let's see if I can bend the tools a new way and learn something in the process". -- Matt S Trout Catalyst and DBIx::Class consulting and support - Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Christmas fun in collectable card game form - http://www.shadowcat.co.uk/resources/2007_trading/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Session/Authentication/Authorization for legacy + Cat
On Tue, Nov 20, 2007 at 08:41:02PM -, Peter Edwards wrote: > >On Mon, Nov 19, 2007 at 11:03:24PM -0800, Ashley Pond V wrote: > >> I'm working on some session code which I'd like to be able to use > >> with legacy code (non-Cat) and Cat... > >> For authentication/authorization though I can't find a(n obvious) > >> path for both legacy and Cat. > >> > >> Any tales from the punchbowl on the topic? > > > >"Let Catalyst handle /login. Make legacy code get user out of session. > > That's a really good way so long as you can make the old app use a Catalyst > session handler. Which in his case is true since he's sharing the sessions via CGI::Session. > We had to incorporate around an old perl app that used a user table with > Unix passwd style passwords and its own cookies and custom session handling. > We set up a DBIx::Class view to the SQL user table in the Catalyst > authentication configuration and took a hit on using different session > stores between old and new apps, which wasn't really a problem in this case. > The old app works the same and the new Catalyst parts are self-contained but > share the user login/password. I'm not sure whether that's horrible or beautiful. I think the best solution may simply be to drink enough beer to forget it was ever done :) -- Matt S Trout Catalyst and DBIx::Class consulting and support - Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Christmas fun in collectable card game form - http://www.shadowcat.co.uk/resources/2007_trading/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Shared Host Setup
On Tue, Nov 20, 2007 at 04:34:54PM -0500, Jason Kohles wrote: > 1. I run squid on my laptop, bound only to the localhost interface and > with ACLs that only allow localhost to use it as a general-purpose > proxy, then I login to the remote host with a port forward and run > cpanp (or cpan) with a proxy configuration... > > ssh -R 3128:localhost:3128 server.address > server% http_proxy=http://localhost:3128 cpanp > > 2. If I'm at a client site where my laptop won't have outgoing access > either, then I run apache on the laptop, and use CPAN::Mini to make > myself a local mirror of CPAN before I go... > > minicpan -l /var/www/html/minicpan -r http://some.cpan.mirror/ > > ssh -R 8080:localhost:80 server.address > server% cpanp (and use http://localhost:8080/minicpan as the mirror > address) the minicpan script is ass. But then it was written as an article, not as a highly efficient piece of code. http://trout.me.uk/perl/mirror.sh.txt syncs a hell of a lot faster and makes two rsync connections rather than a vast number of HTTP requests. > 3. As a last resort, if the site is so paranoid that ssh forwarding is > locked down too, then I still have a fallback... > > rsync -essh -avz /var/www/html/minicpan some.secure.host:minicpan Meh. CPAN doesn't delete anything from ~/.cpan/sources, ever, normally. So you start from an empty site_perl and an empty local::lib, wipe that, do a 'make installdeps' on your app, verify it (this being essential to ensuring you've got all the deps into Makefile.PL anyway), then you just rsync that up and the CPAN.pm on the far end has the exact set of tarballs it needs. Much more bandwidth efficient :) -- Matt S Trout Catalyst and DBIx::Class consulting and support - Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Christmas fun in collectable card game form - http://www.shadowcat.co.uk/resources/2007_trading/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Shared Host Setup
On Nov 20, 2007, at 3:42 PM, John Goulah wrote: On Nov 20, 2007 1:16 PM, Mesdaq, Ali <[EMAIL PROTECTED]> wrote: Someone said they were going to write a advent calendar entry for using local::lib so I was waiting for that. But just wanted to share my solution as an alternative because some shared hosts are big pains to work with. Some don't even allow outbound connections so using cpan is not an option. So you would basically have to package everything up and lay it down. I'll be writing that, but really if you follow bootstrap instructions , that covers most of it. I'll just cover a couple extras and go into more detail. Of course, you'd be out of luck without an outbound connection, I try to avoid those hard to work with hosts :-) Not necessarily. There are several ways to work around this problem that I've used with great success. In order of my preference, they are: 1. I run squid on my laptop, bound only to the localhost interface and with ACLs that only allow localhost to use it as a general-purpose proxy, then I login to the remote host with a port forward and run cpanp (or cpan) with a proxy configuration... ssh -R 3128:localhost:3128 server.address server% http_proxy=http://localhost:3128 cpanp 2. If I'm at a client site where my laptop won't have outgoing access either, then I run apache on the laptop, and use CPAN::Mini to make myself a local mirror of CPAN before I go... minicpan -l /var/www/html/minicpan -r http://some.cpan.mirror/ ssh -R 8080:localhost:80 server.address server% cpanp (and use http://localhost:8080/minicpan as the mirror address) 3. As a last resort, if the site is so paranoid that ssh forwarding is locked down too, then I still have a fallback... rsync -essh -avz /var/www/html/minicpan some.secure.host:minicpan If you write your own mirroring tool instead of using the cpanmini script, you can even exclude stuff from your local mirror... #!/usr/bin/perl -w use strict; use warnings; use CPAN::Mini; CPAN::Mini->update_mirror( remote => 'http://some.cpan.mirror', local => '/data/minicpan', force => 0, trace => 1, skip_perl => 1, path_filters=> [ qr/(CGI-Application|Maypole|Oracle|Class-DBI)/ ], module_filters => [ qr/Acme/, ], ); CPAN::Mini only mirrors the most recent version of each module, so the size is much smaller than you might expect (I believe a minicpan mirror can still fit on a CD-ROM, although I haven't checked that recently...) -- Jason Kohles, RHCA RHCDS RHCE [EMAIL PROTECTED] - http://www.jasonkohles.com/ "A witty saying proves nothing." -- Voltaire ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Shared Host Setup
On Nov 20, 2007 1:16 PM, Mesdaq, Ali <[EMAIL PROTECTED]> wrote: > Someone said they were going to write a advent calendar entry for using > local::lib so I was waiting for that. But just wanted to share my > solution as an alternative because some shared hosts are big pains to > work with. Some don't even allow outbound connections so using cpan is > not an option. So you would basically have to package everything up and > lay it down. I'll be writing that, but really if you follow bootstrap instructions , that covers most of it. I'll just cover a couple extras and go into more detail. Of course, you'd be out of luck without an outbound connection, I try to avoid those hard to work with hosts :-) ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Session/Authentication/Authorization for legacy + Cat
>On Mon, Nov 19, 2007 at 11:03:24PM -0800, Ashley Pond V wrote: >> I'm working on some session code which I'd like to be able to use >> with legacy code (non-Cat) and Cat... >> For authentication/authorization though I can't find a(n obvious) >> path for both legacy and Cat. >> >> Any tales from the punchbowl on the topic? > >"Let Catalyst handle /login. Make legacy code get user out of session. That's a really good way so long as you can make the old app use a Catalyst session handler. We had to incorporate around an old perl app that used a user table with Unix passwd style passwords and its own cookies and custom session handling. We set up a DBIx::Class view to the SQL user table in the Catalyst authentication configuration and took a hit on using different session stores between old and new apps, which wasn't really a problem in this case. The old app works the same and the new Catalyst parts are self-contained but share the user login/password. Regards, Peter Dragonstaff Limited http://www.dragonstaff.com Business IT Consultancy ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Session/Authentication/Authorization for legacy + Cat
On Mon, Nov 19, 2007 at 11:03:24PM -0800, Ashley Pond V wrote: > I'm working on some session code which I'd like to be able to use > with legacy code (non-Cat) and Cat. No problem. Apache::Session > (::Flex) and CGI::Session both have Cat plugins so either one will > migrate fine (seems like CGI::Session is the winner; deeper controls, > same divers backends, active development, no table MySQL locking or > DESTROY squirreliness). Yay, team! > > For authentication/authorization though I can't find a(n obvious) > path for both legacy and Cat. I love the Cat plugins, btw. Is there > is, or is there ain't a way to write authentication/authorization > which is going to work (at least in the backend) for both? > > Any tales from the punchbowl on the topic? "Let Catalyst handle /login. Make legacy code get user out of session. Stop worrying and learn to love the bomb." 'Tis a strange love we have for the legacies we inherit. -- Matt S Trout Catalyst and DBIx::Class consulting and support - Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Christmas fun in collectable card game form - http://www.shadowcat.co.uk/resources/2007_trading/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to get controller path
On Tue, Nov 20, 2007 at 08:30:58AM -0600, Peter Karman wrote: > > > On 11/20/2007 06:52 AM, Matt S Trout wrote: > > On Tue, Nov 20, 2007 at 12:27:32PM +0530, Alok Sharma wrote: > >> Hi, > >> Need a bit of help. > >> Given a path we have ways to get the uri using the method uri_for(path). > >> Is there a possible way to get the controller path given the uri so I am > >> able > >> to do some thing like this > >>$c->res->redirect(uri); $c->forward(controller_path(uri)); > > > > Why can't you start off with a controller action? > > > > my $action = $c->controller('Foo')->action_for('bar'); # > > Controller::Foo->bar > > > > $c->res->redirect($c->uri_for($action)); > > $c->forward($action->reverse); > > > > That assumes you know which Controller to start with. > > I've had this same issue recently. The problems IME are case and attributes. > E.g., URIs are all lc() but the corresponding Controller/Action could be any > case. > > /foo/bar > > might correspond to: > > MyApp::Controller::Foo::Bar->default() > > or > > MyApp::Controller::FOO->bar() > > or > > MyApp::Controller::foo->BAR() > > etc. You have no way of knowing from just a URI, and in my case, that was what > I had to go on in my template. I usually take that as "time to refactor the template". obXThread: I try and avoid having URIs -anywhere- in my app code except in the action attributes/config. It means I can rename stuff any time I need to in terms of the external URI space and be certain of not needing to change code or templates to handle it - effectively the path part names are just another string dictionary to me. > The Catalyst::Dispatcher seems to be the correct > place to interrogate the action map for any given URL, maybe with > get_action_by_path(). Nope, that's for forward() lookup. Since actions can decide to match or not match the request based on pretty much anything they like, the only way to determine what URI a particular request would dispatch to with certainty is to mock up a request and context and ask the dispatcher to set up $c->action the same way the prepare_action phase of a real HTTP request dispatch would. Any attempt to do otherwise runs really fast into me hiding under the desk and yelling 'Halting Problem!' over and over until you go away. Of course if you're willing to restrict what your code does and enforce that via project policy or otherwise, the rules change - but there isn't really a general solution here. Relying on action objects rather than URLs is the best answer we have currently, which is why $c->uri_for($action, ...) got implemented in the first place. -- Matt S Trout Catalyst and DBIx::Class consulting and support - Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Christmas fun in collectable card game form - http://www.shadowcat.co.uk/resources/2007_trading/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Shared Host Setup
Someone said they were going to write a advent calendar entry for using local::lib so I was waiting for that. But just wanted to share my solution as an alternative because some shared hosts are big pains to work with. Some don't even allow outbound connections so using cpan is not an option. So you would basically have to package everything up and lay it down. Thanks, -- Ali Mesdaq Security Researcher II Websense Security Labs http://www.WebsenseSecurityLabs.com -- -Original Message- From: Matt S Trout [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 20, 2007 9:49 AM To: The elegant MVC web framework Subject: Re: [Catalyst] Shared Host Setup On Mon, Nov 19, 2007 at 12:25:37PM -0800, Mesdaq, Ali wrote: > So I tired something I been meaning to test out. So I created a vmware > image of freebsd and created the full path I would have on my shared > host and downloaded and installed perl to that path. Then I ran cpan > downloading every module I needed for catalyst using the new perl I just > built. Then I uploaded that perl directory to my host and ran all my > scripts with that as the path to perl. > > Catalyst looks like its working fine. So far no issues. Can anyone think > of a reason why this would not be a good alternative setup option on > shared hosts? Other than being much, much more effort than local::lib and potentially vulnerable to library/compiler/etc. versioning issues, no, it seems fine. I just have better things to do with my life than set up a complete OS install for a simple shared deployment :) -- Matt S Trout Catalyst and DBIx::Class consulting and support - Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Christmas fun in collectable card game form - http://www.shadowcat.co.uk/resources/2007_trading/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/ TO REPORT THIS AS SPAM, PLEASE CLICK THE FOLLOWING LINK: https://www.mailcontrol.com/sr/e4wLVAN+znP93GK8o0NBd8Ct2b527xWYWB0CsXeMB Vy9rti9i5pY8E978VewCvyAPR7RRvARALBMy+hBTz9LkSmQRI0u7vMBN5gxZRX3+GtPk4C5D wphdGnEJjfvBcGKslsK9gKEs6BOldhqz!6x4HHjssnC91G0z1b6D4F7WWUg2CXhueYDtpuBv phK3fCQTnESY1AGvpLR3RH!!BtZdoMpTQJYFKNp ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] PathPart help
On Mon, Nov 19, 2007 at 09:41:06AM +0100, Dami Laurent (PJ) wrote: > >-Message d'origine- > >De : Matt S Trout [mailto:[EMAIL PROTECTED] > >Envoyé : samedi, 17. novembre 2007 12:40 > > [ snip ] > > > > >What I'd do instead is - > > > >package MyApp::ControllerBase::HasObject; > > > >sub has_object :PathPart('') :CaptureArgs(0) > >sub edit :Chained('has_user') :PathPart('edit') :Args(0) > > > >package MyApp::ControllerBase::ChainBase; > > > >__PACKAGE__->mk_accessors(qw(object_chains)); > > > >__PACKAGE__->config(object_chains => []); > > > >sub COMPONENT { > > my $new = shift->NEXT::COMPONENT(@_); > > foreach my $chain (@{$new->object_chains}) { # commented > >using example 'id' > >my $action = $self->action_for($chain); # Catalyst::Action > >for /foo/id > >my $pkg = ref($new).'::'.ucfirst($chain); # 'id' -> > >Controller::Foo::Id > >{ > > no strict 'refs'; > > @{"${pkg}::ISA"} = 'MyApp::ControllerBase::HasObject'; # > >inject base class > >} > ># Set :Chained('id') on Controller::Foo::Id->has_user > >$pkg->config(actions => { has_object => { Chained => > >$action->reverse } }); > > } > > return $new; > >} > > > >package MyApp::Controller::Foo; > > > >use base qw(MyApp::ControllerBase::Chains); > > > >__PACKAGE__->config(object_chains = [ qw(id name email) ]); > > > >sub id ... > >sub name ... > >sub email ... > > > >Now, when Catalyst creates the Controller::Foo instance the > >stuff after the > >component method will create Controller::Foo::Id, ::Name, > >::Email - Catalyst > >will automatically pick this up (the same way it picks up the > >sub-models > >created by e.g. Model::DBIC::Schema) and will load the > >Foo/Id.pm etc. files > >afterwards -if- they exist. > > > >That way you'll get /foo/id/edit, /foo/name/edit etc. actions > >which can be > >passed happily to $c->uri_for without ambiguity, and still have minimal > >repeated code. > > > >(Disclaimer: code typed straight into mail. probably at least > >one typo or > >thinko lurking in there) > > > >If people like this approach, I could write it up as an advent > >entry ... > > > > Well, it may seem cute, but I am worried about long-term maintenance of this > approach : if two years later somebody has to change anything in that setup, > without knowing as much about Catalyst internals as you do Matt, then it > could be quite hard for them to understand what is going on. Which is why I provided a full explanation of the technique, such as could be put into comments in the classes involved so in two years the maintenance programmer opens the file and finds a complete description of the mechanisms :) > The original Catalyst design of URL-method mappings was quite obvious to > understand (Local, Global, Regex, etc.). Then came the chained actions, that > gave us much more flexibility and reuse, but require quite a bit of reading > and experiment to really understand them. Now if we add even more indirection > levels, it will make it even harder to follow. > > Two days ago at the French Perl Workshop somebody mentioned that Ruby on > Rails has a notion of global, centralized dispatch table. Apache also has a > convenient way to centralize the URL mappings, with or > directives. As far as I know, Catalyst does not yet have any > similar dispatch mechanism, but maybe that would be an interesting evolution > path to investigate ? You can already do that. All the attributes can be assigned from controller config, as shown above. So in MyApp.pm __PACKAGE__->config( Controller::Foo => { action => { bar => { Path => '/some/path' } } } ); is identical to having :Path(/some/path) on the 'sub bar'. So we -can- do things globally if we really want to. But having self-contained controllers was an intentional design decision in order to allow for improved code re-use - my base class trickery can be written once and shared between projects, and in fact Reaction will include a number of Catalyst::Controller subclasses designed for just this sort of usage - a general admin interface one that scaffolds a full CRUD system, a basic one-table CRUD controller and a simpler one-table 'list and view actions only' controller. Most large-scale Catalyst projects that Shadowcat is currently helping clients with are already using base classes and connect-the-dots approaches like this to maximise code re-use across their architecture (and were doing so before we got involved); where this stuff then reflects out to apache configs there's invariably either a nightmare nest of Include directives or a TT setup that generates the appropriate httpd.conf chunks in order to get round the limitation of a single global config tree. So, on the whole the rails/httpd.conf approach might be superficially simpler for small projects, but really doesn't scale the way the currently available Catalyst approaches do. Additional levels of indirection is a normal part of refactoring for re-use; liberal use of commen
Re: [Catalyst] Shared Host Setup
On Mon, Nov 19, 2007 at 12:25:37PM -0800, Mesdaq, Ali wrote: > So I tired something I been meaning to test out. So I created a vmware > image of freebsd and created the full path I would have on my shared > host and downloaded and installed perl to that path. Then I ran cpan > downloading every module I needed for catalyst using the new perl I just > built. Then I uploaded that perl directory to my host and ran all my > scripts with that as the path to perl. > > Catalyst looks like its working fine. So far no issues. Can anyone think > of a reason why this would not be a good alternative setup option on > shared hosts? Other than being much, much more effort than local::lib and potentially vulnerable to library/compiler/etc. versioning issues, no, it seems fine. I just have better things to do with my life than set up a complete OS install for a simple shared deployment :) -- Matt S Trout Catalyst and DBIx::Class consulting and support - Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Christmas fun in collectable card game form - http://www.shadowcat.co.uk/resources/2007_trading/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Patch to make ConfigLoader load "local" files
On Tue, Nov 20, 2007 at 01:37:49PM +, John Tate wrote: > > Sorry. This time with an attachment... You still seem to have missed the rest of the patch. Try doing a diff -ur so it picks up the test changes as well. -- Matt S Trout Catalyst and DBIx::Class consulting and support - Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Christmas fun in collectable card game form - http://www.shadowcat.co.uk/resources/2007_trading/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Patch to make ConfigLoader load "local" files
John, John Tate wrote: I've been trying to get C::P::ConfigLoader (0.18) to load "local" configuration files. From my reading of the documentation, if have a Config::General configuration file called "myapp.conf", I should be able to load another file named something like "myapp_local.conf", but I've not been able to make it work. I can't find any other reports of this problem, so I'm probably misreading the documentation or misusing the plugin... I've yet to see an issue that would prevent the "suffix" option to work as expected. I've confirmed with mst, who uses Config::General files, that it works for him. Are you setting any configuration or environment variables to further tweak ConfigLoader's workings? (i.e. any of the settings described in get_config_path() [1] and get_config_local_suffix() [2]) -Brian [1] http://search.cpan.org/dist/Catalyst-Plugin-ConfigLoader/lib/Catalyst/Plugin/ConfigLoader.pm#get_config_path [2] http://search.cpan.org/dist/Catalyst-Plugin-ConfigLoader/lib/Catalyst/Plugin/ConfigLoader.pm#get_config_local_suffix ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] PageCache and SubRequest
On 11/20/2007 04:39 AM, Kyoko Shikamata wrote: > Hello All, > > I have a trouble about PageCache(Cache::FileCache) and SubRequest . > The part using SubRequest of the page cannot be cached often . > > - Controller : > use Catalyst qw/SubRequest Cache::FileCache PageCache/; > > __PACKAGE__->config->{page_cache} = { > expires => 300, > set_http_headers => 1, > debug => 1, > }; > __PACKAGE__->config->{cache}->{storage} = '/tmp'; > > sub index : Local { > my ( $self, $c ) = @_; > $c->cache_page( 300 ); > # action > $c->stash->{template} = 'index.tt' > $c->forward("My::View::TT"); > } > > sub test : Path('/parts/test') { > my ( $self, $c ) = @_; > $c->response->body('Test'); > } > > - TT (index.tt): > > > Hello > [%c.subreq('/parts/test')%] > > > > I hope that the page including 'Hello' and 'Test' are cached. > But, often I cannot see 'Test' in the cached page. > The behavior often happens. > You likely need to cache the page (or parts of it) instead of the request. See Template::Plugin::Cache and use the existing cache object. I have code using that technique in production, for caching parts of pages, and it works wonderfully. -- Peter Karman . [EMAIL PROTECTED] . http://peknet.com/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to get controller path
On 11/20/2007 06:52 AM, Matt S Trout wrote: > On Tue, Nov 20, 2007 at 12:27:32PM +0530, Alok Sharma wrote: >> Hi, >> Need a bit of help. >> Given a path we have ways to get the uri using the method uri_for(path). >> Is there a possible way to get the controller path given the uri so I am >> able >> to do some thing like this >> $c->res->redirect(uri); $c->forward(controller_path(uri)); > > Why can't you start off with a controller action? > > my $action = $c->controller('Foo')->action_for('bar'); # Controller::Foo->bar > > $c->res->redirect($c->uri_for($action)); > $c->forward($action->reverse); > That assumes you know which Controller to start with. I've had this same issue recently. The problems IME are case and attributes. E.g., URIs are all lc() but the corresponding Controller/Action could be any case. /foo/bar might correspond to: MyApp::Controller::Foo::Bar->default() or MyApp::Controller::FOO->bar() or MyApp::Controller::foo->BAR() etc. You have no way of knowing from just a URI, and in my case, that was what I had to go on in my template. The Catalyst::Dispatcher seems to be the correct place to interrogate the action map for any given URL, maybe with get_action_by_path(). Or am I way off base? -- Peter Karman . [EMAIL PROTECTED] . http://peknet.com/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Patch to make ConfigLoader load "local" files
Sorry. This time with an attachment... John Tate wrote: Hi, I've been trying to get C::P::ConfigLoader (0.18) to load "local" configuration files. From my reading of the documentation, if have a Config::General configuration file called "myapp.conf", I should be able to load another file named something like "myapp_local.conf", but I've not been able to make it work. I can't find any other reports of this problem, so I'm probably misreading the documentation or misusing the plugin... However, from looking at the code and after adding my own debug calls to C::P::ConfigLoader, I think there might be a problem with the find_files method. When building the list of config files to load, it returns something like "myapp.conf_local" rather than "myapp_local.conf". That file will never get loaded into the configuration because it doesn't have the right file type to be picked up by Config::Any. Attached is a trivial patch that changes the way the method builds the filename, which makes "myapp_local.conf" get loaded as I'd expect. John. -- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE. --- Catalyst-Plugin-ConfigLoader-0.18/lib/Catalyst/Plugin/ConfigLoader.pm 2007-10-14 03:01:31.0 +0100 +++ Catalyst-Plugin-ConfigLoader-0.18.patched/lib/Catalyst/Plugin/ConfigLoader.pm 2007-11-20 12:59:10.81900 + @@ -113,7 +113,8 @@ my @files; if ($extension) { next unless grep { $_ eq $extension } @extensions; -push @files, $path, "${path}_${suffix}"; +my( $fileroot ) = $path =~ m{^(.*?)\.${extension}$}; +push @files, $path, "${fileroot}_${suffix}.${extension}"; } else { @files = map { ( "$path.$_", "${path}_${suffix}.$_" ) } @extensions; } ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Patch to make ConfigLoader load "local" files
Hi, I've been trying to get C::P::ConfigLoader (0.18) to load "local" configuration files. From my reading of the documentation, if have a Config::General configuration file called "myapp.conf", I should be able to load another file named something like "myapp_local.conf", but I've not been able to make it work. I can't find any other reports of this problem, so I'm probably misreading the documentation or misusing the plugin... However, from looking at the code and after adding my own debug calls to C::P::ConfigLoader, I think there might be a problem with the find_files method. When building the list of config files to load, it returns something like "myapp.conf_local" rather than "myapp_local.conf". That file will never get loaded into the configuration because it doesn't have the right file type to be picked up by Config::Any. Attached is a trivial patch that changes the way the method builds the filename, which makes "myapp_local.conf" get loaded as I'd expect. John. -- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] how to get controller path
On Tue, Nov 20, 2007 at 12:27:32PM +0530, Alok Sharma wrote: > Hi, > Need a bit of help. > Given a path we have ways to get the uri using the method uri_for(path). > Is there a possible way to get the controller path given the uri so I am > able > to do some thing like this > $c->res->redirect(uri); $c->forward(controller_path(uri)); Why can't you start off with a controller action? my $action = $c->controller('Foo')->action_for('bar'); # Controller::Foo->bar $c->res->redirect($c->uri_for($action)); $c->forward($action->reverse); -- 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/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] PageCache and SubRequest
Hello All, I have a trouble about PageCache(Cache::FileCache) and SubRequest . The part using SubRequest of the page cannot be cached often . - Controller : use Catalyst qw/SubRequest Cache::FileCache PageCache/; __PACKAGE__->config->{page_cache} = { expires => 300, set_http_headers => 1, debug => 1, }; __PACKAGE__->config->{cache}->{storage} = '/tmp'; sub index : Local { my ( $self, $c ) = @_; $c->cache_page( 300 ); # action $c->stash->{template} = 'index.tt' $c->forward("My::View::TT"); } sub test : Path('/parts/test') { my ( $self, $c ) = @_; $c->response->body('Test'); } - TT (index.tt): Hello [%c.subreq('/parts/test')%] I hope that the page including 'Hello' and 'Test' are cached. But, often I cannot see 'Test' in the cached page. The behavior often happens. Best regards, --- Kyoko Shikamata ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/