ASDF.Registry.Handler behaviour (asdf v0.1.0)

Copy Markdown View Source

Behaviour for one YAML tag.

ASDF.Registry.register/2 stores the module. When the reader sees that tag, it calls decode/1 with the tag's value. The tag string is not turned into a module name. A tag with no handler stays an %ASDF.Tagged{}.

A handler replaces the tagged node. It does not choose how the file is parsed.

Example

A handler that reads a small note mapping:

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)

decode/1 receives the mapping after nested tags have been walked. Return {:ok, term} to replace the node, or {:error, %ASDF.Error{}} to fail the read.

Summary

Callbacks

Decodes the tag's value.

Callbacks

decode(value)

@callback decode(value :: term()) :: {:ok, term()} | {:error, ASDF.Error.t()}

Decodes the tag's value.

value is the YAML content of the tagged node. Nested tags have already been walked. Return {:ok, term} to replace the node. Return {:error, %ASDF.Error{}} to fail the read. This callback does not raise.