<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># NAME

MooX::Const - Syntactic sugar for constant and write-once Moo attributes

# VERSION

version v0.3.1

# SYNOPSIS

```perl
use Moo;
use MooX::Const;

use Types::Standard -types;

has thing =&gt; (
  is  =&gt; 'const',
  isa =&gt; ArrayRef[HashRef],
);
```

# DESCRIPTION

This is syntactic sugar for using [Types::Const](https://metacpan.org/pod/Types::Const) with [Moo](https://metacpan.org/pod/Moo). The
SYNOPSIS above is equivalent to:

```perl
use Types::Const -types;

has thing =&gt; (
  is     =&gt; 'ro',
  isa    =&gt; Const[ArrayRef[HashRef]],
  coerce =&gt; 1,
);
```

It modifies the `has` function to support "const" attributes.  These
are read-only ("ro") attributes for references, where the underlying
data structure has been set as read-only.

This will return an error if there is no "isa", the "isa" is not a
[Type::Tiny](https://metacpan.org/pod/Type::Tiny) type, if it is not a reference, or if it is blessed
object.

Simple value types such as `Int` or `Str` are silently converted to
read-only attributes.

As of v0.2.0, it also supports write-once ("wo") attributes for
references:

```perl
has setting =&gt; (
  is  =&gt; 'wo',
  isa =&gt; HashRef,
);
```

This allows you to set the attribute _once_. The value is coerced
into a constant, and cannot be changed again.

# KNOWN ISSUES

Accessing non-existent keys for hash references will throw an
error. This is a feature, not a bug, of read-only hash references, and
it can be used to catch mistakes in code that refer to non-existent
keys.

Unfortunately, this behaviour is not replicated with array references.

# SEE ALSO

[Const::Fast](https://metacpan.org/pod/Const::Fast)

[Moo](https://metacpan.org/pod/Moo)

[Types::Const](https://metacpan.org/pod/Types::Const)

[Type::Tiny](https://metacpan.org/pod/Type::Tiny)

# SOURCE

The development version is on github at [https://github.com/robrwo/MooX-Const](https://github.com/robrwo/MooX-Const)
and may be cloned from [git://github.com/robrwo/MooX-Const.git](git://github.com/robrwo/MooX-Const.git)

# BUGS

Please report any bugs or feature requests on the bugtracker website
[https://github.com/robrwo/MooX-Const/issues](https://github.com/robrwo/MooX-Const/issues)

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

# AUTHOR

Robert Rothenberg &lt;rrwo@cpan.org&gt;

This module was inspired by suggestions from Kang-min Liu åŠ‰åº·æ°‘
&lt;gugod@gugod.org&gt; in a [blog post](http://blogs.perl.org/users/robert_rothenberg/2018/11/typeconst-released.html).

# CONTRIBUTOR

Kang-min Liu åŠ‰åº·æ°‘ &lt;gugod@gugod.org&gt;

# COPYRIGHT AND LICENSE

This software is Copyright (c) 2018-2019 by Robert Rothenberg.

This is free software, licensed under:

```
The Artistic License 2.0 (GPL Compatible)
```
</pre></body></html>