File Coverage

blib/lib/Convert/MRC/Variables.pm
Criterion Covered Total %
statement 44 44 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 54 54 100.0


line stmt bran cond sub pod time code
1             #
2             # This file is part of Convert-MRC
3             #
4             # This software is copyright (c) 2013 by Alan K. Melby.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             package Convert::MRC::Variables;
10              
11 5     5   31 use strict;
  5         8  
  5         267  
12 5     5   28 use warnings;
  5         9  
  5         269  
13             # ABSTRACT: Provide global constants used by Convert::MRC
14             our $VERSION = '4.03'; # VERSION
15 5     5   29 use base 'Exporter';
  5         9  
  5         1202  
16             ## no critic (ProhibitAutomaticExportation)
17             our @EXPORT = qw(
18             %corresp
19             $langCode
20             %correctCaps
21             %allowed
22             %legalIn
23             %position
24             %meta
25             );
26              
27             # reference variables
28             our %corresp = _get_corresp();
29             our $langCode = _get_lang_code();
30             our %correctCaps = _get_correct_caps();
31             our %allowed = _get_allowed();
32             our %legalIn = _get_legal_in();
33             our %position = _get_position();
34             our %meta = _get_meta();
35              
36             # How does the data category from a header row relate to the header?
37             # (This is also a validity check.)
38             sub _get_corresp {
39 5     5   27 my %corresp = (
40             workingLanguage => 'Language',
41             sourceDesc => 'Source',
42             subjectField => 'Subject',
43             );
44 5         33 return %corresp;
45             }
46              
47             # ISO 639 language code, and optionally region code: fr, eng-US
48             # case-insensitive; values are smashed to lowercase when parsed
49             sub _get_lang_code {
50 5     5   25 return qr/[a-zA-Z]{2,3}(?:-[a-zA-Z]{2})?/;
51             }
52              
53             # What is the proper capitalization for each data category/picklist item?
54             # A hash from a case-smashed version to the correct version, which will be
55             # used to recognize and fix user input.
56             sub _get_correct_caps {
57 5     5   9 my %correct_caps;
58 5         190 $correct_caps{'DatCat'}{ lc($_) } = $_ foreach qw (
59             sourceDesc workingLanguage subjectField xGraphic definition
60             term partOfSpeech administrativeStatus context geographicalUsage
61             grammaticalGender termLocation termType note source
62             crossReference externalCrossReference customerSubset projectSubset
63             transactionType fn org title role email uid tel adr type
64             );
65 5         62 $correct_caps{'partOfSpeech'}{ lc($_) } = $_ foreach qw (
66             noun verb adjective adverb properNoun other
67             );
68 5         45 $correct_caps{'administrativeStatus'}{ lc($_) } = $_ foreach qw (
69             preferredTerm-admn-sts admittedTerm-admn-sts
70             deprecatedTerm-admn-sts supersededTerm-admn-sts
71             );
72 5         139 $correct_caps{'grammaticalGender'}{ lc($_) } = $_ foreach qw (
73             masculine feminine neuter other
74             );
75 5         162 $correct_caps{'termLocation'}{ lc($_) } = $_ foreach qw (
76             menuItem dialogBox groupBox textBox comboBox comboBoxElement
77             checkBox tab pushButton radioButton spinBox progressBar slider
78             informativeMessage interactiveMessage toolTip tableText
79             userDefinedType
80             );
81 5         46 $correct_caps{'termType'}{ lc($_) } = $_ foreach qw (
82             fullForm acronym abbreviation shortForm variant phrase
83             );
84 5         35 $correct_caps{'transactionType'}{ lc($_) } = $_ foreach qw (
85             origination modification
86             );
87 5         29 $correct_caps{'type'}{ lc($_) } = $_ foreach qw (
88             person organization
89             );
90 5         44 return %correct_caps;
91             }
92              
93             # Which additional fields are allowed on which data categories?
94             sub _get_allowed {
95 5     5   9 my %allowed;
96 5         14 $allowed{$_}{'Note'} = 1 foreach qw ();
97 5         32 $allowed{$_}{'Source'} = 1 foreach qw (
98             definition subjectField context
99             );
100 5         47 $allowed{$_}{'Link'} = 1 foreach qw (
101             transactionType crossReference externalCrossReference xGraphic
102             );
103 5         13 $allowed{'transactionType'}{'Date'} =
104             $allowed{'transactionType'}{'Responsibility'} = 1;
105 5         36 $allowed{$_}{'FieldLang'} = 1 foreach qw (Source Note Responsibility);
106 5         53 return %allowed;
107             }
108              
109             # which data categories are allowed at which level?
110             sub _get_legal_in {
111 5     5   61 $legalIn{'Concept'}{$_} = 1 foreach qw (
112             transactionType crossReference externalCrossReference
113             customerSubset projectSubset xGraphic subjectField note
114             source
115             );
116 5         53 $legalIn{'LangSet'}{$_} = 1 foreach qw (transactionType crossReference
117             externalCrossReference customerSubset projectSubset
118             definition note source
119             );
120             $legalIn{'Term'}{$_} = 1
121 5         109 foreach qw (transactionType crossReference externalCrossReference
122             customerSubset projectSubset context grammaticalGender
123             geographicalUsage partOfSpeech termLocation termType
124             administrativeStatus note source term
125             );
126 5         131 $legalIn{'Party'}{$_} = 1 foreach qw (email title role org uid tel adr fn);
127 5         32 return %legalIn;
128             }
129              
130             # what part of the term structure does each data category go in?
131             sub _get_position {
132 5     5   12 my %position = map { $_ => 'termGrp' } qw (
  30         70  
133             administrativeStatus geographicalUsage grammaticalGender
134             partOfSpeech termLocation termType
135             );
136 45         152 %position = (
137             %position,
138 5         18 map { $_ => 'auxInfo' }
139             qw (
140             context customerSubset projectSubset crossReference note
141             source transactionType externalCrossReference xGraphic
142             )
143             );
144 5         105 return %position;
145             }
146              
147             # which TBX meta data category does each data category print as?
148             sub _get_meta {
149 5     5   8 my %meta;
150 5         24 $meta{$_} = 'admin' foreach qw (customerSubset projectSubset);
151 5         23 $meta{$_} = 'descrip' foreach qw (definition subjectField context);
152             $meta{$_} = 'termNote'
153 5         60 foreach
154             qw (grammaticalGender geographicalUsage partOfSpeech termLocation termType administrativeStatus);
155 5         54 return %meta;
156             }
157              
158             1;
159              
160             __END__