Revision history for Switch-Declare
0.03 2026-06-14
- New patterns:
* `case undef` - matches an undefined topic.
* `case ref(TYPE)` / `ref` - ref($topic) [eq "TYPE"]; bare = any ref.
* `case reftype(TYPE)` / `reftype` - underlying type, through blessing.
* `case isa(Class)` - blessed object derived from Class (fast @ISA).
- Undef/type safety: every pattern is now warning-free. An undef topic
matches only `case undef` (else falls to default) instead of warning
and mis-matching `case 0`/`case ""`. Numeric patterns are guarded by
looks_like_number, so a non-numeric topic neither warns ("Argument
isn't numeric") nor mis-matches (`"one" == 0` was true; now it is not).
- The numeric guard is computed once per switch (hoisted), so numeric
switches run on par with an equivalently type-safe hand-written chain.
0.02 2026-06-13
- Fix load failure on perl 5.14-5.20.
0.01 2026-06-12
First release.
- `switch (EXPR) { case PAT { ... } ... default { ... } }` as a real
lexical pragma, recognised only within `use Switch::Declare` scope.
- Compile-time keyword plugin; the construct lowers to a native
conditional expression. No source filter, no smartmatch, no CPAN
dependencies (core perl 5.14+ only).
- Pattern kinds: number (==), string (eq), regex /.../imsx, range
[LO..HI], list [a,b,c] membership, and predicates - either \&name
(also package-qualified, \&Pkg::name) or an inline sub { ... } that
closes over the enclosing lexicals. Each lowers to native ops (regex
compiles to a real OP_MATCH at compile time); there are no runtime
helper subs.
- Statement and expression (value-returning) forms; usable infix.
- Scrutinee evaluated exactly once; first matching case wins; optional
trailing default.
- Fast path: a plain variable/constant scrutinee with single-expression
arms compiles to exactly a hand-written if/elsif chain (0-2% in the
bundled benchmark).
- Dispatch mode: a string-keyed lookup table (>= 4 arms, constant
values) compiles to a single O(1) hash lookup against a compile-time
hash - ~2.5x faster than the if/elsif chain at 20 arms. Chosen
automatically; never changes behaviour.