Langertha-Knarr
view release on metacpan or search on metacpan
.claude/skills/perl-moo/SKILL.md view on Meta::CPAN
---
## Type Constraints
Moo has no built-in type system. `isa` takes a coderef:
```perl
use Types::Standard qw(Str Int ArrayRef);
has name => (is => 'ro', isa => Str);
has tags => (is => 'ro', isa => ArrayRef[Str], default => sub { [] });
```
`Type::Tiny` / `Types::Standard` is the official recommendation in Moo docs (replaces `MooseX::Types`).
---
## Decision Guide
| Situation | Use |
|---|---|
.claude/skills/perl-moose/SKILL.md view on Meta::CPAN
```
Use `method` (not `sub`) inside `role { }` block. Non-core â adds `MooseX::Role::Parameterized` dependency.
---
## Pattern 7 â Attribute Options Cheatsheet
```perl
has name => (is => 'ro', required => 1);
has tags => (is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }); # ALWAYS coderef for refs
has content => (is => 'lazy'); # built on first access
sub _build_content { "generated: " . $_[0]->name }
has status => (
is => 'rw',
isa => 'Str',
trigger => sub { # fires on new() and set
my ($self, $new, $old) = @_; # $old is undef on construction
die "bad status" unless $new =~ /\A(new|ok|done)\z/;
},
.claude/skills/perl-moose/SKILL.md view on Meta::CPAN
where { $_ > 0 },
message { "$_ is not a positive integer" };
coerce 'PositiveInt',
from 'Str',
via { int($_) };
# Or use Type::Tiny (recommended â works with both Moo and Moose):
use Types::Standard qw(Str Int ArrayRef InstanceOf);
has name => (is => 'ro', isa => Str);
has items => (is => 'ro', isa => ArrayRef[Str], default => sub { [] });
```
Prefer `Type::Tiny` / `Types::Standard` â portable between Moo and Moose, better error messages.
---
## Decision Guide
| Situation | Use |
|---|---|
t/71_router_passthrough_fallback.t view on Meta::CPAN
use Future;
use Langertha::Knarr::Session;
use Langertha::Knarr::Request;
use Langertha::Knarr::Handler::Router;
# Mock router: knows one model, dies on others.
{
package MockRouter;
use Moose;
has known => ( is => 'ro', isa => 'HashRef', default => sub { { 'gpt-test' => 1 } } );
sub resolve {
my ($self, $model) = @_;
die "no such model: $model\n" unless $self->known->{ $model // '' };
return ( MockEngine->new, $model );
}
sub list_models { [ { id => 'gpt-test', object => 'model' } ] }
__PACKAGE__->meta->make_immutable;
}
{
package MockEngine;
( run in 2.836 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )