Bare-name DSL
ORM::Factory::DSL is an opt-in module that defines factories without the
leading-dot method-call syntax. It is plain Raku (exported subs over a dynamic
builder), so it carries no slang, no macro, no precompilation risk, and full
editor tooling. The canonical dotted form is unchanged and remains the default.
Use this module instead of ORM::Factory; it re-exports the build and query
helpers, so it is self-contained.
1 | |
The three forms
All three define the same factory and dispatch to the same builders. Pick per taste; they can be mixed in one block.
Canonical dotted form (use ORM::Factory):
1 2 3 4 5 6 7 | |
Bare-name keyword form (use ORM::Factory::DSL):
1 2 3 4 5 6 7 | |
Colon-pair form (also ORM::Factory::DSL):
1 2 3 4 5 6 7 8 | |
Keywords
Every DSL keyword is available as a bare sub: factory, variant, transient,
sequence, association, before, after, callback, to-create,
initialize-with, skip-create, variants-for-enum, plus define and
modify. They dispatch to the active builder, so nested blocks (factory,
variant, transient) retarget correctly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Attributes: attr vs attrs
attr NAME, VALUE is the explicit setter. A Callable value is a dynamic
(lazily evaluated) attribute, the same as the dotted .name: { ... } form.
attr preserves declaration order, so it is the form to use for a dependent
chain that must read in a fixed order:
1 2 3 4 | |
attrs(:NAME<VALUE>, ...) takes a colon-pair list. A Callable value is again
a dynamic attribute. Because the pairs arrive as named arguments, their order is
not preserved across the list; use sequential attr calls when order
matters.
1 2 3 4 5 6 7 | |
A dynamic value must be a flexible-arity { ... } block, not a strict
-> { ... }, because the evaluator passes the block an argument (the same rule
as the dotted form).
Building
The build and query helpers are re-exported, so no separate use ORM::Factory
is needed: build, create, build-stubbed, attributes-for, the -list and
-pair variants, generate, generate-list, and reload.