Reaction::UI::Controller::Root - Base component for the Root Controller


Reaction documentation Contained in the Reaction distribution.

Index


Code Index:

NAME

Top

Reaction::UI::Controller::Root - Base component for the Root Controller

SYNOPSIS

Top

  package MyApp::Controller::Root;
  use base 'Reaction::UI::Controller::Root';

  __PACKAGE__->config(
    view_name => 'Site',
    window_title => 'Reaction Test App',
    namespace => ''
  );

  # Create UI elements:
  $c->self->push_viewport('Reaction::UI::ViewPort', %args);

  # Access the window title in a template:
  [% window.title %]

DESCRIPTION

Top

Using this module as a base component for your Catalyst Root Controller provides automatic creation of a Reaction::UI::Window object containing an empty Reaction::UI::FocusStack for your UI elements. The stack is also resolved and rendered for you in the end action.

At the begin of each request, the Window object is created using the configured view_name, content_type and window_title. These thus should be directly changed on the stashed window object at runtime, if needed.

ATTRIBUTES

Top

view_name

Arguments: $viewname?

Set or retrieve the classname of the view used to render the UI. Can also be set by a call to config. Defaults to 'XHTML'.

content_type

Arguments: $contenttype?

Set or retrieve the content type of the page created. Can also be set by a call to config or in a config file. Defaults to 'text/html'.

window_title

Arguments: $windowtitle?

Set or retrieve the title of the page created. Can also be set by a call to config or in a config file. No default.

ACTIONS

Top

begin

Stuffs a new Reaction::UI::Window object into the stash, using the view_name and content_type provided in the configuration.

Make sure you call this base begin action if writing your own.

end

Draws the UI via the flush in Reaction::UI::Window method.

METHODS

Top

error_404

Sets $c->res (the Catalyst::Response) body, status and content type to output a 404 (File not found) error.

error_403

Sets $c->res (the Catalyst::Response) body, status and content type to output a 403 (Forbidden) error.

AUTHORS

Top

See Reaction::Class for authors.

LICENSE

Top

See Reaction::Class for the license.


Reaction documentation Contained in the Reaction distribution.

package Reaction::UI::Controller::Root;

use Moose;
use Reaction::UI::Window;

BEGIN { extends 'Reaction::UI::Controller'; }

__PACKAGE__->config(
  view_name => 'XHTML',
  content_type => 'text/html',
);

has 'view_name' => (isa => 'Str', is => 'rw', required => 1);
has 'content_type' => (isa => 'Str', is => 'rw', required => 1);
has 'window_title' => (
  isa => 'Str', is => 'rw', predicate => 'has_window_title'
);

sub begin :Private {
  my ($self, $ctx) = @_;
  $ctx->stash(
    window => Reaction::UI::Window->new(
      ctx => $ctx,
      view_name => $self->view_name,
      content_type => $self->content_type,
      ($self->has_window_title
         ? (title => $self->window_title)
           : ()),
    )
  );
  my $focus_stack = $ctx->stash->{window}->focus_stack;
  $focus_stack->loc_prefix('r-vp');
  $ctx->stash(focus_stack => $focus_stack);
}

sub end :Private {
  my ($self, $ctx) = @_;
  $ctx->stash->{window}->flush;
}

sub error_404 :Private {
  my ($self, $c) = @_;
  $c->res->body("Error 404: Not Found");
  $c->res->status(404);
  $c->res->content_type('text/plain');
}

sub error_403 :Private {
  my ($self, $c) = @_;
  $c->res->body("Error 403: Forbidden");
  $c->res->status(403);
  $c->res->content_type('text/plain');
}

1;