Throw a link with a tutorial where the creation of a module with a class is described. When you call a module, a new object is created for which events you can hang handlers.
How many google, but so far I come across only the most primitive articles, and I can not find a simple module with the necessary functionality to peep the code.