Welcome Guest to Defaut site!

Comserv App Documentation: Root Controller

The `Root` controller serves as the backbone of the Comserv application. It provides:

1. Overview

The Root controller lays the foundation of the Comserv application by executing its responsibilities:

back to top

2. Naming Conventions

To avoid errors and maintain clarity in a dynamic, multi-tenant platform:

back to top

3. Logging

Logging in `Root.pm` adheres to detailed conventions for traceability and debugging. Each log should include the following components:

  1. File and Line Number: Use `__FILE__` and `__LINE__` to pinpoint the origin of the log.
  2. Action or Method Context: Provide the action or method name in the log message.
  3. Detailed Message: Add relevant variables and states.

Example:

$self->logging->log_with_details($c, __FILE__, __LINE__,
    'fetch_and_set',
    "ControllerName resolved to: $c->session->{ControllerName}");
back to top

4. Domain Mapping

Domain management ensures requests are correctly directed based on the incoming domain:

Steps:

  1. Extract Domain: Fetch the domain from the request:
    $domain = $c->req->base->host;
  2. Match in Database: Query the database to match the domain:
    my $site_domain = $c->model('Site')->get_site_domain($domain);
  3. Set Context: If a match is found, set critical request variables (`SiteName`, `ControllerName`).
  4. Fallback: Default to a fallback domain if no match exists.
back to top

5. index Action

The `index` action serves as the default route and processes root (`/`) requests.

Example:

if ($ControllerName) {
    $c->detach($ControllerName, 'index');
} else {
    $c->stash(template => 'index.tt');
    $c->forward($c->view('TT'));
}
back to top

6. auto Action

The `auto` action runs before each routed action method. Its primary responsibilities include:

Example:

if ($c->req->path eq '/' || $c->req->path eq '') {
    $self->index($c);
}
back to top

7. fetch_and_set Method

An essential helper method used to:

back to top

8. site_setup Method

The `site_setup` method fetches additional tenant-specific details (like styling or configuration) and initializes view-related data. This method builds on the variables set by `fetch_and_set` and customizes request processing further.

back to top

9. end Action

The `end` action is the final step in the Catalyst request lifecycle. It renders the response by processing and populating the required template using Catalyst’s `RenderView` action.

back to top

10. Suggestions for Improvement

To improve the readability and functionality of the `Root` controller, consider the following:

back to top