lexically-scoped resource management, port of the Perl module Scope::Guard