The following were replaced with RapidApp::DBIC::Key and RapidApp::DBIC::KeyVal utility methods
sub get_primary_key_string { my ($self, $rsrc, $rec)= @_; my @pkvals; for my $colN ($rsrc->primary_columns) { defined $rec->{$colN} or return ''; # primary key wasn't given. Hopefully it gets autogenerated during insert. push @pkvals, $rec->{$colN}; } return stringify_pk(@pkvals); }
# For purposes of hash keys, we want to come up with a string that # uniquely represents a key on a table. # A key may have multiple columns. # We use a string of the form TABLE.COL1+COL2+COL3... # We ignore the possibility of a column having a "+" in its name and colliding # with another key on the same table with similar names. sub stringify_colkey { my ($self, $table, @cols)= @_; return $table.'.'.join('+', sort @cols); }
# get the values of a key from a hash, by colKey sub get_key_val { my ($self, $colKey, $rowHash)= @_; my ($table, $colList)= split(/[.]/, $colKey); my @cols= split(/[+]/, $colList); return map { $rowHash->{$_} } @cols; }
# This method stringifies a value for a key. # For all single-column keys, we just use the value. # For multiple-column keys, we join the values with the length of that value # i.e. LEN "~" VALUE LEN "~" VALUE ... # (which is a quick and easy way to ensure that unique values get unique # strings without having to escape anything. This trick is borrowed # from C++ name mangling) sub stringify_key_val { my ($self, @vals)= @_; scalar(@vals) eq 1 && !(ref $vals[0]) and return $vals[0]; scalar(@vals) eq 1 && ref $vals[0] eq 'ARRAY' and return @vals= @{$vals[0]}; return join '', map { length($_).'~'.$_ } @vals; }