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

SYNOPSIS

 my $q = CGI->new;
 
 # create mapper object
 my $mapper = CGI::DataObjectMapper->new( 
     class_prefix => 'YourApp',
     classes => { 
         Person => qw/name age contry_name/,
         'Data::Book' => qw/title author/
     },
     decode => 'utf8',
 );
 
 my $objects = $mapper->map_to_objects( $q->Vars );
 
 my $person = $objects->{ 'Person' };
 my $person_name = $person->name;
 my $person_age = $person->age;
 my $person_country_name = $person->country_name;
 
 my $book = $objects->{ 'Data::Book' };
 my $book_title = $data_book->title;
 my $book_author = $data_book->author;
 
 
 package YourApp::Person;
 use Object::Simple;
 
 sub name : Attr {}
 sub age : Attr {}
 sub country_name : Attr {}
 
 Object::Simple->end;

 package YourApp::Data::Book;
 use Object::Simple;
 
 sub title : Attr {}
 sub author : Attr {}
 
 Object::Simple->end;
 
 # 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="person--country-name" 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

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.

classes

is mapped class names. this must be array ref.

{
    Person => qw/name age contry_name/,
    'Data::Book' => qw/title author/
}

etc.

decode

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

if this is not specify, decode is not done.

Method

map_to_objects

convert input to objects.

You can get object.

my $objects = $mapper->map_to_objects( $q->Vars );

my $person = $objects->{ 'Person' };
my $person_name = $person->name;
my $person_age = $person->age;
my $person_country_name = $person->country_name;

my $book = $objects->{ 'Data::Book' };
my $book_title = $data_book->title;
my $book_author = $data_book->author;

unmapped

You can get unmapped key after calling map_to_objects

my $unmapped = $mapper->unmapped;

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.