Re: [Catalyst] About output in a browser
prints neatly, every line of the directory listing on a separate line in the browser: sub getFiles() { my ( $self, $c ) = @_; print getFiles() !; @{$c-stash-{files}} = `ls -l /home/frodo/`; } It looks like adding a print statement will throw the output into literal mode of some sort. Anyhow, that's not how the output should be made, since a view should be used and at least a minimal tt file. When I chomp the directory lines otained with 'ls -l' and use a simple tt file using pre and a view, everything is fine. But if I add a print statement in the model's method, then even the pre tags are shown in the browser. So since I learn Catalyst and I should be using views, then this behaviour of a print statement is not very important. Cheers, Al ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] About output in a browser
On 28/08/2007, lanas [EMAIL PROTECTED] wrote: Hi folks, In understanding how Catalyst work and how to work with , I'm making very simple stuff, like having a model that only returns a directory listing. I found something curious before starting to make a view. Every line of the directory listing, obtained with 'ls -l', will be chomped if I do not put a print String ! just before it in the model, like this: prints chomped lines, which results in unstructured output in the browser: MyApp01/lib/MyApp01/Model/MyApp01Model.pm sub getFiles() { my ( $self, $c ) = @_; @{$c-stash-{files}} = `ls -l /home/user/`; } prints neatly, every line of the directory listing on a separate line in the browser: sub getFiles() { my ( $self, $c ) = @_; print getFiles() !; @{$c-stash-{files}} = `ls -l /home/frodo/`; } 'getFiles()!' will also get printed in the browser, but I presume this is OK. The output is in the following. There are no view defined at the moment. MyApp01/lib/MyApp01/Controller/Root.pm sub end : ActionClass('RenderView') { my ( $self, $c ) = @_; if (defined $c-stash-{files}) { $c-response-body( @{$c-stash-{files}} ) } else { $c-response-body(NO DATA !); } } Can someone tell me why the output of the directory listing is not the same due to, apparently, the poresence of a print statement ? Are you setting this anywhere...? $c-res-content_type('text/plain'); If not, I think if you view the page source in the browser, you'll see that the linebreaks are there - but the browser is ignoring them because it's treating it as HTML. If you change your output line to: $c-response-body( join br, @{$c-stash-{files}} ) then I think you'll find it looks as you expect. (Not that I'm recommending this as a solution - I definitely recommend using a templating View for most common uses). If you run the scripts/myapp_test.pl file from a command line, you can easily see the exact output that would be sent to your browser. Carl ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] About output in a browser
On Aug 28, 2007, at 6:52 PM, lanas wrote: Can someone tell me why the output of the directory listing is not the same due to, apparently, the poresence of a print statement ? The print statement is being output before the document headers are. Without the print statement, you are getting a content-type of text/ html, which causes everything to run together since the lines are separated with newlines instead of br tags. When you add the print statement, you are preventing the headers from being delivered correctly to the browser, and either the web server or the browser is deciding that since you didn't specify a content-type, it's going to default to text/plain. -- Jason Kohles [EMAIL PROTECTED] http://www.jasonkohles.com/ A witty saying proves nothing. -- Voltaire ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] About output in a browser
FWIW I recently used keywords in TT template filenames to identify which CSS file to use (public,admin portal, customer portal, etc.). But the default wrapper (root/lib/site/wrapper) will use text/plain if the filename has css|js|txt in it. ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] About output in a browser
Hi folks, In understanding how Catalyst work and how to work with , I'm making very simple stuff, like having a model that only returns a directory listing. I found something curious before starting to make a view. Every line of the directory listing, obtained with 'ls -l', will be chomped if I do not put a print String ! just before it in the model, like this: prints chomped lines, which results in unstructured output in the browser: MyApp01/lib/MyApp01/Model/MyApp01Model.pm sub getFiles() { my ( $self, $c ) = @_; @{$c-stash-{files}} = `ls -l /home/user/`; } prints neatly, every line of the directory listing on a separate line in the browser: sub getFiles() { my ( $self, $c ) = @_; print getFiles() !; @{$c-stash-{files}} = `ls -l /home/frodo/`; } 'getFiles()!' will also get printed in the browser, but I presume this is OK. The output is in the following. There are no view defined at the moment. MyApp01/lib/MyApp01/Controller/Root.pm sub end : ActionClass('RenderView') { my ( $self, $c ) = @_; if (defined $c-stash-{files}) { $c-response-body( @{$c-stash-{files}} ) } else { $c-response-body(NO DATA !); } } Can someone tell me why the output of the directory listing is not the same due to, apparently, the poresence of a print statement ? Al ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/