<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def trace_module(module, tracer=tracer, pattern=r".*", flags=0):
 """ Traces given module members using given tracer. :param module: Module to trace. :type module: ModuleType :param tracer: Tracer. :type tracer: object :param pattern: Matching pattern. :type pattern: unicode :param flags: Matching regex flags. :type flags: int :return: Definition success. :rtype: bool :note: Only members exported by **__all__** attribute will be traced. """


    if is_traced(module):
        return False

    global REGISTERED_MODULES

    for name, function in inspect.getmembers(module, inspect.isfunction):
        if name not in module.__all__ or not re.search(pattern, name, flags=flags):
            continue

        trace_function(module, function, tracer)

    for name, cls in inspect.getmembers(module, inspect.isclass):
        if name not in module.__all__ or not re.search(pattern, name, flags=flags):
            continue

        trace_class(cls, tracer, pattern, flags)

    REGISTERED_MODULES.add(module)

    set_traced(module)

    return True