Form::Factory::Interface - Role for form interface implementations


Form-Factory documentation Contained in the Form-Factory distribution.

Index


Code Index:

NAME

Top

Form::Factory::Interface - Role for form interface implementations

VERSION

Top

version 0.020

SYNOPSIS

Top

  package MyApp::Interface::MyUI;
  use Moose;

  with qw( Form::Factory::Interface );

  sub render_control {
      my ($self, $control, %options) = @_;

      # Draw $control for user
  }

  sub consume_control {
      my ($self, $control, %options) = @_;

      # Consume values from user to fill $control
  }

  package Form::Factory::Interface::Custom::MyUI;
  sub register_implementation { 'MyApp::Interface::MyUI' }

DESCRIPTION

Top

Defines the contract form interface classes must fulfill.

ATTRIBUTES

Top

stasher

A place for remembering things.

METHODS

Top

stash

unstash

See Form::Factory::Stash.

new_action

  my $action = $interface->new_action('Some::Action::Class', \%options);

Given the name of an action class, it initializes the class for use with this interface. The %options are passed to the constructor.

new_control

  my $control = $interface->new_control($name, \%options);

Given the short name for a control and a hash reference of initialization arguments, return a fully initialized control.

ROLE METHODS

Top

The following methods need to implement the following methods.

render_control

  $interface->render_control($control, %options);

This method is used to render the control in the current form.

consume_control

  $interface->consume_control($control, %options);

This method is used to consume the values input for a current form.

CONTROLS

Top

Here's a list of controls and the classes they represent:

button

Form::Factory::Control::Button

checkbox

Form::Factory::Control::Checkbox

full_text

Form::Factory::Control::FullText

password

Form::Factory::Control::Password

select_many

Form::Factory::Control::SelectMany

select_one

Form::Factory::Control::SelectOne

text

Form::Factory::Control::Text

value

Form::Factory::Control::Value

SEE ALSO

Top

Form::Factory::Action, Form::Factory::Control, Form::Factory::Stasher

AUTHOR

Top

Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Form-Factory documentation Contained in the Form-Factory distribution.
package Form::Factory::Interface;
BEGIN {
  $Form::Factory::Interface::VERSION = '0.020';
}
use Moose::Role;

use Carp ();
use Form::Factory::Stasher::Memory;

requires qw( render_control consume_control );

has stasher => (
    is        => 'ro',
    does      => 'Form::Factory::Stasher',
    required  => 1,
    default   => sub { Form::Factory::Stasher::Memory->new },
    handles   => [ qw( stash unstash ) ],
);

sub new_action {
    my ($self, $class_name, $args) = @_;

    Class::MOP::load_class($class_name)
        or Carp::croak("cannot load $class_name: $@");

    return $class_name->new( %$args, form_interface => $self );
}

sub new_control {
    my ($self, $name, $args) = @_;

    my $class_name = Form::Factory->control_class($name);
    return unless $class_name;

    return $class_name->new($args);
}

1;