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.0104

SYNOPSIS

 my $q = CGI->new;
 
 # create mapper object
 my $mapper = CGI::DataObjectMapper->new( 
     input => $q->Vars, # this is hash ref
     class_prefix => 'YourApp',
     classes => { 
         Person => qw/name age contry_name/,
         Data::Book => qw/title author/
     },
     decode => 'utf8',
 );
 
 my $obj = $mapper->obj; # get mapped object
 
 my $person_name = $obj->person->name;
 my $person_age = $obj->person->age;
 my $person_country_name = $obj->person->country_name;
 
 my $book_name = $obj->data_book->title;
 my $book_author = $obj->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;

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 = $obj->data_book->title;

classes

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

obj

is converted object.

You can get object.

$data = $mapper->obj;

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

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

decode

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

if this is not specify, decode is not done.

ignore

is ignored attribute. This must be array ref.

Method

build_obj

is build obj from input information.

This is automatically called when obj method is called.

If you set new input data, Please call this method

$mapper->input( { a => 1, b => 2 } );
$mapper->build_obj;
my $obj = $mapper->obj; # 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.