A thing of beauty it is…

I’ve spent about the last three weeks converting much of the infrastructure code for AnteSpam to use AnyEvent.

One of the small bits of fallout from using AnyEvent is that we now have a large number of anonymous code references as callbacks, and in our logging code, these all have the same name: __ANON__.

This makes debugging output a little less useful.

In browsing some code in AnyEvent::SMTP, I happened across the trick of locally setting the __ANON__ typeglob to the name you want to use used in stacktraces and the like:

my $var = sub { local *__ANON__ = 'What::ever::you::want'; ... };

So, this is kinda ugly, and I couldn’t find any official documentation of it, so I went looking around, and found Sub::Name, which is a module to make this a little more palatable. Now we can do:

my $var = subname 'What::ever::you::want' => sub { ... };

Still perhaps not beautiful, but not totally covered in warts, either.

Now to go retrofit this onto all of our code…