NAME
Catalyst::Seal::Construct - two things built per request that need not be
DESCRIPTION
A controller's BUILD on the context object
The application class's linearized ISA is
MyApp, Catalyst, Catalyst::Component, Moose::Object, Catalyst::Controller
so the per-request context object inherits Catalyst::Controller::BUILD, and BUILDALL runs it on a throwaway object every request:
my $attr_value = $self->merge_config_hashes($actions, $action);
$self->_controller_actions($attr_value);
$self->_all_actions_attributes; # trigger lazy builder
$self->_action_roles; # trigger lazy builder
Two lazy builders fired to compute values derived from class data that stopped changing at setup_finalize. 17.5 us per request inclusive.
The memo here is deliberately narrow. It runs the stock body once per class, and remembers the class only when all three results came out empty, which is the case for a context object built with no arguments. Then it stores *fresh* empty containers into each new instance rather than sharing the remembered ones: a shared actions hash that something wrote to would leak between requests, and _build__all_actions_attributes deletes a key from that hash as it goes.
Anything else, including a real controller being configured at setup with action or actions arguments, takes the stock body.
A Stats object built when stats are off
prepare does
$c->stats($class->stats_class->new)->enable($c->use_stats);
unconditionally, and Catalyst::Stats has tree as a required, non-lazy attribute defaulting to Tree::Simple->new({t => [gettimeofday]}). So a tree is built and the clock read on every request for an object that, with stats disabled, nothing reads again.
With stats enabled this changes nothing: the object is constructed eagerly, at the same point, because the timestamp in that default is the request start and deferring it would move the elapsed time that gets reported.
With stats disabled the construction is deferred to the first read of $c->stats, which usually never comes. It is not shared between requests: a request calling $c->stats->enable(1) would otherwise profile into a tree that outlives it and grows for the life of the worker.
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)