import inspect


def make_ref(obj):
    """Makes a reference to the object; the returned string can be used as argument
       to load_obj.

       Parameters
       ----------
       obj: object
           The given object

       Returns
       -------
       str
           The object's reference.
    """
    name = None
    for key in '__qualname__', '__name__':
        val = getattr(obj, key, None)
        if val is not None:
            name = val
            break
    if name is None:
        raise ValueError("cannot make a ref to {!r}: object has no name".format(obj))
    if inspect.ismodule(obj):
        return name
    else:
        module_name = getattr(obj, "__module__", None)
        if module_name is None:
            raise ValueError("cannot make a ref to {!r}: object has no module".format(obj))
        return module_name + ":" + name