Subject: | Tangram::Storage.pm,Schema.pod patch - adding object propagation to make_id |
Date: | Fri, 26 Jan 2007 01:02:12 +0200 |
To: | bug-Tangram [...] rt.cpan.org |
From: | Assen Tchorbadjiev <pt [...] tchorbadjiev.com> |
Hello,
its not a bug :), its a feature that I find useful.
Here's the case:
The current make_id() call, when inserting objects into the storage,
does not propagate the $o[bject] to be inserted.
Some applications (as mine does) might find it useful to have this
instance when they define/generate custom ids for the backend.
Regards,
Assen
diff --git a/lib/Tangram/Schema.pod b/lib/Tangram/Schema.pod
index 1f9319d..568d7fc 100644
--- a/lib/Tangram/Schema.pod
+++ b/lib/Tangram/Schema.pod
@@ -179,10 +179,11 @@ Sequences are emulated on pretend databa
This is a I<closure> that is expected to return an unique ID. It is
called like this:
- $make_id->($class_id, $storage)
+ $make_id->($class_id, $storage, $object)
Where C<$class_id> is the Class identifier for_the newly created
object, and C<$storage> is the B<Tangram::Storage> object.
+The C<$object> is the instance of the object to be inserted.
=item * cid
diff --git a/lib/Tangram/Storage.pm b/lib/Tangram/Storage.pm
index 842451b..45d9175 100644
--- a/lib/Tangram/Storage.pm
+++ b/lib/Tangram/Storage.pm
@@ -311,7 +311,7 @@ sub prepare
# XXX - lots of options here not tested by test suite
sub make_id
{
- my ($self, $class_id) = @_;
+ my ($self, $class_id, $o) = @_;
# see if the class has its own ID generator
my $cname = $self->{id2class}{$class_id};
@@ -319,7 +319,7 @@ sub make_id
my $id;
if ( $classdef->{make_id} ) {
- $id = $classdef->{make_id}->($class_id, $self);
+ $id = $classdef->{make_id}->($class_id, $self, $o);
print $Tangram::TRACE "Tangram: custom per-class ($cname) make ID function returned ".(pretty($id))."\n" if $Tangram::TRACE;
} elsif ( $classdef->{oid_sequence} ) {
eval { $id = $self->get_sequence($classdef->{oid_sequence}) };
@@ -328,7 +328,7 @@ sub make_id
# maybe the entire schema has its own ID generator
if ( !defined($id) and $self->{schema}{sql}{make_id} ) {
- $id = $self->{schema}{sql}{make_id}->($class_id, $self);
+ $id = $self->{schema}{sql}{make_id}->($class_id, $self, $o);
print $Tangram::TRACE "Tangram: custom schema make ID function returned "
.(pretty($id))."\n" if $Tangram::TRACE;
} elsif ( !defined($id) &&
@@ -655,7 +655,7 @@ sub _insert
my $class = $self->{schema}->classdef($class_name);
- my $id = $self->make_id($classId);
+ my $id = $self->make_id($classId, $obj);
$self->welcome($obj, $id);
$self->tx_on_rollback( sub { $self->goodbye($obj, $id) } );