# `Dagger.Mod.Object`
[🔗](https://github.com/dagger/dagger/blob/v0.20.5/sdk/elixir/lib/dagger/mod/object.ex#L1)

Declare a module as an object type.

## Declare an object

Add `use Dagger.Mod.Object` to the Elixir module that want to be a
Dagger module and give a name through `:name` configuration:

    defmodule Potato do
      use Dagger.Mod.Object, name: "Potato"

      # ...
    end

The module also support documentation by using Elixir standard documentation,
`@moduledoc`.

## Declare a function

The module provides a `defn`, a macro for declare a function.
Let's declare a new function named `echo` that accepts a `name` as a string
and return a container that echo a name in the module `Potato` from the previous
section:

    defmodule Potato do
      use Dagger.Mod.Object, name: "Potato"

      defn echo(name: String.t()) :: Dagger.Container.t() do
        dag()
        |> Dagger.Client.container()
        |> Dagger.Container.from("alpine")
        |> Dagger.Container.with_exec(["echo", name])
      end
    end

From the example above, the `defn` allows you to annotate a type to function
arguments and return type by using Elixir Typespec. The type will convert to
a Dagger type when registering a module.

The supported primitive types for now are:

1. `integer()` for a boolean type.
2. `boolean()` for a boolean type.
3. `String.t()` or `binary()` for a string type.
4. `list(type)` or `[type]` for a list type.
5. `type | nil` for optional type.
6. Any type that generated under `Dagger` namespace (`Dagger.Container.t()`,
   `Dagger.Directory.t()`, etc.).

The function also support documentation by using Elixir standard documentation,
`@doc`.

# `function_def`

```elixir
@type function_def() :: {function_name(), keyword()}
```

# `function_name`

```elixir
@type function_name() :: atom()
```

# `decoder_hint`

# `defn`
*macro* 

Declare a function.

# `field`
*macro* 

Declare a field.

# `get_function_cache_policy`

```elixir
@spec get_function_cache_policy(struct()) ::
  Dagger.FunctionCachePolicy.t()
  | {Dagger.FunctionCachePolicy.t(), {:ttl, String.t()}}
  | nil
```

Get function cache policy.

Return `Dagger.FunctionCachePolicy` or `nil` if the function did not specify `@cache` attributes

# `get_function_deprecated`

Get function deprecation reason if deprecated from docs or attribute

Return `{:deprecated, reason}` or `nil` if the function did not specify `@deprecated reason` attributes or `@doc deprecated: "reason" docstring`

# `get_function_doc`

```elixir
@spec get_function_doc(module(), function_name()) :: String.t() | nil
```

Get function documentation.

Return doc string or `nil` if that function didn't have a documentation.

# `get_module_deprecated`

Get module deprecation reason if deprecated from docs annotation metadata

Return `{:deprecated, reason}` or `nil` if the module did not specify `@moduledoc deprecated: "reason"`

# `get_module_doc`

```elixir
@spec get_module_doc(module()) :: String.t() | nil
```

Get module documentation.

Returns module doc string or `nil` if the given module didn't have a documentation.

# `object`
*macro* 

Declare an object struct.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
