I've heard that KiokuDB can (de)serialize closures including all variables they closed over, so maybe it might be worth for you to look at how KiokuDB does it. (Or ask on their IRC channel, they are generally rather helpful if you have a bit of patience).