[Catalyst] HOWTO reference config settings from template
Hi, I'm not sure if this is a Catalyst question - How do I reference __PACKAGE__config settings from a Template Toolkit template? I'd like to use the config tool to set values outside the stash. Cheers, jec ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] HOWTO reference config settings from template
Jeff Chimene scribbled on 4/12/07 9:29 AM: Hi, I'm not sure if this is a Catalyst question - How do I reference __PACKAGE__config settings from a Template Toolkit template? I'd like to use the config tool to set values outside the stash. [% c.config.yourconfigkeyhere %] -- Peter Karman . http://peknet.com/ . [EMAIL PROTECTED] ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] HOWTO reference config settings from template
Peter Karman wrote: Jeff Chimene scribbled on 4/12/07 9:29 AM: Hi, I'm not sure if this is a Catalyst question - How do I reference __PACKAGE__config settings from a Template Toolkit template? I'd like to use the config tool to set values outside the stash. [% c.config.yourconfigkeyhere %] Hi Peter, Thank-you for the prompt response. I tried that as one of my first attempts. No joy. I've also tried: [% USE Dumper; dump_html(Catalyst); %] and I don't see the TT2 configuration settings. When I try the similar experiment in the perl module, dump __PACKAGE__-config, the TT2 configuration settings are displayed. Here is the relevant perl code from the P::V I should be able to display any of these variables, right? __PACKAGE__-config({ CATALYST_VAR = 'Catalyst', INCLUDE_PATH = [ fori-path_to( 'root', 'src' ), fori-path_to( 'root', 'lib' ) ], PRE_PROCESS = 'config/main', WRAPPER = 'site/wrapper', ERROR= 'error.tt2', TIMER= 0, FRAMES = 1, }); Here are the TT2 references I've tried. I use ERROR here on the assumption (probably incorrect) that I cannot stick a new value into the config list. Frames = [% Catalyst.config.error %] Frames = [% c.config.error %] Frames = [% Catalyst.config.ERROR %] Frames = [% c.config.error %] Cheers, jec ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] HOWTO reference config settings from template
Jeff Chimene scribbled on 4/12/07 10:35 AM: and I don't see the TT2 configuration settings. When I try the similar experiment in the perl module, dump __PACKAGE__-config, the TT2 configuration settings are displayed. that's because your TT config probably isn't getting set in the master config for your app, which is what c.config returns. Every M/V/C in Catalyst has a config() method (iirc -- please correct me, oh gurus), and the master MyApp class has a config() too, which is where you generally set values for the entire application. You can set your TT config there too. But looking at what you're trying to do, I wonder if what you really want is a TT type config file, which can set constants and other relevant TT stuff. CatRose has an example of how I do it: http://search.cpan.org/src/KARMAN/Catalyst-Controller-Rose-0.01/examples/CatRose/lib/CatRose/View/TT.pm cheers. pek -- Peter Karman . http://peknet.com/ . [EMAIL PROTECTED] ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] little syntax
Hi Will, You want: $c-stash-{recs} = [EMAIL PROTECTED]; And then to access it in the Template Toolkit template, you want: [% FOREACH row IN recs %] id: [% row.id %] name: [% row.name %]br / [% END %] And you should probably check out the following two URLs for more info on Catalyst + Template Toolkit. http://search.cpan.org/dist/Catalyst-Manual/ http://www.template-toolkit.org/docs/plain/Manual/index.html - Jim Will Smith wrote: I have the following piece of code: # in controller ... while ( my $row = $file-read ) { push @record, { id = $row-{id}, name = $row-{name}, }; } $c-stash-{recs} = @records; . What is the syntax on the tt2 to access the id and name? Or please point me to somewhere that I could do some reading on the question. Thank you -- Jim Spath Lead Developer Pangea Media Em: [EMAIL PROTECTED] Ph: 617.314.6687 Fx: 617.390.7824 IM: panJimS (AIM) ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] HOWTO reference config settings from template
Peter Karman wrote: Jeff Chimene scribbled on 4/12/07 10:35 AM: and I don't see the TT2 configuration settings. When I try the similar experiment in the perl module, dump __PACKAGE__-config, the TT2 configuration settings are displayed. that's because your TT config probably isn't getting set in the master config for your app, which is what c.config returns. Every M/V/C in Catalyst has a config() method (iirc -- please correct me, oh gurus), and the master MyApp class has a config() too, which is where you generally set values for the entire application. You can set your TT config there too. But looking at what you're trying to do, I wonder if what you really want is a TT type config file, which can set constants and other relevant TT stuff. CatRose has an example of how I do it: http://search.cpan.org/src/KARMAN/Catalyst-Controller-Rose-0.01/examples/CatRose/lib/CatRose/View/TT.pm cheers. pek Hi Peter, The config is called in the View package (fori::View::Menu) I was hoping to set TT2 values /per package/ via the config as created by the TT2 helper. It looks like (after DEBUG = 'all') that TT2 only references the stash when it resolves variables. I think that I'll look for other ways to solve this problem. Cheers, jec ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] little syntax
Will Smith scribbled on 4/12/07 11:43 AM: I have the following piece of code: # in controller ... while ( my $row = $file-read ) { push @record, { id = $row-{id}, name = $row-{name}, }; } $c-stash-{recs} = @records; . What is the syntax on the tt2 to access the id and name? Or please point me to somewhere that I could do some reading on the question. you want: $c-stash-{recs} = [EMAIL PROTECTED]; and then in tt: [% FOR rec IN recs; rec.id; rec.name; END %] -- Peter Karman . http://peknet.com/ . [EMAIL PROTECTED] ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Handling slow uploads externally
Hello all, I have a CMS-like application using Catalyst for which about 40-50% of requests contain large file uploads. I'm using a pretty standard two-tiered setup to avoid tying up heavy mod_perl procs for slow client downloads. Now I'd like to avoid tying up the heavy procs for slow uploads. Many suggest to run upload handlers as CGI rather than mod_perl because the 1s startup time is negligent compared to the time required to upload. I have tried this and it works, but it still creates a 60+ MB process to sit around for 2 minutes while a dial up user uploads a huge image. I'm thinking of splitting file upload handling out to a simple CGI app (no Catalyst code) that serializes the request, including uploaded files, to a tmp directory. It would then redirect to a Catalyst-handled URL matching the serialized request. Then I can validate the submission in Catalyst and display success or error using my views, etc. Is there something like this in existence already? I searched Google and CPAN but didn't find anything promising. I'd appreciate any tips or suggestions. If I do implement it from scratch, would there be any interest in the CGI and a Catalyst base controller being released on CPAN? Best, Brian Kirkbride ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Handling slow uploads externally
Brian Kirkbride scribbled on 4/12/07 12:16 PM: Is there something like this in existence already? I searched Google and CPAN but didn't find anything promising. I'd appreciate any tips or suggestions. If I do implement it from scratch, would there be any interest in the CGI and a Catalyst base controller being released on CPAN? I'd be interested in collaborating on something if you end up rolling your own. We were looking at this recently: http://trac.lighttpd.net/trac/wiki/Docs%3AModUploadProgress and doing something similar to what you're describing. -- Peter Karman . http://peknet.com/ . [EMAIL PROTECTED] ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] HOWTO reference config settings from template
On Apr 12, 2007, at 1:01 PM, Jeff Chimene wrote: The config is called in the View package (fori::View::Menu) I was hoping to set TT2 values /per package/ via the config as created by the TT2 helper. It looks like (after DEBUG = 'all') that TT2 only references the stash when it resolves variables. What is the problem you are trying to solve? Changing the template processor configuration from within a template that it is currently processing doesn't seem wise to me. That being said, the reason that only the stash variables are accessible is because they are all that are provided to TT by default... package MyApp::View::TT; sub template_vars { my ( $self, $c ) = @_; my %vars = $self-SUPER::template_vars( $c ); $vars{ 'ttconfig' } = $self-config; return %vars; } -- Jason Kohles [EMAIL PROTECTED] http://www.jasonkohles.com/ A witty saying proves nothing. -- Voltaire ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] little syntax
On Thu, Apr 12, 2007 at 09:43:07AM -0700, Will Smith wrote: I have the following piece of code: # in controller ... while ( my $row = $file-read ) { Template Toolkit also has WHILE so you could just pass in $file Extensive use of $c-log-_dump or [% USE Dumper %] or other variations can save a lot of time when dealing with the templates. -- Bill Moseley [EMAIL PROTECTED] ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Re: Handling slow uploads externally
Hi Brian, * Brian Kirkbride [EMAIL PROTECTED] [2007-04-12 19:25]: I have a CMS-like application using Catalyst for which about 40-50% of requests contain large file uploads. I'm using a pretty standard two-tiered setup to avoid tying up heavy mod_perl procs for slow client downloads. […] I'm thinking of splitting file upload handling out to a simple CGI app (no Catalyst code) that serializes the request, including uploaded files, to a tmp directory. It would then redirect to a Catalyst-handled URL matching the serialized request. My suggestion is to do something much more transparent. Use a CGI script on the front-end webserver to accept uploads. When the upload completes, the CGI script then in turn makes a HTTP request to the application webserver server to upload the file, and returns the app’s response to the client. That way, the actual application itself does not need to change at all. There is no serialisation mechanism, no extra code in the application to handle such a special upload mechanism, no need for configuration of filesystem paths or other shared resources, nothing. The handling is isolated on the front-end webserver. This way, a programming consideration becomes a mere deployment consideration. HTTP is great like that. Is there something like this in existence already? I searched Google and CPAN but didn't find anything promising. I'd appreciate any tips or suggestions. If I do implement it from scratch, would there be any interest in the CGI and a Catalyst base controller being released on CPAN? Sometimes, there is no code to do something because no code is needed to do it. :-) Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/ ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Re: internal redirect
Hi Adeola, * Adeola Awoyemi [EMAIL PROTECTED] [2007-04-11 16:40]: In my application I'm generating images on the fly and want to redirect to the image if creation succeeds. I tried using $c-response-redirect( $new_filepath ) but that issues a 302 Temporarily Moved status. But what I actually want is a way to do the redirect outside of the response chain. how to do this has been answered, but I want to point out that you may not actually want to do it. If the request is not for the canonical address of the image, then you should use an external redirect. Otherwise, the URL that the browser sees is not that of the image, but that of eg. a form action address, and people will bookmark (or paste in a forum, or whatever) the wrong link. This is particularly important if you are generating an image in response to a POST request. If you don’t respond with an external redirect to a POST, then users hitting the Back button might re-submit the form. You should use the internal redirect only if the browser is already sending a request for the canonical address for the image and it should always use this URL to request the image you are generating. This might be the case if the image you are generating is a thumbnail, f.ex. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/ ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Handling slow uploads externally
On 4/12/07, Brian Kirkbride [EMAIL PROTECTED] wrote: Now I'd like to avoid tying up the heavy procs for slow uploads. Many suggest to run upload handlers as CGI rather than mod_perl because the 1s startup time is negligent compared to the time required to upload. I have tried this and it works, but it still creates a 60+ MB process to sit around for 2 minutes while a dial up user uploads a huge image. Yeah, I was reading that and thinking that you'll probably use more memory for CGI, since you still have to run perl but you don't get any copy-on-write benefit. It could be offset by loading as few modules as possible into the CGI, but that seems kind of ugly. A better solution would be a proxy that buffers uploads. I thought mod_proxy would do this for you. Are you certain that it doesn't? If so, take a look at the other proxy options out there. - Perrin ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] new C::P::A::LDAP for new-style C::P::A
Mentioned on irc, but you can drop the Credential portion of this altogether. All you need to do is use the standard Password credential and set the password_type config option to be 'self_check', and it will do what you want, actually almost _exactly_ what your code does in fact. The check_password() method is called against the user object, though, not the store. Beyond that, I have not worked with LDAP in a very long time so the other bits someone else will have to comment on. Jay On Apr 12, 2007, at 2:10 PM, Evan Carroll wrote: I've create a new version of C::P::A::LDAP to work with the new C::P::A api more info at a: http://search.cpan.org/~jayk/Catalyst-Plugin-Authentication/lib/ Catalyst/Plugin/Authentication.pm The new version has run-time configuration of dns and rules, this allows namespaces that can be configured at login. This functionality is required by portal like sites that need namespaces for each client/company. It also has full store functionality so it won't hit the directory on each successive call to $c-user. so you can do something like base_dn: dc=%s,dc=%s,ou=clients;o=Company and resolve that on a call to -authenticate( {basedn_values = [ 'foo', 'com'], id = 'username', pw = 'password' } ); As a last note this version also keeps a config object from login which mirrors the C::P::A::LDAP config on compile time, but reflects the modifications made on the call to -authenticate(), this can be accessed with $c-user-config and utilized from within a module. Examples of applications in pod. I don't have any tests created largely because I don't see any useful ones that are easily created, but there is documentation in the .tar.gz as pody.pod. You can find a copy at http://64.200.109.9/LDAP.tar.gz comments welcome. -- Evan Carroll System Lord of the Internets [EMAIL PROTECTED] 888-403-9143 ps unban me from #catalyst. ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/ [EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/ --- America will never be destroyed from the outside. If we falter and lose our freedoms, it will be because we destroyed ourselves. -- Abraham Lincoln ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Handling slow uploads externally
Perrin Harkins wrote: On 4/12/07, Brian Kirkbride [EMAIL PROTECTED] wrote: Now I'd like to avoid tying up the heavy procs for slow uploads. Many suggest to run upload handlers as CGI rather than mod_perl because the 1s startup time is negligent compared to the time required to upload. I have tried this and it works, but it still creates a 60+ MB process to sit around for 2 minutes while a dial up user uploads a huge image. Yeah, I was reading that and thinking that you'll probably use more memory for CGI, since you still have to run perl but you don't get any copy-on-write benefit. It could be offset by loading as few modules as possible into the CGI, but that seems kind of ugly. A better solution would be a proxy that buffers uploads. I thought mod_proxy would do this for you. Are you certain that it doesn't? If so, take a look at the other proxy options out there. - Perrin Perrin, It doesn't look like mod_proxy, which I am currently using, supports this. It looks like Perlbal does however. Any other suggestions? I'd like to avoid Squid as it would be overkill for this application. Thanks! ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Re: Handling slow uploads externally
A. Pagaltzis wrote: Hi Brian, * Brian Kirkbride [EMAIL PROTECTED] [2007-04-12 19:25]: I have a CMS-like application using Catalyst for which about 40-50% of requests contain large file uploads. I'm using a pretty standard two-tiered setup to avoid tying up heavy mod_perl procs for slow client downloads. […] I'm thinking of splitting file upload handling out to a simple CGI app (no Catalyst code) that serializes the request, including uploaded files, to a tmp directory. It would then redirect to a Catalyst-handled URL matching the serialized request. My suggestion is to do something much more transparent. Use a CGI script on the front-end webserver to accept uploads. When the upload completes, the CGI script then in turn makes a HTTP request to the application webserver server to upload the file, and returns the app’s response to the client. That way, the actual application itself does not need to change at all. There is no serialisation mechanism, no extra code in the application to handle such a special upload mechanism, no need for configuration of filesystem paths or other shared resources, nothing. The handling is isolated on the front-end webserver. This way, a programming consideration becomes a mere deployment consideration. HTTP is great like that. Is there something like this in existence already? I searched Google and CPAN but didn't find anything promising. I'd appreciate any tips or suggestions. If I do implement it from scratch, would there be any interest in the CGI and a Catalyst base controller being released on CPAN? Sometimes, there is no code to do something because no code is needed to do it. :-) Wonderful, thank you for the insight Aristotle. I will try Perrin's suggestion of using an upload-buffering proxy first, falling back on a simple CGI proxy like this if need be. ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Handling slow uploads externally
On 4/12/07, Brian Kirkbride [EMAIL PROTECTED] wrote: It doesn't look like mod_proxy, which I am currently using, supports this. It looks like Perlbal does however. Any other suggestions? Since I always use mod_proxy, I can't vouch for any others. I've seen people mention nginx, pound, and pen. It might also be worth asking about this on the mod_proxy list, or checking the archives. - Perrin ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] HOWTO reference config settings from template
Jason Kohles wrote: On Apr 12, 2007, at 1:01 PM, Jeff Chimene wrote: The config is called in the View package (fori::View::Menu) I was hoping to set TT2 values /per package/ via the config as created by the TT2 helper. It looks like (after DEBUG = 'all') that TT2 only references the stash when it resolves variables. What is the problem you are trying to solve? Changing the template processor configuration from within a template that it is currently processing doesn't seem wise to me. That being said, the reason that only the stash variables are accessible is because they are all that are provided to TT by default... package MyApp::View::TT; sub template_vars { my ( $self, $c ) = @_; my %vars = $self-SUPER::template_vars( $c ); $vars{ 'ttconfig' } = $self-config; return %vars; } Hi Jason, Thanks for the reply. The problem I'm trying to solve is referencing (reading) config settings from a template. I'd like to tell one or more templates that sometimes they will use frames sometimes not (debugging). I blithely assumed this would be an appropriate use of configuration variables. I was wrong. I'll use the stash for now. Cheers, jec ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] HOWTO reference config settings from template
On Thu, Apr 12, 2007 at 04:18:06PM -0700, Jeff Chimene wrote: Thanks for the reply. The problem I'm trying to solve is referencing (reading) config settings from a template. I'd like to tell one or more templates that sometimes they will use frames sometimes not (debugging). I blithely assumed this would be an appropriate use of configuration variables. I was wrong. I'll use the stash for now. What's View is generating your templates? you can't do [% c.config.foo %] ? How about: [% USE Dumper; Dumper.dump( c.config ) | stderr %] Maybe your View isn't stuffing $c into the stash, or is using a different name (see C::View::TT). -- Bill Moseley [EMAIL PROTECTED] ___ List: [EMAIL PROTECTED] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/