Hi,
I have a DBIC record object like
my $obj = $c-model(Database::Table)-find($id);
The table has very many fields and I would like to put their values in a TT
template without inserting them one by one in the stash.
So I would like to create a hash ref from $obj where the name of the field
On 13/03/07, Octavian Rasnita [EMAIL PROTECTED] wrote:
Hi,
I have a DBIC record object like
my $obj = $c-model(Database::Table)-find($id);
The table has very many fields and I would like to put their values in a TT
template without inserting them one by one in the stash.
So I would like to
On Tue, 13 Mar 2007, Octavian Rasnita wrote:
I have a DBIC record object like
my $obj = $c-model(Database::Table)-find($id);
The table has very many fields and I would like to put their values in a TT
template without inserting them one by one in the stash.
So I would like to create a hash
From: Simon Wilcox [EMAIL PROTECTED]
I just put the object in the stash. TT abstracts the method/hash key
accessor issue for you so that [% obj.name1 %] will work whether obj is an
object with a name1 accessor or a hash with a name1 key.
Ok, then I will use that way. I hoped that the first
On Tue, 13 Mar 2007, Daniel McBrearty wrote:
basically : an object IS a (blessed) hash.
Not necessarily, you can also bless scalars and arrays. A blessed array,
in particular can be a very effective way of improving performance for
certain types of data structures.
You kind of need to
Simon Wilcox wrote:
Not necessarily, you can also bless scalars and arrays. A blessed array,
in particular can be a very effective way of improving performance for
certain types of data structures.
Strictly speaking you can bless any reference, although the most useful
are hashes and
On Tue, 13 Mar 2007, Octavian Rasnita wrote:
From: Simon Wilcox [EMAIL PROTECTED]
I just put the object in the stash. TT abstracts the method/hash key
accessor issue for you so that [% obj.name1 %] will work whether obj is an
object with a name1 accessor or a hash with a name1 key.
I know that an object is a blessed hash, but the DBIC objects are very
complex, and I cannot use
$c-stash($obj);
If I do that, the values from $obj hash reference are not put in the
template like when $obj is a reference to a common hash.
That's why I want to find how to put the key/values
On 3/13/07, Kiki [EMAIL PROTECTED] wrote:
Simon Wilcox wrote:
Not necessarily, you can also bless scalars and arrays. A blessed array,
in particular can be a very effective way of improving performance for
certain types of data structures.
Strictly speaking you can bless any reference,
If I do that, the values from $obj hash reference are not put in the
template like when $obj is a reference to a common hash.
Impossible to know what you mean here without an example of the
template, but I commonly put DBIC objects on the stash, and call
methods on them with the dot operator
On Tue, 13 Mar 2007, Octavian Rasnita wrote:
That's why I want to find how to put the key/values from $obj into a common
hash.
It sounds like this might be a bad design decision. Why would you not want
to group your template variables ?
As your app grows you'd be much more likely to see one
From: Simon Wilcox [EMAIL PROTECTED]
You will have to iterate over the accessors individually to put them into
the stash (I think) but you should be able to use DBIC to do most of the
thinking. Something like (untested):
my $model = $c-model(Database::Table);
foreach my $column
Daniel McBrearty wrote:
basically : an object IS a (blessed) hash.
http://perldoc.perl.org/perlboot.html
You kind of need to understand this, if you don't already. It's worth
having a read through the tutorials.
As others have pointed out, objects can also be created by blessing
other
Is it possible to do that without specifying all the keys by name? Or at
least is there a way to get all the keys from $obj, then loop and create a
hash, something like:
my $hash;
foreach(@keys) {
$hash-{$_} = $obj-$_;
}
You're asking for trouble with something like that. Create a DB column
From: Simon Wilcox [EMAIL PROTECTED]
You will have to iterate over the accessors individually to put them into
the stash (I think) but you should be able to use DBIC to do most of the
thinking. Something like (untested):
my $model = $c-model(Database::Table);
foreach my $column
From: Daniel McBrearty [EMAIL PROTECTED]
Impossible to know what you mean here without an example of the
template, but I commonly put DBIC objects on the stash, and call
methods on them with the dot operator in TT. TT is smart enough to
work out what needs to be done and do it
so whether the
Hi,
The problem appears when I want to use only [% element %] and not [%
obj.element %] in templates.
And I want to use the first way because there are very many variables and it
is more simple.
As others have said, I think this is going to bite you in the arse
later. K-I-S-S. It seems we
On Tuesday 13 March 2007 15:06, Octavian Rasnita wrote:
my $model = $c-model(Database::Table);
foreach my $column (@{$model-columns}) {
$column =~ s{me\.}{}; # strip the prefix DBIC adds
$c-stash-{$column} = $obj-$column;
}
I have tried that, but it gave the following error:
On Tue, 13 Mar 2007, Dave Howorth wrote:
In the context of the original question, it's also worth remembering
that an object is not the same as a hash as far as TT is concerned. It
unifies the syntax to call accessors and to access the members of a
hash. But it does *not* let you access
Bogdan Lucaciu wrote:
On Tuesday 13 March 2007 15:06, Octavian Rasnita wrote:
my $model = $c-model(Database::Table);
foreach my $column (@{$model-columns}) {
$column =~ s{me\.}{}; # strip the prefix DBIC adds
$c-stash-{$column} = $obj-$column;
}
I have tried that, but it gave
From: Matt Lawrence [EMAIL PROTECTED]
Alternatively, get_columns will return a hash (not a reference!) of the
current row.
$c-stash-{obj }= { $row-get_columns };
Oh thanks. Finally I've used
$c-stash-{obj} = $obj;
and I've modified the template, because it seems that it is a better design.
On 3/13/07, Octavian Rasnita [EMAIL PROTECTED] wrote:
Please tell me what it means column inflation.
Check the docs for DBIx::Class::InflateColumn
--
Eden Cardim
Instituto Baiano de Biotecnologia
Núcleo de Biologia Computacional e Gestão de Informações Biotecnológicas
Laboratório de
22 matches
Mail list logo