in reply to beginner's question regarding objects
bless $class, [ @_ ];
you still want to index it the same way. So, either use the individual accessors:
$e->index( index => $index, type => $type, id => $id, body => { head => $object->head, opinion => $object->opinion, result => $object->result, }, );
or, create a method for the object to dump a structure to index:
sub hashify { my $self = shift; return { %$self } }
which you can later (after converting to the array implementation) change to
my @attributes = qw( head opinion result ); sub hashify { my $self = shift; return { map { $attributes[$_] => $self->[$_] } 0 .. $#$self } }
Update: Note that hashify creates a shallow copy, i.e. it doesn't clone nested references.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: beginner's question regarding objects
by McSvenster (Novice) on Mar 28, 2015 at 13:44 UTC |