| 1 | package File::ERC; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | our $VERSION; | |||||||||||||||||||||||||||
| 8 | 7 | $VERSION = sprintf "%d.%02d", q$Name: Release-1-05 $ =~ /Release-(\d+)-(\d+)/; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 7 | require Exporter; | |||||||||||||||||||||||||||
| 11 | 7 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 7 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 17 | num2tag tag2num tag2num_init | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 7 | our %erc_terms = ( | |||||||||||||||||||||||||||
| 21 | 'h10' => 'about-erc', # analog for dir_type? | ||||||||||||||||||||||||||||
| 22 | 'h12' => 'about-what', | ||||||||||||||||||||||||||||
| 23 | 'h13' => 'about-when', | ||||||||||||||||||||||||||||
| 24 | 'h14' => 'about-where', | ||||||||||||||||||||||||||||
| 25 | 'h11' => 'about-who', | ||||||||||||||||||||||||||||
| 26 | 'h15' => 'about-how', | ||||||||||||||||||||||||||||
| 27 | 'h506' => 'contributor', | ||||||||||||||||||||||||||||
| 28 | 'h514' => 'coverage', | ||||||||||||||||||||||||||||
| 29 | 'h502' => 'creator', | ||||||||||||||||||||||||||||
| 30 | 'h507' => 'date', | ||||||||||||||||||||||||||||
| 31 | 'h504' => 'description', | ||||||||||||||||||||||||||||
| 32 | 'c1' => 'ERC', | ||||||||||||||||||||||||||||
| 33 | 'h9' => 'erc', # h0->h9 to not collide with dir_type | ||||||||||||||||||||||||||||
| 34 | 'h0' => 'dir_type', | ||||||||||||||||||||||||||||
| 35 | 'v1' => ':etal', | ||||||||||||||||||||||||||||
| 36 | 'h509' => 'format', | ||||||||||||||||||||||||||||
| 37 | 'c2' => 'four h\'s', | ||||||||||||||||||||||||||||
| 38 | 'h510' => 'identifier', | ||||||||||||||||||||||||||||
| 39 | 'h602' => 'in', | ||||||||||||||||||||||||||||
| 40 | 'h5' => 'how', | ||||||||||||||||||||||||||||
| 41 | 'h512' => 'language', | ||||||||||||||||||||||||||||
| 42 | 'c3' => 'metadata', | ||||||||||||||||||||||||||||
| 43 | 'h30' => 'meta-erc', # dirtype? | ||||||||||||||||||||||||||||
| 44 | 'h32' => 'meta-what', | ||||||||||||||||||||||||||||
| 45 | 'h33' => 'meta-when', | ||||||||||||||||||||||||||||
| 46 | 'h34' => 'meta-where', | ||||||||||||||||||||||||||||
| 47 | 'h31' => 'meta-who', | ||||||||||||||||||||||||||||
| 48 | 'v2' => ':none', | ||||||||||||||||||||||||||||
| 49 | 'h601' => 'note', | ||||||||||||||||||||||||||||
| 50 | 'v3' => ':null', | ||||||||||||||||||||||||||||
| 51 | 'c4' => 'object', | ||||||||||||||||||||||||||||
| 52 | 'h505' => 'publisher', | ||||||||||||||||||||||||||||
| 53 | 'c5' => 'resource', | ||||||||||||||||||||||||||||
| 54 | 'h513' => 'relation', | ||||||||||||||||||||||||||||
| 55 | 'h515' => 'rights', | ||||||||||||||||||||||||||||
| 56 | 'h511' => 'source', | ||||||||||||||||||||||||||||
| 57 | 'h503' => 'subject', | ||||||||||||||||||||||||||||
| 58 | 'h20' => 'support-erc', # dirtype? | ||||||||||||||||||||||||||||
| 59 | 'h22' => 'support-what', | ||||||||||||||||||||||||||||
| 60 | 'h23' => 'support-when', | ||||||||||||||||||||||||||||
| 61 | 'h24' => 'support-where', | ||||||||||||||||||||||||||||
| 62 | 'h21' => 'support-who', | ||||||||||||||||||||||||||||
| 63 | 'c6' => 'stub ERC', | ||||||||||||||||||||||||||||
| 64 | 'v4' => ':tba', | ||||||||||||||||||||||||||||
| 65 | 'h501' => 'title', | ||||||||||||||||||||||||||||
| 66 | 'h508' => 'type', | ||||||||||||||||||||||||||||
| 67 | 'v5' => ':unac', | ||||||||||||||||||||||||||||
| 68 | 'v6' => ':unal', | ||||||||||||||||||||||||||||
| 69 | 'v7' => ':unap', | ||||||||||||||||||||||||||||
| 70 | 'v8' => ':unas', | ||||||||||||||||||||||||||||
| 71 | 'v9' => ':unav', | ||||||||||||||||||||||||||||
| 72 | 'v10' => ':unkn', | ||||||||||||||||||||||||||||
| 73 | 'h2' => 'what', | ||||||||||||||||||||||||||||
| 74 | 'h3' => 'when', | ||||||||||||||||||||||||||||
| 75 | 'h4' => 'where', | ||||||||||||||||||||||||||||
| 76 | 'h1' => 'who', | ||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 7 | our %erc_tags; # for lazy evaluation | |||||||||||||||||||||||||||
| 80 | 7 | our @erc_termlist; # for lazy evaluation | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 4 | ▶ | sub tag2num_init { | ||||||||||||||||||||||||||
|
Subroutine
tag2num_init: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 4 | @erc_termlist = sort values %erc_terms; # so we can grep | |||||||||||||||||||||||||||
| 85 | $erc_tags{$erc_terms{$_}} = $_ # so we can inverse map | ||||||||||||||||||||||||||||
| 86 | 4 | for (keys %erc_terms); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 4 | ▶ | sub tag2num { | ||||||||||||||||||||||||||
|
Subroutine
tag2num: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 4 | ▶ | @erc_termlist && %erc_tags or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@File::ERC::erc_termlist and %File::ERC::erc_tags
MC/DC0%0/2
@File::ERC::erc_termlist and %File::ERC::erc_tags
@File::ERC::erc_termlist
%File::ERC::erc_tags
Truth table33%1/3
A and B
A= @File::ERC::erc_termlistB= %File::ERC::erc_tags
| |||||||||||||||||||||||||||||
| 92 | tag2num_init(); # one-time lazy definition | ||||||||||||||||||||||||||||
| 93 | 4 | my (@ret, $tag); | |||||||||||||||||||||||||||
| 94 | 4 | foreach $tag (@_) { | |||||||||||||||||||||||||||
| 95 | # if it doesn't look like a regexp, do exact match | ||||||||||||||||||||||||||||
| 96 | 4 | ▶ | push(@ret, grep( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | ($tag =~ /[\\\*\|\[\+\?\{\^\$]/ ? /$tag/ : /^$tag$/), | ||||||||||||||||||||||||||||
| 98 | @erc_termlist)); | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 4 | return @ret; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # Returns an array of terms corresponding to args given as coded | ||||||||||||||||||||||||||||
| 104 | # synonyms for Dublin Kernel elements, eg, num2tag('h1') -> 'who'. | ||||||||||||||||||||||||||||
| 105 | # | ||||||||||||||||||||||||||||
| 106 | 11 | ▶ | sub num2tag { | ||||||||||||||||||||||||||
|
Subroutine
num2tag: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 11 | my (@ret, $code); | |||||||||||||||||||||||||||
| 109 | 11 | for (@_) { | |||||||||||||||||||||||||||
| 110 | # Assume an 'h' in front if it starts with a digit. | ||||||||||||||||||||||||||||
| 111 | # | ||||||||||||||||||||||||||||
| 112 | 14 | ($code = $_) =~ s/^(\d)/h$1/; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # Return a defined hash value or the empty string. | ||||||||||||||||||||||||||||
| 115 | # | ||||||||||||||||||||||||||||
| 116 | push @ret, defined($erc_terms{$code}) ? | ||||||||||||||||||||||||||||
| 117 | 14 | ▶ | $erc_terms{$code} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 11 | return @ret; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 7 | 1; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||||||||||