Ok, I am going to give point-for-point feedback and tell you when I
can't follow your wording.

On 1/17/06, Bill Moseley <[EMAIL PROTECTED]> wrote:
>
> I'm looking for namespace and package name suggestions for a (yes,
> another) form processing module.
>
> Its job it to move data between a store and input/output forms,

Be sure to mention Class::DBI::AsForm
http://search.cpan.org/~tmtm/Class-DBI-AsForm-2.42/lib/Class/DBI/AsForm.pm

I used it last night and it is quite sweet. Perhaps some
comparison/contrast to that module would help.


> validating along the way.  It doesn't generate any HTML, although I use
> it in web applications mostly.  But it's not limited to web
> applications.

I cannot imagine a use for forms outside of web applications... the
validation might be useful outside, but then it sounds like
functionality which does not belong _in_ the form module but might be
better used _by_ the form module you want to name and upload to CPAN.


>
> In my world it's in the "Form" namespace (Form::Base, Form::Field,
> Form::Model).  But I'm not sure where it fits best in CPAN.

Is it Class::DBI dependant or does it use general Perl data structures
for its work? I think HTML::Form is where most of these things go if
they are generic, except for HTML::FillInForm, which might've been
better named HTML::Form::FillIn

>
> Here's a somewhat brief description:
>
> A user of this module creates a form object that is used in their
> application.  The user's form object inherits from this module (currently
> called Form::Base).   A form is made up of field objects that inherit
> from Form::Field.  So A "Text" field is Form::Field::Text and inherits
> from Form::Field.  An "Integer" field is Form::Field::Integer and
> inherits from Form::Field::Text.  And so on.
>
> Fields can contain a form object,

Hmm, the Perl oo modeling here is different from the HTML. HTML forms
cant have forms as fields can they? Well, as long as it works

> so compound fields are easy to
> build (such as separate day, month, year that is a DateTime object
> internally).
>

So the overarching form is a renderable form while the inner forms are
just computable or displayable.

>
> The magic of this module is when forms inherit from a "model" class
> instead of directly from Form::Base.  For example, I use Class::DBI
> and there's Form::Model::CDBI.  By looking at the database
> relationships Form::Model::CDBI can populate option lists, validate
> against those lists, and update many-to-many relationships.

update m-to-n relationships after the form is submitted you mean?

>
> The module is based partly on the design of Rose-HTML-Objects, but
> again, this module focuses more on the database side instead of doing
> HTML generation.

Just FYI, the HTML generation in CDBI::AsForm returns an HTML::Element
instead of pure HTML so that the HTML can be easier manipulated. The
old_style was pure HTML.

>
> Here's a synopsis, if still following along:
>
>        In an application you might want a controller to handle creating and 
> updating a "User"
>        record.  And not want to write much code.  Here's using Catalyst as an 
> example:

ah, the latest and freshest and newest framework, just the way I like it :)

>
>            # Catalyst Controller
>            package MyApplication::Controller::User;
>            use strict;
>            use MyApplication::Form::User;
>
>            sub edit : Local {
>                my ( $self, $c, $id ) = @_;
>
>                # Create the form object
>                my $form = MyApplication::Form::User->new( $id );

so this does a MyApplication::Model::User->retrieve($id)
is there some way to get at that? perhaps a 2 element list of
($form, $model) should be returned? or clearer as a hashref:

my $retval = ....
$retval->{form}
$retval->{model}

>
>                # Update the user record if form posted and form validates

how about taint checking?

>                $form->update_from_from( $c->request->parameters  )
                                                       form, not from
>                    if $c->form_posted;
>
>                $c->stash->{form} = $form;
>            }
>
>        The above form class might then look like this:
>
>            package MyApplication::Form::User;
>            use strict;
>            use base 'Form::Model::CDBI';
>
>            sub object_class { 'DB::User' }
>
>            sub profile {

are we looking at form fields names here or database column names?
must the form field names correspond to database column names or can
there be a transform to/fro?

>                my $self = shift;
>
>                return {
>                    required => {
>                        name        => 'Text',
>                        age         => 'PosInteger',
>                        username    => 'Text'.
>                        password    => 'Password',
>                        sex         => 'Select',
>                        birthdate   => 'PastDate',
>                    },
>                    optional => {
>                        hobbies     => 'Multiple', # many-to-many
>                        address     => 'Text',
>                        city        => 'Text',
>                        state       => 'Select',   # lookup table
>                    },
>
>                    # Make sure this is unique in the database
>                    unique => [ qw/ username /  ],
>
>                    # if any entered then all are required
>                    dependency => [
>                        [qw/ address city state /],
>                    ],
>                };
>            }
>
>            sub options_sex {
>                return (
>                    m => 'Male',
>                    f => 'Female',
>                );
>            }
>            sub validate_age {
>                my ( $self, $field ) = @_;
>                $field->add_error('Sorry, you must be 18')

presumably add_error() indicates which field did not validate in the
results hash? I presume the results hash is similar to dfv with
missing, invalid

>                    if $field->value < 18;
>            }
>
>
>
>        Or when you need a quick, small form do this in a controller:
>
>            my @fields = qw/ first_name last_name email /;
>            $c->stash->{form} = Form::Base->new(
>                profile => {
>                    required => {
>                        map { $_ => 'Text' } qw/ first_name last_name email /,
>                    },
>                },
>            );
>
>
>
>
>
> --
> Bill Moseley
> [EMAIL PROTECTED]
>
>


--
Play me in correspondence chess:
http://slowchess.com/profile.php?username=tbrannon

Reply via email to