Refactor handling of RESTRICTED classes such as IO and IO::Socket.