The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SyForm - SyForm - a role driven form management

VERSION

version 0.006

SYNOPSIS

  use SyForm;

  my $form = SyForm->create([
    'username' => {
      isa => 'Str',
      required => 1,
      label => 'Your name',
    },
    'age' => {
      isa => 'Int',
      label => 'Your age',
    },
    'unchecked' => {
      label => 'Unchecked',
    },
  ]);

  $form->does('SyForm'); # its all roles
  $form->field('username')->does('SyForm::Field');
  $form->field('username')->does('SyForm::Field::Label');
  $form->field('username')->does('SyForm::Field::Verify');

  # Roles are only automatically loaded on requirement
  !$form->field('unchecked')->does('SyForm::Field::Verify');

  my $view = $form->process( username => 'YoCoolCopKiller', age => 13 );

  # or ...
  # $values = $form->process_values(%args);
  # my $value = $values->value;
  # !$values->can('success'); # values are only the input
  # $results = $form->process_results(%args);
  # my $result = $results->username;
  # my $value = $results->values->username; # same as above $value
  # my $success = $result->success # result is after check

  for (@{$view->field_names}) {
    my $input_value = $view->field($_)->value;
    if ($view->success) {
      my $verified_result = $view->field($_)->result;  
    } else {
      my $verified_result_if_exist = $view->field($_)->result;
    }
    # for access to the main SyForm::Field of the view field
    my $syform_field = $view->field($_)->field;
  }

DESCRIPTION

SyForm is developed for SyContent.

SyForm has many SyForm::Field. You get a form object with calling create([@fields], %form_args) on SyForm.

With SyForm::Process (automatically added) you can give it process_args via calling of process(%args) on your form object that you get from the create.

This call to process creates internally a SyForm::Values out of the process args together with the help of the fields. Those again use this to produce a SyForm::Results with the final results of the process.

Those end up in a SyForm::View together with a SyForm::ViewField for every SyForm::Field that is used in the process flow. The view field allows easy access to the SyForm::Values values, the SyForm::Results results and the actually SyForm::Field definition, to get a complete access of all variables in the rendering.

WARNING: SyForm::Values and SyForm::Results produce Moose attributes for storing their data, those are named directly after the key given for the field on the definition. This is highly risky for collides so its best to avoid using any term used in SyForm as key for those fields. This will change and getting real attributes will become an optional feature.

SUPPORT

IRC

  Join #sycontent on irc.perl.org. Highlight Getty for fast reaction :).

Repository

  http://github.com/SyContent/SyForm
  Pull request and additional contributors are welcome

Issue Tracker

  http://github.com/SyContent/SyForm/issues

AUTHOR

Torsten Raudssus <torsten@raudss.us>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.