blib/lib/DBIx/Class/FormTools.pm

filter: Statementstmt 94.1% 113 / 120 Branchbran 87.5% 35 / 40 Conditioncond 58.6% 17 / 29 MC/DCmcdc 36.8% 7 / 19 Subroutinesub 85.7% 12 / 14 Podpod 50.0% 2 / 4 totaltotal 82.3% 186 / 226 CC 38 SCAR 23.0
CC
38
Cov
87%
_inflate_object
18.3
__ANON__
9.4
fieldname
7.1
CRAP 10.0
↑ Summary Build »
1 package DBIx::Class::FormTools;
2  
3 10 our $VERSION = '0.000009';
4  
5 10 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #use DBIx::Class::FormTools::Form;
10  
11 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 10 ▶use Data::Dump 'pp';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 # use Debug::ShowStuff ':all';
16  
17 10 has 'schema' => (is => 'rw', isa => 'Ref');
18 10 has '_formdata' => (is => 'rw', isa => 'HashRef');
19  
20 10 has '_objects' => (is => 'rw', isa => 'HashRef');
21 10 has '_delayed_attributes' => (is => 'rw', isa => 'HashRef');
22  
23 =head1 NAME
24  
25 DBIx::Class::FormTools - Helper module for building forms with multiple related L<DBIx::Class> objects.
26  
27 =head1 VERSION
28  
29 This document describes DBIx::Class::FormTools version 0.0.8
30  
31 =head1 SYNOPSIS
32  
33 =head2 This is BETA software
34  
35 There may be bugs. The interface might change (But the it hasn't changed in a long time, so it is probably safe to use).
36  
37 =head2 Prerequisites
38  
39 In the examples I use 3 objects, a C<Film>, an C<Actor> and a C<Role>.
40 C<Role> is a many to many relation between C<Film> and C<Actor>.
41  
42 package MySchema;
43 use base 'DBIx::Class::Schema';
44 __PACKAGE__->load_classes(qw[
45 Film
46 Actor
47 Role
48 ]);
49  
50  
51 package MySchema::Film;
52 __PACKAGE__->table('films');
53 __PACKAGE__->add_columns(qw[
54 id
55 title
56 ]);
57 __PACKAGE__->set_primary_key('id');
58 __PACKAGE__->has_many(roles => 'MySchema::Role', 'film_id');
59  
60  
61 package MySchema::Actor;
62 __PACKAGE__->table('films');
63 __PACKAGE__->add_columns(qw[
64 id
65 name
66 ]);
67 __PACKAGE__->set_primary_key('id');
68 __PACKAGE__->has_many(roles => 'MySchema::Role', 'actor_id');
69  
70  
71 package MySchema::Role;
72 __PACKAGE__->table('roles');
73 __PACKAGE__->add_columns(qw[
74 film_id
75 actor_id
76 ]);
77 __PACKAGE__->set_primary_key(qw[
78 film_id
79 actor_id
80 ]);
81  
82 __PACKAGE__->belongs_to(film_id => 'MySchema::Film');
83 __PACKAGE__->belongs_to(actor_id => 'MySchema::Actor');
84  
85  
86 =head2 In your Controller
87  
88 use DBIx::Class::FormTools;
89  
90 my $formtool = DBIx::Class::FormTools->new({ schema => $schema });
91  
92  
93 =head2 In your view - L<HTML::Mason> example
94  
95 <%init>
96 my $film = $schema->resultset('Film')->find(42);
97 my $actor = $schema->resultset('Actor')->find(24);
98 my $role = $schema->resultset('Role')->new;
99  
100 </%init>
101 <form>
102 <input
103 name="<% $formtool->fieldname($film, 'title', 'o1') %>"
104 type="text"
105 value="<% $film->title %>"
106 />
107 <input
108 name="<% $formtool->fieldname($film, 'length', 'o1') %>"
109 type="text"
110 value="<% $film->length %>"
111 />
112 <input
113 name="<% $formtool->fieldname($film, 'comment', 'o1') %>"
114 type="text"
115 value="<% $film->comment %>"
116 />
117 <input
118 name="<% $formtool->fieldname($actor, 'name', 'o2') %>"
119 type="text"
120 value="<% $actor->name %>"
121 />
122 <input
123 name="<% $formtool->fieldname($role, undef, 'o3', {
124 film_id => 'o1',
125 actor_id => 'o2'
126 }) %>"
127 type="hidden"
128 value="dummy"
129 />
130 </form>
131  
132  
133 =head2 In your controller (or cool helper module, used in your controller)
134  
135 my @objects = $formtool->formdata_to_objects(\%querystring);
136 foreach my $object ( @objects ) {
137 # Assert and Manupulate $object as you like
138 $object->insert_or_update;
139 }
140  
141 =head1 DESCRIPTION
142  
143 =head2 Introduction
144  
145 L<DBIx::Class::FormTools> is a data serializer, that can convert HTML formdata
146 to L<DBIx::Class> objects based on element names created with
147 L<DBIx::Class::FormTools>.
148  
149 It uses user supplied object ids to connect the objects with each-other.
150 The objects do not need to exist on beforehand.
151  
152 The module is not ment to be used directly, although it can of-course be done
153 as seen in the above example, but rather used as a utility module in a
154 L<Catalyst> helper module or other equivalent framework.
155  
156 =head2 Connecting the dots - The problem at hand
157  
158 Creating a form with data from one object and storing it in a database is
159 easy, and several modules that does this quite well already exists on CPAN.
160  
161 What I am trying to accomplish here, is to allow multiple objects to be
162 created and updated in the same form - This includes the relations between
163 the objects i.e. "connecting the dots".
164  
165 =head2 Non-existent ids - Enter object_id
166  
167 When converting the formdata to objects, we need "something" to identify the
168 objects by, and sometimes we also need this "something" to point to another
169 object in the formdata to signify a relation. For this purpose we have the
170 C<object_id> which is user definable and can be whatever you like.
171  
172 =head1 METHODS
173  
174 =head2 C<new>
175  
176 Arguments: { schema => $schema }
177  
178 Creates new form helper
179  
180 my $formtool = DBIx::Class::FormTools->new({ schema => $schema });
181  
182 =cut
183  
184 =head2 C<schema>
185  
186 Arguments: None
187  
188 Returns the schema
189  
190 my $schema = $formtool->schema;
191  
192 =cut
193  
194  
195 =head2 C<fieldname>
196  
197 Arguments: $object, $accessor, $object_id, $foreign_object_ids
198  
199 my $name_film = $formtool->fieldname($film, 'title', 'o1');
200 my $name_actor = $formtool->fieldname($actor, 'name', 'o2');
201 my $name_role = $formtool->fieldname($role, undef,'o3',
202 { film_id => 'o1', actor_id => 'o2' }
203 );
204 my $name_role = $formtool->fieldname($role,'charater','o3',
205 { film_id => 'o1', actor_id => 'o2' }
206 );
207  
208 Creates a unique form field name for use in an HTML form.
209  
210 =over
211  
212 =item C<$object>
213  
214 The object you wish to create a key for.
215  
216 =item C<$accessor>
217  
218 The attribute in the object you wish to create a key for.
219  
220 =item C<$object_id>
221  
222 A unique string identifying a specific object in the form.
223  
224 =item C<$foreign_object_ids>
225  
226 A C<HASHREF> containing C<attribute =E<gt> object_id> pairs, use this to
227 connect objects with each-other as seen in the above example.
228  
229 =back
230  
231 =cut
232 sub fieldname
233 {
234 57 ▶ my ($self,$object,$attribute,$object_id,$foreign_object_ids) = @_;
Subroutine fieldname: called CC=7 SCAR=19.6
Pod documented
235  
236 # Get class name
237 57 ▶ my $class = $object->source_name || ref($object);
Condition33%1/3
$object->source_name || ref $object
l!l&&r!l&&!r
0570
MC/DC0%0/2
$object->source_name || ref $object
$object->source_name ref $object
Truth table33%1/3
A || B
A= $object->source_nameB= ref $object
ABresult
1X1
011
000
238  
239 57 my @primary_keys = $object->primary_columns;
240  
241 my %relationships
242 57 = ( map { $_,$object->relationship_info($_) } $object->relationships );
243  
244 57 my %id_fields = ();
245 57 foreach my $primary_key ( @primary_keys ) {
246 # Field is foreign key
247 62 ▶ if ( exists $relationships{$primary_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $relationships{$primary_key}) { } 10 52 62
248 10 $id_fields{$primary_key} = $foreign_object_ids->{$primary_key};
249 }
250 # Field is local
251 else {
252 52 ▶ $id_fields{$primary_key}
Branch: 1 branch
BranchTrueFalseTotal
ref $object && $object->$primary_key ? : 25 27 52
Condition66%2/3
ref $object and $object->$primary_key
!ll&&!rl&&r
02725
MC/DC50%1/2
ref $object and $object->$primary_key
ref $object $object->$primary_key
Truth table66%2/3
A and B
A= ref $objectB= $object->$primary_key
ABresult
0X0
100
111
253 = ( ref($object) && $object->$primary_key )
254 ? $object->$primary_key
255 : 'new';
256 }
257 }
258  
259 # Build object key
260 my $fieldname = join('|',
261 'dbic',
262 $object_id,
263 $class,
264 57 ▶ join(q{;}, map { "$_:".$id_fields{$_} } keys %id_fields),
Condition100%2/2
$attribute || ''
l!l
543
MC/DC100%1/1
$attribute || ''
$attribute
Truth table100%2/2
A
A= $attribute
Aresult
11
00
265 ($attribute || ''),
266 );
267  
268 57 return($fieldname);
269 }
270  
271  
272 sub field_id {
273 0 ▶ my $self = shift;
Subroutine field_id: not called CC=1 SCAR=6.9
Pod undocumented
274 0 my $field_name = $self->fieldname(@_);
275 0 $field_name =~ s/[:|]+/_/go;
276 0 return $field_name;
277 }
278  
279  
280 =head2 C<formdata_to_objects>
281  
282 Arguments: \%formdata
283  
284 my @objects = $formtool->formdata_to_objects($formdata);
285  
286 Turn formdata(a querystring) in the form of a C<HASHREF> into an C<ARRAY> of
287 C<DBIx::Class> objects.
288  
289 =cut
290 sub formdata_to_object_hash
291 {
292 7 ▶ my ($self,$formdata) = @_;
Subroutine formdata_to_object_hash: called CC=3 SCAR=11.0
Pod undocumented
293 # my $to_object_indent = indent();
294 7 my $objects = {};
295 my $rs = $self->schema->txn_do(sub{
296 # Cleanup old objects
297 7 ▶ $self->_objects({});
Subroutine __ANON__: called CC=9 SCAR=22.4
298 7 $self->_formdata({});
299 7 $self->_delayed_attributes({});
300  
301 # Extract all dbic fields
302 7 my @dbic_formkeys = grep { /^dbic\|/ } keys %$formdata;
303  
304 # Create a todo list with one entry for each unique objects
305 7 my $to_be_inflated = {};
306  
307 # Sort data into piles for later object creation/updating
308 7 foreach my $formkey ( @dbic_formkeys ) {
309 43 my ($prefix,$object_id,$class,$id,$attribute) = split(/\|/,$formkey);
310  
311 # Store form value for $attribute
312 43 ▶ if ( $attribute ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attribute) 41 2 43
313 41 my $real_attribute = $self->_get_real_attribute_from_class($class,$attribute);
314  
315 41 my $metadata = $self->schema->source($class)->column_info($real_attribute);
316 41 my $value = $formdata->{$formkey};
317  
318 # Handle empty fields for numeric attributes
319 41 ▶ $value = undef if !$value && $self->schema->storage->is_datatype_numeric($metadata->{data_type});
Branch: 1 branch
BranchTrueFalseTotal
if not $value and $self->schema->storage->is_datatype_numeric($metadata->{"data_type"}) 0 41 41
Condition33%1/3
not $value and $self->schema->storage->is_datatype_numeric($metadata->{"data_type"})
!ll&&!rl&&r
4100
MC/DC0%0/2
not $value and $self->schema->storage->is_datatype_numeric($metadata->{"data_type"})
not $value $self->schema->storage->is_datatype_numeric($metadata->{"data_type"})
Truth table33%1/3
not(A) and B
A= not $valueB= $self->schema->storage->is_datatype_numeric($metadata->{"data_type"})
ABresult
0X0
100
111
320  
321 # Handle empty fields for date attributes
322 41 ▶ $value = undef if !$value && exists($metadata->{_ic_dt_method});
Branch: 1 branch
BranchTrueFalseTotal
if not $value and exists $metadata->{"_ic_dt_method"} 0 41 41
Condition33%1/3
not $value and exists $metadata->{"_ic_dt_method"}
!ll&&!rl&&r
4100
MC/DC0%0/2
not $value and exists $metadata->{"_ic_dt_method"}
not $value exists $metadata->{"_ic_dt_method"}
Truth table33%1/3
not(A) and B
A= not $valueB= exists $metadata->{"_ic_dt_method"}
ABresult
0X0
100
111
323  
324 # Store value
325 41 $self->_formdata->{$object_id}->{'content'}->{$real_attribute} = $value;
326 }
327  
328 # Build id field
329 43 my %id;
330 43 foreach my $field ( split(/;/,$id) ) {
331 46 my ($key,$value) = split(/:/,$field);
332 46 $id{$key} = $value;
333 }
334  
335 # Store id field
336 43 $self->_formdata->{$object_id}->{'form_id'} = \%id;
337  
338 # Save class name and oid in the todo list
339 # println "$class | $object_id";
340 43 $to_be_inflated->{"$class|$object_id"} = {
341 class => $class,
342 object_id => $object_id,
343 };
344 }
345  
346 # Build objects from form data
347 7 foreach my $todo ( values %$to_be_inflated ) {
348 my $object = $self->_inflate_object(
349 $todo->{ 'object_id' },
350 19 $todo->{ 'class' },
351 );
352 19 $objects->{ $todo->{ 'object_id' } } = $object;
353 }
354 7 });
355  
356 7 foreach my $oid ( keys %{$self->_delayed_attributes} ) {
357 # println "Setting delayed attributes for '$oid'";
358 6 foreach my $accessor ( keys %{$self->_delayed_attributes->{$oid}} ) {
359 # println "- ",ref($objects->{$oid}),"->$accessor( ",ref($self->_delayed_attributes->{$oid}{$accessor})," )";
360 10 $objects->{$oid}->$accessor($self->_delayed_attributes->{$oid}{$accessor});
361 }
362 }
363  
364 # Cleanup old objects
365 7 $self->_objects({});
366 7 $self->_formdata({});
367  
368 7 return($objects);
369 }
370  
371 sub formdata_to_objects {
372 2 ▶ my ($self,$formdata,$inflate_only) = @_;
Subroutine formdata_to_objects: called CC=1 SCAR=0.0
Pod documented
373 2 my $hash = $self->formdata_to_object_hash($formdata,$inflate_only);
374 2 return values %$hash;
375 }
376  
377 sub _get_real_attribute_from_class {
378 67 ▶ my ($self,$class,$attribute) = @_;
Subroutine _get_real_attribute_from_class: called CC=5 SCAR=16.1
379  
380 # Get relationship info for the attribute
381 67 my $relationship_info = $self->schema->source($class)->relationship_info($attribute);
382  
383 # Resolve the actual column name in the table (e.g. a relation named 'location' might be called 'location_id' in the result_source)
384 my $real_attribute = ( $relationship_info && $relationship_info->{attrs}{accessor} eq 'filter' ) ? $attribute
385 67 ▶ : ( $relationship_info && $relationship_info->{attrs}{accessor} eq 'single' ) ? (keys %{$relationship_info->{'attrs'}{'fk_columns'}})[0]
Branch: 2 branches
BranchTrueFalseTotal
$relationship_info && $relationship_info->{'attrs'}{'accessor'} eq 'filter' ? : 17 50 67
$relationship_info && $relationship_info->{'attrs'}{'accessor'} eq 'single' ? : 11 39 50
Condition83%5/6
$relationship_info and $relationship_info->{"attrs"}{"accessor"} eq "filter"
!ll&&!rl&&r
391117
$relationship_info and $relationship_info->{"attrs"}{"accessor"} eq "single"
!ll&&!rl&&r
39011
MC/DC100%2/2
$relationship_info and $relationship_info->{"attrs"}{"accessor"} eq "filter"
$relationship_info $relationship_info->{"attrs"}{"accessor"} eq "filter"
MC/DC50%1/2
$relationship_info and $relationship_info->{"attrs"}{"accessor"} eq "single"
$relationship_info $relationship_info->{"attrs"}{"accessor"} eq "single"
Truth table100%3/3
A and B
A= $relationship_infoB= $relationship_info->{"attrs"}{"accessor"} eq "filter"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $relationship_infoB= $relationship_info->{"attrs"}{"accessor"} eq "single"
ABresult
0X0
100
111
386 : $attribute;
387 67 return $real_attribute;
388 }
389  
390 sub _flatten_id
391 {
392 0 ▶ my ($id) = @_;
Subroutine _flatten_id: not called CC=1 SCAR=6.9
393  
394 0 return join(';', map { $_.':'.$id->{$_} } sort keys %$id);
395 }
396  
397 sub _inflate_object
398 {
399 29 ▶ my ($self,$oid,$class) = @_;
Subroutine _inflate_object: called CC=18 SCAR=29.1
400 # my $inflate_indent = indent();
401 # println "[$oid] _inflate_object - Begin";
402 29 my $id;
403 29 my $attributes = {};
404  
405 # Object exists in form
406 29 ▶ if ( exists($self->_formdata->{$oid}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->_formdata->{$oid}) { } 28 1 29
407 28 $id = $self->_formdata->{$oid}->{'form_id'};
408 28 $attributes = $self->_formdata->{$oid}->{'content'};
409 }
410 # oid does not exist in the formdata, use oid is a real id
411 else {
412 1 $id = { id => $oid };
413 }
414  
415 # We must have an attribute hash if we want to call 'new' later on
416 29 ▶ $attributes = {} unless $attributes;
Branch: 1 branch
BranchTrueFalseTotal
unless $attributes 2 27 29
417  
418 # Return object if is already inflated
419 return $self->_objects->{$class}->{$oid}
420 29 ▶ if ( $self->_objects->{$class} && $self->_objects->{$class}->{$oid} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_objects->{$class} and $self->_objects->{$class}{$oid} 9 20 29
Condition100%3/3
$self->_objects->{$class} and $self->_objects->{$class}{$oid}
!ll&&!rl&&r
1739
MC/DC100%2/2
$self->_objects->{$class} and $self->_objects->{$class}{$oid}
$self->_objects->{$class} $self->_objects->{$class}{$oid}
Truth table100%3/3
A and B
A= $self->_objects->{$class}B= $self->_objects->{$class}{$oid}
ABresult
0X0
100
111
421  
422 # Build a lookup hash of fields that are relationship fields
423 my $relationships = {
424 20 map { $_,$self->schema->source($class)->relationship_info($_) }
425 $self->schema->source($class)->relationships
426 };
427  
428 # Inflate foreign fields that map to a *single* column
429 20 my $todo_delayed_attributes = {};
430 20 foreach my $foreign_accessor ( keys %$relationships ) {
431 # Resolve foreign class name
432 39 my $foreign_class = $self->schema->source($relationships->{$foreign_accessor}->{'class'})->result_class;
433 39 my $foreign_relation_type = $relationships->{$foreign_accessor}->{'attrs'}->{'accessor'};
434 # println "[$oid] Processing $foreign_accessor for $foreign_class";
435  
436 # Do not process multicolumn relationships, they will be processed
437 # seperatly when the object to which they relate is inflated
438 # I.e. only process "local" attributes
439 39 ▶ next if $foreign_relation_type eq 'multi';
Branch: 1 branch
BranchTrueFalseTotal
if $foreign_relation_type eq "multi" 13 26 39
440  
441 # Resolve the actual column name in the table (e.g. a relation named 'location' might be called 'location_id')
442 26 my $real_foreign_accessor = $self->_get_real_attribute_from_class($class,$foreign_accessor);
443  
444 # Lookup foreign object id or real id, if the foreign object has already been inflated
445 my $foreign_oid = ( exists($self->_formdata->{$oid}{'form_id'}{$real_foreign_accessor}) )
446 ? $self->_formdata->{$oid}{'form_id'}{$real_foreign_accessor}
447 26 ▶ : $self->_formdata->{$oid}{'content'}{$real_foreign_accessor};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->_formdata->{$oid}{'form_id'}{$real_foreign_accessor} ? : 6 20 26
448  
449 # say "Formdata for local object: ".pp($self->_formdata);
450 # println "[$oid] Foreign oid to inflate ", $foreign_oid;
451 # println pp($self->_formdata->{$oid});
452  
453 # No id found, no inflate needed
454 26 ▶ next unless $foreign_oid;
Branch: 1 branch
BranchTrueFalseTotal
unless $foreign_oid 16 10 26
455  
456 10 my $foreign_object = $self->_inflate_object(
457 $foreign_oid,
458 $foreign_class,
459 );
460  
461 # Store object for later use
462 10 $self->_objects->{$foreign_class}->{$oid} = $foreign_object;
463  
464 # If the field is part of the id then store it there as well
465 10 ▶ $id->{$foreign_accessor} = $foreign_object->id if exists $id->{$foreign_accessor};
Branch: 1 branch
BranchTrueFalseTotal
if exists $id->{$foreign_accessor} 6 4 10
466  
467 # If the inflated foreign object is new, its 'id' will be undefined.
468 # Therefore we delay adding the foreign object to the local object, until the local object have been inflated or created.
469 # println "[$oid] Delaying setting $foreign_accessor to ".ref($foreign_object);
470 10 $self->_delayed_attributes->{$oid}{$foreign_accessor} = $foreign_object;
471 # $attributes->{$real_foreign_accessor} = $foreign_object->id;
472 }
473 # All foreign objects have been now been inflated
474  
475 # Look up object in memory
476 20 my $object = $self->_objects->{$class}->{$oid};
477  
478 # Lookup in object in db
479 20 ▶ unless ( $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object) 20 0 20
480 20 my $source = $self->schema->source($class);
481 # Don't lookup object if id is 'new'
482 $object = $self->schema->resultset($source->source_name)->find($id)
483 20 ▶ unless grep { defined($id->{$_}) && $id->{$_} eq 'new' } $source->primary_columns;
Branch: 2 branches
BranchTrueFalseTotal
unless grep {defined $id->{$_} and $id->{$_} eq "new";} $source->primary_columns 10 10 20
defined $id->{$_} and $id->{$_} eq "new" 19 4 23
484 }
485  
486 # Still no object, the create it
487 20 ▶ unless ( $object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($object) 13 7 20
488 13 $object = $self->schema->resultset($class)->new($attributes);
489 }
490  
491 # If we have a object update it with form data, if it exists
492 # println "[$oid] We have an object: ".ref($object).", add to todo list";
493 # println "[$oid] Attributes: ".pp($attributes);
494 20 ▶ $object->set_columns($attributes) if $object && $attributes;
Branch: 1 branch
BranchTrueFalseTotal
if $object and $attributes 20 0 20
Condition33%1/3
$object and $attributes
!ll&&!rl&&r
0020
MC/DC0%0/2
$object and $attributes
$object $attributes
Truth table33%1/3
A and B
A= $objectB= $attributes
ABresult
0X0
100
111
495  
496 # Store object for later use
497 20 ▶ if ( $id && $object ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and $object) 20 0 20
Condition33%1/3
$id and $object
!ll&&!rl&&r
0020
MC/DC0%0/2
$id and $object
$id $object
Truth table33%1/3
A and B
A= $idB= $object
ABresult
0X0
100
111
498 # say "Storing object ".ref($object)." for later use.";
499 20 $self->_objects->{$class}->{$oid} = $object;
500 }
501 # println "[$oid] _inflate_object - End";
502 20 return($object);
503 }
504  
505 10 1; # Magic true value required at end of module
506 __END__
507  
508 =head2 meta
509  
510 This is a method which provides access to the current class's metaclass.
511  
512 =head1 CAVEATS
513  
514 =head2 Transactions
515  
516 When using this module it is prudent that you use a database that supports
517 transactions.
518  
519 The reason why this is important, is that when calling C<formdata_to_objects>,
520 C<DBIx::Class::Row-E<gt>create()> is called foreach nonexistent object in
521 order to get the C<primary key> filled in. This call to C<create> results in a
522 SQL C<insert> statement, and might leave you with one object successfully put
523 into the database and one that generates an error - Transactions will allow
524 you to examine the C<ARRAY> of objects returned from C<formdata_to_objects>
525 before actually storing them in the database.
526  
527 =head2 Automatic Primary Key generation
528  
529 You must use C<DBIx::Class::PK::Auto>, otherwise the C<formdata_to_objects>
530 will fail when creating new objects, as it is unable to determine the value
531 for the primary key, and therefore is unable to connect the object to any
532 related objects in the form.
533  
534 =head1 BUGS AND LIMITATIONS
535  
536 No bugs have been reported.
537  
538 Please report any bugs or feature requests to
539 C<bug-dbix-class-formtools@rt.cpan.org>, or through the web interface at
540 L<http://rt.cpan.org>.
541  
542 =head1 AUTHOR
543  
544 David Jack Olrik C<< <djo@cpan.org> >>
545  
546 =head1 LICENCE AND COPYRIGHT
547  
548 Copyright (c) 2006, David Jack Olrik C<< <djo@cpan.org> >>.
549 All rights reserved.
550  
551 This module is free software; you can redistribute it and/or
552 modify it under the same terms as Perl itself. See L<perlartistic>.
553  
554 =head1 TODO
555  
556 =over
557  
558 =item * Add form object, that keeps track of object ids automagickly.
559  
560 =item * Add field generator, that can generate HTML/XHTML fields based on the
561 objects in the form object.
562  
563 =back
564  
565 =head1 SEE ALSO
566  
567 L<DBIx::Class> L<DBIx::Class::PK::Auto>
↑ Summary Build »