Sourcing::Projection

The role automatically composed into all projection classes. Provides event application infrastructure and version tracking.

Attributes

AttributeTypeDescription
$!__current-version__IntIndex of the last event applied during replay. Set to -1 when no events exist, or @events.elems - 1 after replay.

Methods

multi method new(:@initial-events!, |c)

Creates a new projection instance and applies initial events. Malformed events are logged and skipped (resilient projections).

ParameterDescription
:@initial-eventsEvents to apply during construction
|cAdditional arguments passed to bless

Returns: New projection instance with events applied.

method apply(Event $e)

Abstract method that must be implemented by the projection. Called for each event during replay. Projections typically define multiple multi candidates, one per event type.

multi method apply(OrderPlaced $e) {
    $!status = 'placed';
    $!total = $e.total;
}

multi method apply(OrderShipped $e) {
    $!status = 'shipped';
}

How It's Used

You never use this role directly. It's automatically composed when you declare a projection:

projection MyView {
    has Int $.id is projection-id;
    # Sourcing::Projection is automatically composed here
}

See Also