| 1 | package MARC::Leader::Utils; | ||
| 2 | |||
| 3 | 2 | ▶ | use base qw(Exporter); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 0 | ▶ | use Error::Pure qw(err); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use List::Util 1.33 qw(any); | ||
| 9 | use Scalar::Util qw(blessed); | ||
| 10 | use Readonly; | ||
| 11 | |||
| 12 | # Constants. | ||
| 13 | Readonly::Array our @EXPORT => qw(check_material_type material_type); | ||
| 14 | Readonly::Array our @MATERIAL_TYPES => qw(book computer_file continuing_resource map | ||
| 15 | mixed_material music visual_material); | ||
| 16 | |||
| 17 | our $VERSION = 0.02; | ||
| 18 | |||
| 19 | sub check_material_type { | ||
| 20 | my $material_type = shift; | ||
| 21 | |||
| 22 | if (any { $material_type eq $_ } @MATERIAL_TYPES) { | ||
| 23 | return 1; | ||
| 24 | } else { | ||
| 25 | return 0; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | sub material_type { | ||
| 30 | my $leader = shift; | ||
| 31 | |||
| 32 | if (! defined $leader | ||
| 33 | || ! blessed($leader) | ||
| 34 | || ! $leader->isa('Data::MARC::Leader')) { | ||
| 35 | |||
| 36 | err "Leader object must be a Data::MARC::Leader instance."; | ||
| 37 | } | ||
| 38 | |||
| 39 | my $material_type; | ||
| 40 | if ((any { $leader->type eq $_ } qw(a t)) | ||
| 41 | && (any { $leader->bibliographic_level eq $_ } qw(a c d m))) { | ||
| 42 | |||
| 43 | $material_type = 'book'; | ||
| 44 | } elsif ($leader->type eq 'm') { | ||
| 45 | $material_type = 'computer_file'; | ||
| 46 | } elsif (any { $leader->type eq $_ } qw(e f)) { | ||
| 47 | $material_type = 'map'; | ||
| 48 | } elsif (any { $leader->type eq $_ } qw(c d i j)) { | ||
| 49 | $material_type = 'music'; | ||
| 50 | } elsif ($leader->type eq 'a' | ||
| 51 | && (any { $leader->bibliographic_level eq $_ } qw(b i s))) { | ||
| 52 | |||
| 53 | $material_type = 'continuing_resource'; | ||
| 54 | } elsif (any { $leader->type eq $_ } qw(g k o r)) { | ||
| 55 | $material_type = 'visual_material'; | ||
| 56 | } elsif ($leader->type eq 'p') { | ||
| 57 | $material_type = 'mixed_material'; | ||
| 58 | } else { | ||
| 59 | err "Unsupported material type."; | ||
| 60 | } | ||
| 61 | |||
| 62 | return $material_type; | ||
| 63 | } | ||
| 64 | |||
| 65 | 1; | ||
| 66 | |||
| 67 | __END__ | ||