Bug 34828: Introduce Koha::MetadataExtractor and ->get_normalized_upc
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 18 Sep 2023 12:35:16 +0000 (09:35 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 9 Oct 2023 19:41:30 +0000 (16:41 -0300)
commit0161eeba1301885658519b7b0c15cd6221d54a3d
tree0446badf1f98a823225f76c04711bb4c6773a640
parenta0564496b9b4344d95ee1cdd2529b9e49c548209
Bug 34828: Introduce Koha::MetadataExtractor and ->get_normalized_upc

This patch introduces a new pattern for the different ->get_<thing>
methods we've been adding. The aim is that code will look more like:

my $metadata_extractor = Koha::MetadataExtractor->new;

while ( my $biblio = $biblios->next ) {
    my $record = $biblio->record;
    my $schema = $biblio->record_schema;

    $data->{$biblio->id}->{normalized_upc} =
$metadata_extractor->get_normalized_upc( { record => $record, schema =>
$schema } );
    $data->{$biblio->id}->{normalized_ean} =
$metadata_extractor->get_normalized_ean( { record => $record, schema =>
$schema } );
}

The key is that we are actually reusing the MARC::Record, and code for
each schema is organized cleanly so easier to maintain.

For the class names, I chose to add the 'MARC' name in the path, so we
don't need to refactor anything if we want to add support for another
serialization formats.

To test:
1. Apply this patch
2. Run:
   $ ktd --shell
  k$ qa -c 1
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/MetadataExtractor.pm [new file with mode: 0644]
Koha/MetadataExtractor/MARC/MARC21.pm [new file with mode: 0644]
Koha/MetadataExtractor/MARC/UNIMARC.pm [new file with mode: 0644]
t/Koha/MetadataExtractor.t [new file with mode: 0755]
t/Koha/MetadataExtractor/MARC/MARC21.t [new file with mode: 0755]
t/Koha/MetadataExtractor/MARC/UNIMARC.t [new file with mode: 0755]