Form-Processor

 view release on metacpan or  search on metacpan

lib/Form/Processor/Model.pm  view on Meta::CPAN

$Form::Processor::Model::VERSION = '1.162360';
use strict;
use warnings;
use base 'Rose::Object';
use Carp;
use Data::Dumper;
use Scalar::Util qw/ blessed /;


# Define instance data

use Rose::Object::MakeMethods::Generic (

    scalar => [
        object_class => { interface => 'get_set_init' },

        #item_id         => {},  # Can't init from item->id because of circular references
        item => { interface => 'get_set_init' },
    ],
);

# ABSTRACT: default model base class



sub init_object_class {
    my $self = shift;
    my $item = $self->item;
    return ref $item;    # may be undefined
}




sub init_item {return}



sub guess_field_type { Carp::confess "Don't know how to determine field type of [$_[1]]" }



sub lookup_options {return}




sub init_value {
    my ( $self, $field, $item ) = @_;
    my $name = $field->name;

    return $item->can( $name ) ? $item->$name : undef
        if blessed( $item );


    return $item->{$name};

}


sub update_from_form {
    die "must define 'update_from_form' in Form::Processor::Model subclass";
}





sub model_validate { }





1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Form::Processor::Model - default model base class

=head1 VERSION

version 1.162360

=head1 SYNOPSIS

    # A class to define a form in your application
    package MyApplication::Form::User;
    use strict;

    # Inherit from the form model class for your ORM
    use base 'Form::Processor::Model::CDBI

    # Relate the form to a specific ORM class
    sub object_class{ 'MyDB::User' }

    sub profile {

        [...]
    }

=head1 DESCRIPTION

This is an empty base class that defines methods called by
Form::Processor to support interfacing forms with a data store
such as a database.

This module provides instructions on methods to override to create
a Form::Processor::Model class to work with a specific object relational
mapping (ORM) tool.

For an example see L<Form::Processor::Model::CDBI> for working with
the Class::DBI ORM.

=head1 METHODS



( run in 0.941 second using v1.01-cache-2.11-cpan-39bf76dae61 )