This is indeed an excellent solution. The only problem is that it's not a pure perl module. However, after looking at the xs, the actual code for the closed_over function is rather small. For a simple subref:
$i = 12;
$a = sub { $i };
All it took to get $i was this:
B::svref_2object($a)->PADLIST->ARRAYelt(1)->ARRAYelt(1)->SV->object_2s
+vref
The only problem with using this is that I have no idea how it actually works. I just assumed that PADLIST contains all the local variables for that reference, but why the two-dimensional AV after that? Or for that matter, why is $i located on the second position of the second array? The others just return a B::SPECIAL, which I have no idea what its purpose is.