Build strategies
ORM::Factory ships four strategies for turning a factory definition into a
result. They all share the same surface — (Str:D $name, *@variants, *%overrides)
— and dispatch through a small Strategy role.
| Method | What it returns | Persists? |
|---|---|---|
build |
An unsaved instance. | No |
create |
A persisted instance. | Yes |
attributes-for |
A Hash of resolved attributes. |
No |
build-stubbed |
An adapter-stubbed instance (no DB access). | No |
1 2 3 4 | |
Variants
Variants are positional after the factory name:
1 2 | |
An unknown variant raises X::ORM::Factory::UnknownVariant.
Per-call overrides
Override any attribute (static or dynamic) by passing a named arg:
1 2 | |
A Callable override replaces the attribute with a dynamic block evaluated
in the evaluator context — so dependent attributes see the override:
1 2 | |
attributes-for and build-stubbed honour the same overrides.
Collections
1 2 3 4 5 6 | |
The variants form, the overrides form, and the post-build block can be
combined freely; the block is recognised by its Callable type at the tail
of the positional args.
The same shape works for create-list, build-stubbed-list, and
attributes-for-list. The build-pair and create-pair shortcuts are
fixed-count *-list variants returning two instances.
Strategy role (ORM::Factory::Strategy)
The public methods dispatch through a small role:
1 2 3 4 5 6 | |
The four shipped strategies are BuildStrategy, CreateStrategy,
AttributesForStrategy, and BuildStubbedStrategy. Register your own with
ORM::Factory.register-strategy — see Custom strategies.