NAME

Gears::App - Main application class

SYNOPSIS

package My::App;

use v5.40;
use Mooish::Base;

extends 'Gears::App';

sub build ($self)
{
	$app->load_controller('User');
	$app->load_controller('Blog');
}

# Later in your code
my $app = My::App->new(
	router => $router,
	config => $config,
);

DESCRIPTION

Gears::App is the main application class that ties together the core components of a Gears application. It extends Gears::Component and serves as the central hub that holds references to the router, configuration, and loaded controllers.

The application object is passed to all components, providing them with access to the shared application state. Controllers can be dynamically loaded and are automatically configured with a reference to the application.

EXTENDING

Application classes should extend Gears::App and can add their own attributes and methods. The application object is available to all components and controllers, making it a good place to store shared application state.

Example:

package My::App;

use v5.40;
use Mooish::Base;

extends 'Gears::App';

has field 'database' => (
	isa => InstanceOf['DBI::db'],
	builder => 1,
);

sub _build_database ($self)
{
	# Initialize database connection
	return DBI->connect(...);
}

INTERFACE

Attributes

router

A Gears::Router instance that handles routing for the application.

Required in constructor

config

A Gears::Config instance that manages application configuration.

Required in constructor

controllers

An array reference containing all loaded Gears::Controller instances.

Not available in constructor

app

While this attribute is derived from Gears::Component, it makes little sense in app object. It is set to point at the object itself and removed from constructor arguments.

Not available in constructor

Methods

new

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

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

load_controller

$app = $app->load_controller($name)

Loads a controller by name and adds it to the application's controller list. The controller name is resolved relative to the application's namespace with ::Controller appended. For example, if your application is My::App and you call load_controller('User'), it will load My::App::Controller::User.

Returns the application object for method chaining.