NAME
PICA::Modification - Idempotent modifications of identified PICA+ records
VERSION
version 0.15
SYNOPSIS
use PICA::Modification;
# delete field '0123A' from record 'foo:ppn:123'
my $mod = PICA::Modification->new(
id => 'foo:ppn:123', del => '0123A'
);
$after = $mod->apply( $before );
DESCRIPTION
PICA::Modification models a modification of an identified PICA+ record (PICA::Record). The modification consist of the following attributes:
- add
-
A stringified PICA+ record with fields to be added.
- del
-
A comma-separated list of PICA+ field tags to be removed. All tags of fields to be added must also be included for deletion so modifications are idempotent.
- id
-
The fully qualified record identifier of form
PREFIX:ppn:PPN
. - iln
-
The ILN of level 1 record to modify. Only required for modifications that include level 1 fields.
- epn
-
The EPN of the level 2 record to modify. Only required for modifications that include level 2 fields.
A modification instance may be malformed. A mapping from malformed attributes to error messages is stored together with the PICA::Modification object.
PICA::Modification is extended to PICA::Modification::Request. Collections of modifications can be stored in a PICA::Modification::Queue.
METHODS
check
Checks and normalized all attributes. A list of error messages is collected, each connected to the attribute that an error originates from.
error( [ $attribute [ => $message ] ] )
Gets or sets an error message connected to an attribute. Without arguments this method returns the number of errors.
apply ( $pica [, strict => 0|1 ] )
Applies the modification on a given PICA+ record and returns the resulting record as PICA::Record or undef
on malformed modifications.
Only edits at level 0 and level 1 are supported by now.
The experimental argument strict
can be used to enable additional validation. Validation errors are also collected in the PICA::Modification object. A valid modification must:
have a record identifier with PPN equal to the record's PPN (or both have none)
have ILN/EPN matching to the record's ILN/EPN (if given).
diff
TODO: Test this!
new ( %attributes | {%attributes} | $modification )
Creates a new modification with given attributes. Missing attributes are set to the empty string. On creation, all attributes are checked and normalized.
attributes
Returns a hash reference with attributes of this modification.
SEE ALSO
See PICA::Record for information about PICA+ record format.
AUTHOR
Jakob Voß <voss@gbv.de>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Jakob Voß.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.