gbv / Catmandu-PICA

Catmandu modules for working with PICA+ data
https://metacpan.org/release/Catmandu-PICA
Other
4 stars 4 forks source link

Support PICA record access methods independent from fixes #18

Closed nichtich closed 10 years ago

nichtich commented 10 years ago

Catmandu::Fix::pica_map is useful for Catmandu fixes but processing in raw Perl requires some helper methods, e.g.:

use Catmandu -all;
my %mapping = (
    '010@a' => 'language',
    '003A$0', => 'dc.identifier'
);
importer('PICA', file =>"pica.xml", type=> "XML")->each(sub {
    my $hashref = $_[0];

    my $id = pica_field($hashref->{record}, '003@');
    my $date = pica_value($hashref->{record}, '001A$0');

    my $data = pica_mapping($hashref->{record}, \$mapping);
});

I refactored an independent function parse_pica_path to start with:

We could also bless the PICA record structure, e.g. to do:

$hashref->{record}->fields('1***'); # returns a list of arrays
$hashref->{record}->values('003@$0'); # returns a list of scalar values

In particular one should be able to easily filter holding fields, aggregated by level 1.

jorol commented 10 years ago

That´s an useful enhancement, I did that in some custom fixes with simple subroutines. At which point would you bless the record structure without affecting the existing modules?

nichtich commented 10 years ago

I don't know how Catmandu is effected by blessed structures. The internal array structure is simple enough to process without a blessed structure (e.g. with grep & map). The PICA::Data module requires some more refactoring for performance until we can split it from Catmandu::PICA.