NAME

Gears::Component - Base class for application components

SYNOPSIS

package My::App::Component::Cache;

use v5.40;
use Mooish::Base;

extends 'Gears::Component';

has field 'cache_data' => (
	default => sub { {} },
);

sub configure ($self)
{
	# Called first, before build
	# Good place to read configuration
}

sub build ($self)
{
	# Called after configure
	# The programmer can build the component here
}

DESCRIPTION

Gears::Component is the base class for all application components in Gears. It provides access to the main application object and defines a two-phase initialization process through the configure and build methods.

All components maintain a weak reference to the application to prevent circular references. The initialization happens automatically during object construction, with configure called first, followed by build if it's defined in the component class (not inherited).

INTERFACE

Attributes

app

A weak reference to the Gears::App instance. This allows the component to access shared application resources.

Required in constructor

Methods

new

$object = $class->new(%args)

A standard Mooish constructor. Consult "Attributes" section to learn what keys can key passed in %args.

configure

$component->configure()

Called first during component initialization, before build. This method is intended to be overridden by subclasses to perform configuration-related setup. The default implementation is empty.

This method is always called, even if not overridden in the component class.

build

$component->build()

Called after configure during component initialization. This method is intended to be overridden by subclasses to perform component setup that may depend on configuration.

This method is only called if defined directly in the component class, not if inherited from a parent class. This prevents double initialization when extending components, as it is intended to change the application itself.

The default implementation is empty.