Fluent numbers with Acme::Numbers
Inspired by a post in the Beautiful Code blog, Simon Wistow created Acme::Numbers, which lets you do cleverness like this:
use Acme::Numbers; print two.hundred."n"; # prints 200 print forty.two."n"; # prints 42 print zero.point.zero.five."n"; # prints 0.05 print four.pounds.fifty.five."n"; # prints "4.55" print four.pounds.fifty.pence."n"; # prints "4.50" print four.dollars.fifty.cents."n"; # prints "4.55"
You probably wouldn't want to do this in production code, but like the best of Damian Conway's not-useful-but-thought-provoking modules, it may spark some ideas that you can apply to more useful situations. If nothing else, the source is a fine lesson in overloading and method importing.