Since your object is basically the hash you want with a footnote (the class it's blessed into), you can send the data to elasticsearch just like you'd do with a standard hash. There are a couple of caveats, though:
First: if the elasticsearch API wants a hash and tries to verify that it's a hash with ref, then it may complain because your object isn't just a hash. Second, if the elasticsearch function(s) twiddle the hash, your object will be similarly twiddled. Finally, if the elasticsearch hangs on to the reference, it may bonk your object at some point in the future (alternatively, if you change your object, then elasticsearch could get confused by the change). So if the API is going to play nice, you can simply pass it your object, but if you have any doubts, you can just put in a copy. Here's a quickie example to show what I mean:
$ cat flog.pl #!/usr/bin/env perl use strict; use warnings; my $o = bless {a=>1,b=>2,c=>3}, 'Flog'; my $j = { J => { %$o }, # Make a copy of the object K => $o # or just pass it in }; print "Before:\n"; dumpit($j); $j->{J}{a}=7; $j->{K}{b}=8; $o->{c}=9; print "After:\n"; dumpit($j); sub dumpit { my $t = shift; for my $k ('a' .. 'c') { print "$k : $t->{J}{$k} : $t->{K}{$k} : $o->{$k}\n"; } } Roboticus@Waubli ~ $ perl flog.pl Before: a : 1 : 1 : 1 b : 2 : 2 : 2 c : 3 : 3 : 3 After: a : 7 : 1 : 1 b : 2 : 8 : 8 c : 3 : 9 : 9
In general, I'd suggest sending in a copy unless you *want* the object to be passed around. I mention elasticsearch only because you did. I don't know a thing about it, so I don't know how its API is going to treat your object.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: beginner's question regarding objects
by roboticus
in thread beginner's question regarding objects
by McSvenster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |