NAME
PICA::Modification - Idempotent modification of an identified PICA+ record
VERSION
version 0.16
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
new ( %attributes | { %attributes } | $modification )
Creates a new modification from attributes, given as hash, as hash reference or as another PICA::Modification. The modification is checked on creation, so all attributes are normalized, missing attributes are set to the empty string and invalid attributes result in errors.
attributes
Returns a new hash reference with attributes of this modification.
error( [ $attribute [ => $message ] ] )
Gets or sets an error message connected to an attribute. Without arguments this method returns the current number of errors.
check
Normalizes and checks all attributes. Missing values are set to the empty string and invalid attributes result in errors. Returns the modification.
apply ( $pica )
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.
PPN/ILN/EPN must match or an error is set.
diff ( $record [, $context ] )
Applies the modification to a given PICA+ record and returns a diff on success. The context attribute specifies the number of fields before/after each deleted or added field. If undefines, all fields are included in the diff.
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.