Storage needs

[email protected] (Demian Riccardi) Tue, 23 Jun 2015 13:23:07 -0400
Newsgroups perl.moose
Message-ID <CACaGo3OqW19N7M9okMn6A5MJu_u0-sq2g9yExjMKTOd1SqQj+w@mail.gmail.com>
--001a11c2bb14d2c242051932a447
Content-Type: text/plain; charset=UTF-8

Hello,

I'm trying to add storage to my library (HackaMol), and I think I'm close
to getting it to work. My library depends on a non-moose class
(Math::Vector::Real), which I was able to get serialized:

http://stackoverflow.com/questions/6101800/store-a-moose-object-that-has-a-pdl-as-an-attribute/31005543#31005543

Any attributes that are Math::Vector:Real objects serialize, unless they
are an additional level below in the object, e.g.
(ArrayRef[Math::Vector::Real])  In the script below (along with runtime
errors) I can store and load the HackaMol::Atom if I remove the coords
attribute.  The coords attribute has Array traits for storing large numbers
of atomic configurations, a characteristic that is central to HackaMol.

you can see what I added to get the storage to sorta work here:
https://github.com/demianriccardi/HackaMol/commit/384ceb9ce3749d6342fc54df292182442764d180

you'll notice the strange add_custom_type_handler( '[Math::Vector::Real]'
which was a step I was hoping would bring me closer.  Is there a way to get
this to work?

Thanks!

Demian

use Modern::Perl;

use Math::Vector::Real;

use HackaMol;


my $atom = HackaMol::Atom->new(Z=>1, coords=>[V(1,1,2)]);

print $atom->dump;


$atom->store('atom.json');


my $atom_again = HackaMol::Atom->load('atom.json');

print $atom_again->dump;



Object ({1, 1, 2}) does not have a &pack method, cannot collapse at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm
line 209.

MooseX::Storage::Engine::__ANON__(Math::Vector::Real=ARRAY(0x7f93a8805468),
HASH(0x7f93a8f90700)) called at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm
line 254

MooseX::Storage::Engine::__ANON__(ARRAY(0x7f93a882d478),
HASH(0x7f93a8f90700)) called at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm
line 92

MooseX::Storage::Engine::collapse_attribute_value(MooseX::Storage::Engine=HASH(0x7f93ac54b138),
Moose::Meta::Class::__ANON__::SERIAL::2=HASH(0x7f93ab1ec208),
HASH(0x7f93a8f90700)) called at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm
line 62

MooseX::Storage::Engine::collapse_attribute(MooseX::Storage::Engine=HASH(0x7f93ac54b138),
Moose::Meta::Class::__ANON__::SERIAL::2=HASH(0x7f93ab1ec208),
HASH(0x7f93a8f90700)) called at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm
line 145

MooseX::Storage::Engine::map_attributes(MooseX::Storage::Engine=HASH(0x7f93ac54b138),
"collapse_attribute", HASH(0x7f93a8f90700)) called at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm
line 39

MooseX::Storage::Engine::collapse_object(MooseX::Storage::Engine=HASH(0x7f93ac54b138))
called at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Basic.pm
line 14

MooseX::Storage::Basic::pack(HackaMol::Atom=HASH(0x7f93a882d550)) called at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Format/JSON.pm
line 25

MooseX::Storage::Format::JSON::freeze(HackaMol::Atom=HASH(0x7f93a882d550))
called at
/Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/IO/File.pm
line 20

MooseX::Storage::IO::File::store(HackaMol::Atom=HASH(0x7f93a882d550),
"atom.json") called at atom.pl line 6

--001a11c2bb14d2c242051932a447
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello,<div><br></div><div>I&#39;m trying to add storage to=
 my library (HackaMol), and I think I&#39;m close to getting it to work. My=
 library depends on a non-moose class (Math::Vector::Real), which I was abl=
e to get serialized:</div><div><br></div><div><a href=3D"http://stackoverfl=
ow.com/questions/6101800/store-a-moose-object-that-has-a-pdl-as-an-attribut=
e/31005543#31005543">http://stackoverflow.com/questions/6101800/store-a-moo=
se-object-that-has-a-pdl-as-an-attribute/31005543#31005543</a><br></div><di=
v><br></div><div>Any attributes that are Math::Vector:Real objects serializ=
e, unless they are an additional level below in the object, e.g. (ArrayRef[=
Math::Vector::Real]) =C2=A0In the script below (along with runtime errors) =
I can store and load the HackaMol::Atom if I remove the coords attribute.=
=C2=A0 The coords attribute has Array traits for storing large numbers of a=
tomic configurations, a characteristic that is central to HackaMol.</div><d=
iv><br></div><div>you can see what I added to get the storage to sorta work=
 here:</div><div><a href=3D"https://github.com/demianriccardi/HackaMol/comm=
