App-Raider
view release on metacpan or search on metacpan
.claude/skills/perl-io-async-future/SKILL.md view on Meta::CPAN
use Future;
use Future::AsyncAwait;
use IO::Async::Stream;
sub configure {
my ($self, %params) = @_;
for my $key (qw(host port on_connect on_error)) {
$self->{$key} = delete $params{$key} if exists $params{$key};
}
$self->{host} //= 'localhost';
$self->SUPER::configure(%params); # MUST chain â unknown keys die here
}
sub host { $_[0]->{host} }
```
**Rules:**
- `delete` your keys from `%params` before `SUPER::configure` â leftover keys throw `configure_unknown`.
- Parameter validation/defaults go in `configure`, **not** `new` (Notifier owns construction).
- A Notifier only knows its loop after `$loop->add($notifier)` â anything that calls `$self->loop` must run after that.
- Child notifiers (`IO::Async::Stream`, `IO::Async::Timer`) attach via `$self->add_child($child)`; they inherit the loop automatically.
---
## Pattern 2 â TCP Connect (the GC trap)
```perl
async sub connect {
.claude/skills/perl-io-async-future/SKILL.md view on Meta::CPAN
| Sync block-wait (tests/scripts) | `$f->get` |
---
## Common Pitfalls (the recurring ones)
- **Local-variable-only Future** â silent GC. Hold it on `$self`.
- **Async sub whose caller drops the Future** â "lost its returning future". Hold the result.
- **Strong `$self` capture in callback chain** â object never destroyed; reconnect loops leak. `weaken` it.
- **Forgetting to `delete` the held Future on completion** â stale guards block future operations.
- **Not chaining `SUPER::configure`** â defaults silently missing, or unknown keys silently accepted.
- **Returning a Future from `async sub` without `await`** â double-wrapped result.
- **Calling `$self->loop` before `$loop->add($self)`** â `loop` is undef.
- **Mixing `then` and `on_done` thinking they're the same** â `on_done` returns the original Future, your "chain" is actually two parallel observers.
- **Cancelling a Future inside its own callback** â undefined; cancel from outside.
- **Using `Future->new` instead of `$loop->new_future`** when you need loop-aware behavior (the loop variant integrates with timeouts and is the recommended form inside Notifier subclasses).
---
## The Mental Model
.claude/skills/perl-moose/SKILL.md view on Meta::CPAN
around BUILDARGS => sub {
my ($orig, $class, @args) = @_;
# normalize: allow single string arg
return $class->$orig(id => $args[0]) if @args == 1 && !ref $args[0];
$class->$orig(@args);
};
sub BUILD {
my ($self, $args) = @_; # called AFTER all attributes are set
die "SSN required for US" if $self->country eq 'USA' && !$self->ssn;
# don't call SUPER::BUILD â Moose handles the chain (parentâchild order)
}
```
**Rules:**
- Never define `sub new` â use `BUILDARGS`/`BUILD` instead.
- `BUILDARGS`: class method, runs before construction, returns hashref.
- `BUILD`: object method, runs after construction. Moose calls all `BUILD` in the hierarchy automatically.
- Never call `SUPER::BUILD` manually.
- For cleanup: use `DEMOLISH` (childâparent order), never override `DESTROY`.
---
## Pattern 13 â `make_immutable` + `namespace::autoclean`
```perl
package MyClass;
use Moose;
use namespace::autoclean; # remove imported keywords after compile
.claude/skills/perl-moose/SKILL.md view on Meta::CPAN
---
## Common Pitfalls
- `default => []` â **shared state bug**. Always `default => sub { [] }`.
- `extends 'A'; extends 'B'` â replaces, does NOT add. Use `extends 'A', 'B'`.
- Separate `with 'RoleA'; with 'RoleB'` â skips conflict detection. Use one `with`.
- `with` before `has` â `requires` check may fail spuriously. Define `has` first.
- `coerce` on built-in type names â global side effects across the whole program.
- Never define `sub new` â breaks Moose constructor optimization.
- Never call `SUPER::BUILD` manually â Moose handles the chain.
- Never override `DESTROY` â use `DEMOLISH`.
- Forgetting `make_immutable` â significant performance penalty on every `new`.
- `around` without forwarding `@_` correctly â subtle argument loss.
---
## MooseX Extensions (Cheatsheet)
| Module | Purpose |
|---|---|
( run in 0.703 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )