Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# CLAUDE.md — Slack::WebHook

## What is this

A CPAN Perl module for sending Slack webhook notifications with preset colors and layouts.
~250 lines of Perl. Simple, focused, stable.

## Project structure

```
lib/Slack/WebHook.pm — The module (all logic lives here)
t/hooks.t — Test suite (Test2-based, mocks HTTP::Tiny)
examples/ — Example scripts (embedded in POD via Dist::Zilla InsertExample)
dist.ini — Dist::Zilla config (drives build, release, Makefile.PL generation)
cpanfile — Dependencies (used by CI and cpanm)
Makefile.PL — Auto-generated by dist.ini, committed for CI convenience
.github/workflows/ — GitHub Actions CI
```

## Commands

```bash
# Run tests locally
prove -Ilib -v t/hooks.t

# Install test dependencies
cpanm --installdeps .
```

## Architecture

Call flow: `post_*()` → `_notify()` → `notify_slack()` → `_http_post()`

- **`post()`** — Raw message, bypasses attachment formatting
- **`post_ok/warning/error/info()`** — Colored attachment wrappers
- **`post_start/post_end()`** — Timer pair (elapsed time appended to message)
- **`_notify()`** — Normalizes args (string or key-value pairs) → `notify_slack()`
- **`notify_slack()`** — Builds attachment structure with color, title, text, mrkdwn_in
- **`_http_post()`** — UTF-8 auto-detect + JSON encode + HTTP::Tiny post

## Key conventions

- **OO via Simple::Accessor** — `new()` calls `$self->$key($val)` for each constructor arg.
Accessor names must be **lowercase** (e.g., `url`, not `URL`).
- **Build system**: Dist::Zilla. `Makefile.PL` and `README.md` are auto-generated.
Edit `dist.ini` for dependency or metadata changes, not Makefile.PL directly.
- **Examples**: Files in `examples/` are embedded in POD via `[InsertExample]`.
They must have `use Slack::WebHook ();` and be syntactically valid Perl.
- **Minimum Perl**: 5.010 (declared in dist.ini). Don't use features above 5.10.

## Testing

- Tests mock `HTTP::Tiny::post_form` to capture payloads — no real HTTP calls
- `http_post_was_called_with()` is the main assertion helper: decodes JSON payload and compares
- `Test2::Plugin::NoWarnings` is active — unexpected warnings fail tests
- When testing warning paths, use `local $SIG{__WARN__}` to capture and test explicitly
- Mock must return `{ success => 1 }` — `_http_post()` warns on failure responses

## Dependencies

Runtime: `Simple::Accessor`, `HTTP::Tiny` (>= 0.076), `JSON::XS`, `Encode`
Test: `Test2::Bundle::Extended`, `Test2::Tools::Explain`, `Test2::Plugin::NoWarnings`, `Test::MockModule`

## Git workflow

- Branch prefix: `koan.atoomic/*`
- Never commit to master directly
- PRs target master, always draft
Loading