MooX::ShortHas(3pm)

MooX::ShortHas3pm

Shortcuts for common moo has attribute configurations

Usage

Instead of:

    use Moo;
    
    has hro => is => ro => required => 1;
    has hlazy => is => lazy => builder => sub { 2 };
    has hrwp => is => rwp => required => 1;
    has hrw => is => rw => required => 1;

You can now write:

    use Moo;
    use MooX::ShortHas;
    
    ro "hro";
    lazy hlazy => sub { 2 };
    rwp "hrwp";
    rw "hrw";

And options can be added or overridden by appending them:

    ro hro_opt => required => 0;

Version

version 1.202040

Overview

Moo's "has" asks developers to repeat themselves a lot to set up attributes, and since its inceptions the most common configurations of attributes have crystallized through long usage.

This module provides sugar shortcuts that wrap around has under the appropriate names to reduce the effort of setting up an attribute to naming it with a shortcut.

Exports

ro, rwp, rw

These three work the same, they convert a call like this:

    ro $name => @extra_args;

To this corresponding has call:

    has $name => is => ro => required => 1 => @extra_args;

The appending of extra args makes it easy to override the required if necessary.

lazy

This one is slightly different than the others, as lazy arguments don't require a constructor value, but almost always want a builder of some kind:

    lazy $name => @extra_args;

Corresponds to:

    has $name => is => lazy => builder => @extra_args;

The first extra argument is thus expected to be any of the values appropriate for the builder option.

Support

Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at <https://github.com/wchristian/MooX-ShortHas/issues>. You will be notified automatically of any progress on your issue.

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

<https://github.com/wchristian/MooX-ShortHas>

  git clone https://github.com/wchristian/MooX-ShortHas.git

Contributors

•

Graham Knop <[email protected]>

•

Zakariyya Mughal <[email protected]>

•

mst - Matt S. Trout (cpan:MSTROUT) <[email protected]>

Releases

3 releases since Debian 11 (Bullseye); the text changed 1 time.

  1. 11
  2. 12–13

Author

Christian Walde <[email protected]>

From libmoox-shorthas-perl 1.202040-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.