Opt-in handlers for YAML tags.
Nothing is registered by default. A tag with no handler stays an
%ASDF.Tagged{}. The tag string is never turned into a module name.
A handler is a module that implements ASDF.Registry.Handler.
decode/1 returns {:ok, term} or {:error, %ASDF.Error{}}.
Registering one is the caller's decision. Handlers live in
:persistent_term for the VM.
Examples
iex> defmodule NoteHandler do
...> @behaviour ASDF.Registry.Handler
...> @impl true
...> def decode(%{"text" => text}) when is_binary(text), do: {:ok, text}
...> def decode(_value) do
...> ASDF.Error.wrap(reason: :invalid_tag, message: "note text is missing")
...> end
...> end
...> ASDF.Registry.register("tag:example:note-1.0.0", NoteHandler)
...> result = NoteHandler.decode(%{"text" => "hi"})
...> ASDF.Registry.unregister("tag:example:note-1.0.0")
...> result
{:ok, "hi"}
Summary
Functions
Returns the registered module for tag.
Registers module as the handler for tag.
Removes one handler, or every handler.
Functions
Returns the registered module for tag.
tag is an expanded URI. Returns {:ok, module} or :error when the
tag is left as %ASDF.Tagged{}. Does not raise.
Examples
iex> ASDF.Registry.fetch("tag:example:not-registered")
:error
Registers module as the handler for tag.
tag is the expanded tag URI. module is a module with decode/1.
Returns :ok. A later register for the same tag replaces the module.
Does not raise. Does not check that module exports decode/1.
Examples
iex> defmodule PassthroughHandler do
...> @behaviour ASDF.Registry.Handler
...> @impl true
...> def decode(value), do: {:ok, value}
...> end
...> :ok = ASDF.Registry.register("tag:example:pass-1.0.0", PassthroughHandler)
...> fetched = ASDF.Registry.fetch("tag:example:pass-1.0.0")
...> ASDF.Registry.unregister("tag:example:pass-1.0.0")
...> fetched == {:ok, PassthroughHandler}
true
@spec unregister(String.t() | :all) :: :ok
Removes one handler, or every handler.
tag is an expanded URI, or :all when omitted. Returns :ok.
Removing a tag that was not registered is still :ok. Does not raise.
Examples
iex> defmodule TempHandler do
...> def decode(value), do: {:ok, value}
...> end
...> ASDF.Registry.register("tag:example:temp-1.0.0", TempHandler)
...> ASDF.Registry.unregister("tag:example:temp-1.0.0")
...> ASDF.Registry.fetch("tag:example:temp-1.0.0")
:error
iex> ASDF.Registry.unregister()
:ok