it/384ceb9ce3749d6342fc54df292182442764d180">https://github.com/demianricca=
rdi/HackaMol/commit/384ceb9ce3749d6342fc54df292182442764d180</a><br></div><=
div><br></div><div>you&#39;ll notice the strange=C2=A0<span style=3D"color:=
rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,=
monospace;font-size:12px;line-height:16px;white-space:pre;background-color:=
rgb(234,255,234)">add_custom_type_handler(</span>=C2=A0&#39;[Math::Vector::=
Real]&#39; =C2=A0 which was a step I was hoping would bring me closer.=C2=
=A0 Is there a way to get this to work? =C2=A0</div><div><br></div><div>Tha=
nks!</div><div><br></div><div>Demian</div><div><br></div><div><p style=3D"m=
argin:0px;font-size:18px;font-family:Consolas"><span style=3D"color:rgb(206=
,121,36)">use </span>Modern::Perl;</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span style=3D"=
color:rgb(206,121,36)">use </span>Math::Vector::Real;</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span style=3D"=
color:rgb(206,121,36)">use </span>HackaMol;</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas;min-height:21px"=
><br></p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span style=3D"=
color:rgb(206,121,36)">my</span> <span style=3D"color:rgb(52,187,199)">$ato=
m</span> =3D HackaMol::Atom-&gt;new(<span style=3D"color:rgb(195,55,32)">Z<=
/span>=3D&gt;<span style=3D"color:rgb(195,55,32)">1</span>, <span style=3D"=
color:rgb(195,55,32)">coords</span>=3D&gt;[V(<span style=3D"color:rgb(195,5=
5,32)">1</span>,<span style=3D"color:rgb(195,55,32)">1</span>,<span style=
=3D"color:rgb(195,55,32)">2</span>)]);</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas;color:rgb(52,187=
,199)"><span style=3D"color:rgb(206,121,36)">print</span><span style=3D"col=
or:rgb(0,0,0)">=C2=A0</span>$atom-&gt;dump<span style=3D"color:rgb(0,0,0)">=
;</span><br></p><p style=3D"margin:0px;font-size:18px;font-family:Consolas;=
color:rgb(52,187,199)"><span style=3D"color:rgb(0,0,0)"><br></span></p><p s=
tyle=3D"margin:0px;font-size:18px;font-family:Consolas;color:rgb(52,187,199=
)">$atom-&gt;store<span style=3D"color:rgb(0,0,0)">(</span><span style=3D"c=
olor:rgb(195,55,32)">&#39;atom.json&#39;</span><span style=3D"color:rgb(0,0=
,0)">);</span></p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas;color:rgb(52,187=
,199)"><br></p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span style=3D"=
color:rgb(206,121,36)">my</span> <span style=3D"color:rgb(52,187,199)">$ato=
m_again</span> =3D HackaMol::Atom-&gt;load(<span style=3D"color:rgb(195,55,=
32)">&#39;atom.json&#39;</span>);</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas;color:rgb(52,187=
,199)"><span style=3D"color:rgb(206,121,36)">print</span><span style=3D"col=
or:rgb(0,0,0)"> </span>$atom_again-&gt;dump<span style=3D"color:rgb(0,0,0)"=
>;</span></p></div><div><br></div><div><br></div><div><br></div><div><p sty=
le=3D"margin:0px;font-size:18px;font-family:Consolas">Object ({1, 1, 2}) do=
es not have a &amp;pack method, cannot collapse at /Users/riccade/perl5/per=
lbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm line 209=
.</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::Engine::__ANON__(Math:=
:Vector::Real=3DARRAY(0x7f93a8805468), HASH(0x7f93a8f90700)) called at /Use=
rs/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storag=
e/Engine.pm line 254</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::Engine::__ANON__(ARRAY=
(0x7f93a882d478), HASH(0x7f93a8f90700)) called at /Users/riccade/perl5/perl=
brew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm line 92</=
p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::Engine::collapse_attri=
bute_value(MooseX::Storage::Engine=3DHASH(0x7f93ac54b138), Moose::Meta::Cla=
ss::__ANON__::SERIAL::2=3DHASH(0x7f93ab1ec208), HASH(0x7f93a8f90700)) calle=
d at /Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/Moos=
eX/Storage/Engine.pm line 62</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::Engine::collapse_attri=
bute(MooseX::Storage::Engine=3DHASH(0x7f93ac54b138), Moose::Meta::Class::__=
ANON__::SERIAL::2=3DHASH(0x7f93ab1ec208), HASH(0x7f93a8f90700)) called at /=
Users/riccade/perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Sto=
rage/Engine.pm line 145</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::Engine::map_attributes=
(MooseX::Storage::Engine=3DHASH(0x7f93ac54b138), &quot;collapse_attribute&q=
uot;, HASH(0x7f93a8f90700)) called at /Users/riccade/perl5/perlbrew/perls/p=
5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Engine.pm line 39</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::Engine::collapse_objec=
t(MooseX::Storage::Engine=3DHASH(0x7f93ac54b138)) called at /Users/riccade/=
perl5/perlbrew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Basic.pm =
line 14</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::Basic::pack(HackaMol::=
Atom=3DHASH(0x7f93a882d550)) called at /Users/riccade/perl5/perlbrew/perls/=
p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/Format/JSON.pm line 25</p>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::Format::JSON::freeze(H=
ackaMol::Atom=3DHASH(0x7f93a882d550)) called at /Users/riccade/perl5/perlbr=
ew/perls/p5.20.1t/lib/site_perl/5.20.1/MooseX/Storage/IO/File.pm line 20</p=
>
<p style=3D"margin:0px;font-size:18px;font-family:Consolas"><span class=3D"=
" style=3D"white-space:pre">	</span>MooseX::Storage::IO::File::store(HackaM=
ol::Atom=3DHASH(0x7f93a882d550), &quot;atom.json&quot;) called at <a href=
=3D"http://atom.pl">atom.pl</a> line 6</p></div><div><br></div><div><br></d=
iv><div><br></div></div>

--001a11c2bb14d2c242051932a447--