in reply to syntax question
The “voodoo” here is that new, AUTOLOAD, and can, all become closures.
All of these declarations, including $x, $singleton, and the three subs, all occur within a block. The code executes, defining $x and then $singleton and initializing them both. The subs are defined as returning them. Since the subs will survive the block, and they all now have references to $singleton, each one of them will return a reference to the same object. Once the block ends, the two variables go out-of-scope and thus can no longer be referenced ... except by using the subs provided. Because their reference counts are not zero, and will never become so, they’re like that line from the song, The Highwaymen: “and yet, I’m living still ...”
Voodoo, indeed.