Following Andreas' advice, the dump of the all now displays!
What I did is add (to the main application module)
sub end : Private {
my ( $self, $c ) = @_;
$c->forward('test::View::Mason');
}
Good. Now modify the list method in the test::Controller::db.pm
sub list : Local {
use Data::Dumper;
my ( $self, $c ) = @_;
my (@all);
@all = test::Model::Database::Testing->search();
$c->stash->{stuff}=Dumper(@all);
push @{$c->stash->{data}},@all;
$c->stash->{template}="test.html";
$c->forward( 'test::View::Mason');
}
so that $c->stash->{data} has the stuff I want to display in the view,
and then modify the view so that it does something with the incoming
data ...
<%args>
$stuff => undef
$data => undef
</%args>
% use Data::Dumper;
% my ($k,$string,$dump,$maxid);
% $dump = Dumper($data);
% $maxid=-10;
in Test.html: Dumping....<br />
<hr />
<pre>
<% $stuff %>
</pre>
<hr />
<!-- Dump of data = <% $dump %> -->
<pre>
% foreach (@{$data})
% {
% $string = undef;
% if ($maxid < $_->{_column_data}->{id}) { $maxid $_->{_column_data}->{id}; }
% foreach $k (keys %{$_->{_column_data}})
% {
% $string .= sprintf "| %s ",$_->{_column_data}->{$k};
% }
<% $string %>
% }
</pre>
and we get (ignoring the dump)
a | 1 | b
c | 2 | d
d | 3 | e
which is exactly what I wanted.
Great!
So to mix it up, now I want to add a tiny form at the end of this to add
another row to the database. So I appended
<form action="add" method="post">
Name: <input type="text" name="name" value="" size@ /> <br />
Size: <input type="text" name="size" value="" size@ /> <br />
ID: <input type="text" name="id" value="<% $maxid+1 %>" size@ />
<br />
<input type="submit" value="submit">
</form>
to the test.html, and created an add method in test::Controller::db.pm
sub add : Local {
my ( $self, $c ) = @_;
my (@all,%all2);
%all2 =$c->parameters;
$c->stash->{stuff}=Dumper(\%all2);
$c->stash->{template}="test.html";
$c->forward( 'test::View::Mason');
}
The idea is that $c->{parameters} is a hash of the incoming posted
parameters.
Unfortunately, it seems to get lost somewhere. I see it in the debug
messages on the console
[Wed Dec 28 15:29:37 2005] [catalyst] [debug]
**********************************
[Wed Dec 28 15:29:37 2005] [catalyst] [debug] * Request 1 (0.250/s) [26826]
[Wed Dec 28 15:29:37 2005] [catalyst] [debug]
**********************************
[Wed Dec 28 15:29:37 2005] [catalyst] [debug] Body Parameters are:
.---------------------------------------+--------------------------------------.
Key | Value
+---------------------------------------+--------------------------------------+
id | 4
name | asdasdasd
size | asdasdasda
'---------------------------------------+--------------------------------------'
[Wed Dec 28 15:29:37 2005] [catalyst] [debug] "POST" request for
"db/add" from "192.168.1.32"
[Wed Dec 28 15:29:37 2005] [catalyst] [debug] Path is "db/add"
[Wed Dec 28 15:29:37 2005] [catalyst] [debug] Rendering component
"/test.html"
[Wed Dec 28 15:29:37 2005] [catalyst] [debug] Rendering component
"/test.html"
[Wed Dec 28 15:29:37 2005] [catalyst] [info] Request took 0.018545s
(53.923/s)
.------------------------------------------------------------------+-----------.
Action |
Time |
+------------------------------------------------------------------+-----------+
-> test::View::Mason->process |
0.002368s |
/db/add |
0.002898s |
-> test::View::Mason->process |
0.000978s |
/end |
0.001180s |
'------------------------------------------------------------------+-----------'
but it does not show up in the method call. Is there some magic I need
to do here? I will look back over the Agave and other examples.
Somewhat confused here. Is there any way to force the debug screen even
on successful calls?
Joe
Andreas Marienborg wrote:
I saw your other post, but figured I would comment some bits :)
On 28. des. 2005, at 07.46, Joe Landman wrote:
I added a simple global list method to the db controller
sub list : Global {
use Data::Dumper;
my ( $self, $c ) = @_;
my (@all);
@all = test::Model::Database::Testing->search();
$c->forward( 'test::View::Mason');
put this in the 'sub end : Private { } of your base application, so you
dont have to do it for each controller you write :P This also ensures
that everything you put in the stash is visible upon rendering.
You can also check out the DefaultEnd plugin, which is a grand idea :)
$c->stash->{stuff}=Dumper(@all);
}
--
Joseph Landman, Ph.D
Founder and CEO
Scalable Informatics LLC,
email:
[email protected]web :
http://www.scalableinformatics.comphone: +1 734 786 8423
fax : +1 734 786 8452
cell : +1 734 612 4615