<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def on(cls, event, handler_func=None):
 """ Registers a handler function whenever an instance of the model emits the given event. This method can either called directly, passing a function reference: MyModel.on('did_save', my_function) @MyModel.on('did_save') def myfunction(my_model):
 pass """

        if handler_func:
            cls.handler_registrar().register(event, handler_func)
            return

        def register(fn):
            cls.handler_registrar().register(event, fn)
            return fn

        return register