The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PICA::Patch - Implementation of PICA diff and patch

DESCRIPTION

This file contains the implementation of diff and patch algorithm for PICA+ records. See functions pica_diff and pica_patch (or object methods diff and patch) of PICA::Data for usage.

FORMAT

The difference between two records or the change to be applied to a record is referred to as diff, delta or patch. In any case the format must encode a set of modifications. PICA Patch format encodes modifications to PICA records in form of annotated PICA records. PICA fields can be annotated with:

+

To denote a field that should be added.

-

To denote a field that should be removed.

blank

To denote a field that should be kept as it is.

Modification of a field can be encoded by removal of the old version followed by addition of the new version.

EXAMPLE

Given a PICA record with two fields:

  | 003@ $012345
  | 021A $aA book

A diff to modify the second field could be this:

  | - 021A $aA book
  | + 021A $aAn interesting book

The diff could be extended with the first field to make sure it can only applied if the first field exists in the record:

  |   003@ $012345
  | - 021A $aA book
  | + 021A $aAn interesting book

APPLICATION

Records are always sorted before application of diff or patch. Records must be limited to one level and contain no sub-records.

Fields are not added with a patch if the records already contains a fully identical field.

FUNCTIONS

pica_diff( $before, $after )

Return the difference between two records as annotated record.

pica_patch( $record, $diff )

Apply a difference given as annotated PICA and return the result as new record. This function may die with an error method if the diff cannot be applied.