Form::Sensible::Reflector::DBIC - A reflector class based on Form::Sensible and Form::Sensible::Reflector
version 0.349
my $schema = TestSchema->connect('dbi:SQLite::memory:'); $schema->deploy; use Form::Sensible; use Form::Sensible::Reflector::DBIC; ## name must reflect the table which we are reflecting my $dt = DateTime->now; my $reflector = Form::Sensible::Reflector::DBIC->new(); my $form = $reflector->reflect_from( $schema->resultset("Test"), { form => { name => 'test' }, with_trigger => 1 } ); my $renderer = Form::Sensible->get_renderer('HTML'); $form->set_values( { date => $dt } ); my $output = $renderer->render($form)->complete;
Form::Sensible::Reflector::DBIC was designed with the intention that as much configuration as possible can be done in the definition of the DBIx::Class::ResultSource objects. While the ResultSource definition is used to programatically generate as much of the Form::Sensible::Field definitions as possible, it is possible to add to the Field generated. This is done with several items that can be added to the columinfo hash in the call to add_columns():
The validation hashref is used just as the validation hashref atribute in Form::Sensible::Field. It is typically used by Form::Sensible::Validator in order to create validation rules for form input values. As specified by Form::Sensible::Validator, it can contain keys required, code, and regex.
required
code
regex
The render_hints hashref also gets passed to Form::Sensible::Field as the render_hints attribute to the create_from_flattened constructor.
create_from_flattened
The fs_definition hashref can be used to completely override the intelligence ordinarily used to generate the Form::Sensible::Field definition. If this hashref is present, each key in it is used to completely overwrite the key in the Form::Sensible::Field definition. Any of the attributes accepted by Form::Sensible::Field are acceptable here. Note that one could alternatively specify validation and render_hints options here.
fs_definition
validation
render_hints
For example:
__PACKAGE__->add_columns( 'id', { data_type => 'integer', is_auto_increment => 1, is_nullable => 0 }, 'phone_number', { data_type => 'varchar', validation => { regex => qr/[-\d]+/ }, # passed to Form::Sensible::Field } ); __PACKAGE__->set_primary_key('id'); # Defaults to hidden in the form
Hashref of the supported DBMS type->form element translations.
Default options for Form::Sensible field classes.
This gets field definitions for a given datatype and returns them in hashref form.
Get field names for the form, for example, the column names in the table.
Get a given field's definition.
To install Form::Sensible::Reflector::DBIC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Form::Sensible::Reflector::DBIC
CPAN shell
perl -MCPAN -e shell install Form::Sensible::Reflector::DBIC
For more information on module installation, please visit the detailed CPAN module installation guide.