Moved with() under new namespace.
Added checks to ensure an object is passed and contains a __enter and __exit method.
Many thanks for @igorw for helping write the unit tests!