API-Docker

 view release on metacpan or  search on metacpan

misc/agent-context/.claude/skills/getty-perl-moo/SKILL.md  view on Meta::CPAN

use Moo;
use MooX::Role::Parameterized::With;
with Counter => { name => 'hits' };             # hits attribute + inc_hits method
```

## Delegation

```perl
package Kitchen;
use Moo;
use Sub::HandlesVia;                            # after use Moo
use namespace::clean;

has counter => ( is => 'ro', required => 1, handles => 'App::Role::CounterAPI' );
# or handles => [qw( inc reset )], or handles => { add => 'push' }

has food => (
  is          => 'ro',
  default     => sub { [] },
  handles_via => 'Array',
  handles     => { add => 'push', find => 'grep' },
);
```

`handles` does not run `isa`/`coerce`/`trigger` on the delegate itself.

## Modifiers and triggers

```perl
before calc => sub { croak 'x<0' if $_[1] < 0 };   # validate; cannot change the return
around calc => sub {
  my ( $orig, $self, @args ) = @_;
  return $self->$orig(@args) + 1;                 # only around can change the return
};
after calc => sub { ... };                        # side effects, logging
```

- Modifiers from several roles stack in composition order; `around` must forward `@_`.
- **`trigger => 1`** calls `_trigger_<name>`; it fires on `new()` and set, not on `default`/`builder`, and gets **no old value** (unlike Moose).

## Lifecycle

```perl
around BUILDARGS => sub {
  my ( $orig, $class, @args ) = @_;
  return { source => $args[0] } if @args == 1 && !ref $args[0];   # normalize
  return $class->$orig(@args);
};

sub FOREIGNBUILDARGS {          # args for a non-Moo parent's constructor
  my ( $class, $args ) = @_;
  return ( $args->{source} );
}

sub BUILD {                     # after all attributes are set; parent→child
  my ( $self, $args ) = @_;
  croak 'invalid' unless length $args->{source};
}
```

Never call `SUPER::BUILD` — Moo runs the chain. Cleanup in `DEMOLISH` (child→parent); never override `DESTROY`.

**Strict constructor:** `use MooX::StrictConstructor;` dies on unknown args (`colour => 'blue'`). `namespace::clean` can sweep its `new` — protect with `-except => ['new']` or fix the import order per the module docs.

## House-style import module

Cross-project boilerplate goes into one `Import::Into` module:

```perl
package My::Mooish;
use Import::Into;
sub import {
  my $target = caller;
  strict->import::into($target);
  warnings->import::into($target);
  Moo->import::into($target);
  namespace::clean->import::into($target);   # after Moo, cleans stray imports
}
```

Order matters: imports → `Moo` → `namespace::clean`. With Moo 2, `strictures` v2.

## Moose interop

Moose loaded before the Moo classes compile (`BEGIN { require Moose }`) → Moo inflates its metaclasses: a Moose class can `extends` a Moo class, a Moo class can `with` a Moose role. Moose-style syntax in Moo (`isa => 'Str'`, `lazy_build`): `MooX::l...



( run in 0.825 second using v1.01-cache-2.11-cpan-4e491c91c6e )