NAME

CGI::DataObjectMapper - Data-Object Mapper for CGI form data

CAUTION

This Module is yet experimental stage. Please wait until it will be statble.

VERSION

Version 0.0101

SYNOPSIS

my $q = CGI->new;

# create mapper object
my $mapper = CGI::DataObjectMapper->new( 
    input => $q->Vars, # this is hash ref
    class_prefix => 'YourApp',
    classes => [ qw( Person Data::Book ) ],
    ignore => [ 'rm' ]
    decode => 'utf8',
);

my $data = $mapper->data; # get mapped object

my $person_name = $data->person->name;
my $person_age = $data->person->age;
my $person_country_name = $data->person->country_name;

my $book_name = $data->data_book->title;
my $book_author = $data->data_book->author;


package YourApp::Person;
use Simo;

sub name{ ac }
sub age{ ac }
sub country_name{ ac }


package YourApp::Data::Book;
use Simo;

sub title{ ac }
sub author{ ac }

# Folloing is post data
# This data is mapping YourApp::Person and YourApp::Data::Book

<form method="post" action="xxxx.cgi" >
  <input type="hidden" name="rm" value="start-mode" />
  
  <input type="text" "name="person--name" value="some" />
  <input type="text" name="person--age" value="some" />
  
  <input type="text" name="data-book--title" value="some" />
  <input type="text" name="data-book--author" value="some" />
</form>

DESCRIPTION

This module is data-object mapper for CGI form data.

and decode data if you want.

ACCESSORS

input

is input data. This must be hash ref.

Usually get hash data to use CGI::Vars method

my $q = CGI->new;
$q->Vars;

ignore

is ignored attribute. This must be array ref.

class_prefix

is class prefix.

I want you to specify this value, because Some class names may be conficted.

default_class

is default class when class name cannot get form input attribute name.

<input type="text" name="title" > # class is omited

my $mapper = CGI::DataObjectMapper->new( 
    input => $q->Vars,
    default_class => 'Data::Book',
    classes => [ qw( Person Data::Book ) ],
);

title is attribute of Data::Book

You can get title value this way.

my $title = $data->data_book->title;

classes

is mapped class names. this must be array ref. [ qw( Person Data::Book ) ] etc.

data

is converted data.

You can get object.

$data = $mapper->data;

my $person_name = $data->person->name;
my $person_age = $data->person->age;
my $person_country_name = $data->person->country_name;

my $book_name = $data->data_book->title;
my $book_author = $data->data_book->author;

decode

is charset when data is decoded. 'utf8' etc.

if this is not specify, decode is not done.

Method

build_data

is build data from input information.

This is automatically called when data method is called.

If you set new input data, Please call this method

$mapper->input( { a => 1, b => 2 } );
$mapper->build_data;
my $data = $mapper->data; # data is updated

AUTHOR

Yuki Kimoto, <kimoto.yuki at gmail.com>

BUGS

Please report any bugs or feature requests to bug-cgi-dataobjectmapper at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-DataObjectMapper. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc CGI::DataObjectMapper

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2009 Yuki Kimoto, all rights reserved.

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