X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FUniqueIdentifier.pm;h=8621da0a9001b4a5b22b4dee45a7405ecad90cc9;hb=417c7e0020f9fcf8fdb892144324fad1f896099f;hp=92e7c1548a864865d120650f52abc6ad612aad28;hpb=40d8d018f03631cf38c5bebf854abef604de33bd;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBI/UniqueIdentifier.pm b/lib/DBIx/Class/Storage/DBI/UniqueIdentifier.pm index 92e7c15..8621da0 100644 --- a/lib/DBIx/Class/Storage/DBI/UniqueIdentifier.pm +++ b/lib/DBIx/Class/Storage/DBI/UniqueIdentifier.pm @@ -38,7 +38,8 @@ In which case it is used as the name of database function to create a new GUID, =item coderef In which case the coderef should return a string GUID, using L, or -whatever GUID generation method you prefer. +whatever GUID generation method you prefer. It is passed the C<$self> +L reference as a parameter. =back @@ -56,7 +57,7 @@ sub _is_guid_type { return $data_type =~ $GUID_TYPE; } -sub insert { +sub _prefetch_autovalues { my $self = shift; my ($source, $to_insert) = @_; @@ -64,8 +65,8 @@ sub insert { my %guid_cols; my @pk_cols = $source->primary_columns; - my %pk_cols; - @pk_cols{@pk_cols} = (); + my %pk_col_idx; + @pk_col_idx{@pk_cols} = (); my @pk_guids = grep { $col_info->{$_}{data_type} @@ -79,13 +80,11 @@ sub insert { $col_info->{$_}{data_type} =~ $GUID_TYPE && $col_info->{$_}{auto_nextval} - } grep { not exists $pk_cols{$_} } $source->columns; + } grep { not exists $pk_col_idx{$_} } $source->columns; my @get_guids_for = grep { not exists $to_insert->{$_} } (@pk_guids, @auto_guids); - my $updated_cols = {}; - for my $guid_col (@get_guids_for) { my $new_guid; @@ -99,18 +98,14 @@ sub insert { } if (ref $guid_method eq 'CODE') { - $new_guid = $guid_method->(); + $to_insert->{$guid_col} = $guid_method->($self); } else { - ($new_guid) = $self->_get_dbh->selectrow_array("SELECT $guid_method"); + ($to_insert->{$guid_col}) = $self->_get_dbh->selectrow_array("SELECT $guid_method"); } - - $updated_cols->{$guid_col} = $to_insert->{$guid_col} = $new_guid; } - $updated_cols = { %$updated_cols, %{ $self->next::method(@_) } }; - - return $updated_cols; + return $self->next::method(@_); } =head1 AUTHOR