GX::Application

Module Version: 0.2000_02

NAME

GX::Application - Base class for applications

SYNOPSIS

package MyApp;

use GX::Application;

MyApp->setup(
engine => 'Apache2',
mode => 'development'
);

MyApp->start;

1;

DESCRIPTION

This module provides the GX::Application class which extends the GX::Class::Singleton class.

METHODS

Constructor

new

Returns the application instance.

$application = $application_class->new;
Returns:
Exceptions:

Public Methods

All public methods can be called both as instance and class methods.

action

Returns the action object that represents the specified action.

$action = $application->action( $controller_name, $action_name );
Arguments:
  • $controller_name ( string )

    The qualified or unqualified name of the controller component the action belongs to.

  • $action_name ( string )

    The name of the action.

Returns:

actions

Returns all action objects.

@actions = $application->actions;
Returns:

cache

Returns the instance of the specified cache component or, if called without arguments, the default cache component.

$cache = $application->cache( $cache_name );
Arguments:
  • $cache_name ( string ) [ optional ]

    A qualified or unqualified cache component name.

Returns:

caches

Returns all cache component instances.

@caches = $application->caches;
Returns:

components

Returns a list with the class names of the application's components in the order they were registered.

@components = $application->components;
Returns:
  • @components ( strings )

controller

Returns the instance of the specified controller component.

$controller = $application->controller( $controller_name );
Arguments:
  • $controller_name ( string )

    A qualified or unqualified controller component name.

Returns:

controllers

Returns all controller component instances.

@controllers = $application->controllers;
Returns:

database

Returns the instance of the specified database component or, if called without arguments, the default database component.

$database = $application->database( $database_name );
Arguments:
  • $database_name ( string ) [ optional ]

    A qualified or unqualified database component name.

Returns:

databases

Returns all database component instances.

@databases = $application->databases;
Returns:

default_encoding

Returns the application-wide default encoding.

$encoding = $application->default_encoding;
Returns:
  • $encoding ( string )

dispatcher

Returns the dispatcher component instance.

$dispatcher = $application->dispatcher;
Returns:

engine

Returns the engine component instance.

$engine = $application->engine;
Returns:

handlers

Returns all handler objects.

@handlers = $application->handlers;
Returns:

hook

Returns the specified hook object.

$hook = $application->hook( $hook_name );
Arguments:
  • $hook_name ( string )
Returns:

hooks

Returns all hooks in order of execution.

@hooks = $application->hooks;
Returns:

log

Writes the given message to the default log (or STDERR as fallback).

$application->log( $message );
Arguments:
  • $message ( string )

    The message to log.

Alternative syntax:

$application->log( $log_level, @messages );
Arguments:
  • $log_level ( string | undef )

    A string identifying the log level, for example "notice" or "error". Defaults to "notice". See GX::Logger for more information.

  • @messages ( strings )

    A list with the messages to log.

logger

Returns the instance of the specified logger component or, if called without arguments, the default logger component.

$logger = $application->logger( $logger_name );
Arguments:
  • $logger_name ( string ) [ optional ]

    A qualified or unqualified logger component name.

Returns:

loggers

Returns all logger component instances.

@loggers = $application->loggers;
Returns:

mode

Returns the run mode of the application.

$mode = $application->mode;
Returns:
  • $mode ( string )

    A string identifying the run mode, for example "production" or "development".

model

Returns the instance of the specified model component.

$model = $application->model( $model_name );
Arguments:
  • $model_name ( string )

    A qualified or unqualified model component name.

Returns:

models

Returns all model component instances.

@models = $application->models;
Returns:

path

Returns the absolute path to the specified application directory.

$path = $application->path( $directory );
Arguments:
  • $directory ( string )

    A application directory name, for example "base", "lib" or "templates".

Returns:
  • $path ( string | undef )

paths

Returns all paths as a list of directory name / path pairs.

%paths = $application->paths;
Returns:
  • %paths ( named list of strings )

plugins

Returns a list with the class names of the application's plugins in the order they were registered.

@plugins = $application->plugins;
Returns:
  • @plugins ( strings )

router

Returns the router component instance.

$router = $application->router;
Returns:

session

Returns the specified session component or, if called without arguments, the default session component.

$session = $application->session( $session_name );
Arguments:
  • $session_name ( string ) [ optional ]

    A qualified or unqualified session component name.

Returns:
  • $session ( string | undef )

    The class name of the specified / default session component, or undef if the application has no such component.

sessions

Returns all session components.

@sessions = $application->sessions;
Returns:
  • @sessions ( strings )

    A list with the class names of the application's session components.

setup

Sets up the application.

$application->setup( %options );
Options:
  • default_cache ( string )

    The qualified or unqualified name of the cache component to use as the default cache component.

  • default_database ( string )

    The qualified or unqualified name of the database component to use as the default database component.

  • default_encoding ( string )

    The name of the application-wide default encoding, for example "utf-8" or "iso-8859-1". See Encode for a list of supported encodings. Defaults to "utf-8-strict".

  • default_logger ( string )

    The qualified or unqualified name of the logger component to use as the default logger component.

  • default_session ( string )

    The qualified or unqualified name of the session component to use as the default session component.

  • engine ( string )

    The GX::Engine::* class to use as the base class for the application's engine component, for example "Apache2" or "FCGI". This option is only relevant if the application's engine component is bootstrapped.

  • mode ( string )

    The application run mode which can be either "production" or "development". Defaults to "production". Setting this option to "development" enables the reload mechanism.

Advanced options:
  • dispatcher ( string )

    For internal use only.

  • dispatcher_base_class ( string )

    For internal use only.

  • engine_base_class ( string )

    For internal use only.

  • router ( string )

    For internal use only.

  • router_base_class ( string )

    For internal use only.

Exceptions:

start

Starts the application.

$application->start;
Exceptions:

view

Returns the instance of the specified view component.

$view = $application->view( $view_name );
Arguments:
  • $view_name ( string )

    A qualified or unqualified view component name.

Returns:

views

Returns all view component instances.

@views = $application->views;
Returns:

Internal Methods

add_hook

Internal method.

$application->add_hook( $hook );
Arguments:
Exceptions:

handle_error

Internal method.

$application->handle_error( $context, $error );
Arguments:
Exceptions:

process

Internal method.

$application->process( $context );
Arguments:
Exceptions:

reload

Internal method.

$result = $application->reload( $force );
Arguments:
  • $force ( bool ) [ optional ]
Returns:
  • $result ( bool )
Exceptions:

remove_hook

Internal method.

$result = $application->remove_hook( $hook );
$result = $application->remove_hook( $hook_name );
Arguments:
Returns:
  • $result ( bool )
Exceptions:

watcher

Internal method.

$watcher = $application->watcher;
Returns:

AUTHOR

Jörg A. Uzarek <uzarek@runlevelnull.de>

COPYRIGHT AND LICENSE

Copyright © 2009-2011 Jörg A. Uzarek.

This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.