I did not know about state! Thanks. (Previously I said I knew perl 40% now I will get this down to 30)
To the point, how does passing a DBI connection object around separate perl programs should work in the first place? Either by saving it as a string to a (ENV) variable or serialising it and saving it to a file? I do assume you pass said object around different perl executables/programs because you talk about the ENV right?
I have just used Sereal to save a DB connection object to file and read again. It works (i guess fine, tested read-only and from the same executable instance, i.e. create, save, read, execute all in same executable) as far as executing statements. It returns same results as original handle. But when it comes to disconnect() I get a nasty is not a DBI handle (has no magic) (nasty in the sense that it spits out from the guts its SV, RV, IV...
And expectedly I guess because in retrospect I read from DBI:
If you try to create your own handles using bless() then you'll find the DBI will reject them with an "is not a DBI handle (has no magic)" error.
So, is there a best practice to share DB connection objects among separate perl executables or is something not possible and I misunderstood the setting?
And btw that's probably a bug in Sereal not treating DBI connection objects specially?
bw, bliako
Edit/Update: I can also report that the de-serialised db connection object (the one read from file) is cleaned up automatically when out-of-scope. |