File Coverage

blib/lib/MARC/Field008/Print.pm
Criterion Covered Total %
statement 45 152 29.6
branch 5 44 11.3
condition 0 3 0.0
subroutine 10 14 71.4
pod 2 2 100.0
total 62 215 28.8


line stmt bran cond sub pod time code
1             package MARC::Field008::Print;
2              
3 3     3   115622 use strict;
  3         7  
  3         94  
4 3     3   12 use warnings;
  3         5  
  3         147  
5              
6 3     3   1494 use Check::Term::Color qw(check_term_color);
  3         9283  
  3         59  
7 3     3   1548 use Class::Utils qw(set_params);
  3         16141  
  3         56  
8 3     3   240 use English;
  3         1382  
  3         19  
9 3     3   1199 use Error::Pure qw(err);
  3         4  
  3         134  
10 3     3   1324 use MARC::Field008::L10N 0;
  3         42425  
  3         146  
11 3     3   1542 use Mo::utils 0.06 qw(check_bool);
  3         7649  
  3         80  
12 3     3   1814 use Mo::utils::Language 0.05 qw(check_language_639_1);
  3         569006  
  3         79  
13              
14             our $VERSION = 0.01;
15              
16             # Constructor.
17             sub new {
18 8     8 1 215827 my ($class, @params) = @_;
19              
20             # Create object.
21 8         17 my $self = bless {}, $class;
22              
23             # Language.
24 8         20 $self->{'lang'} = undef;
25              
26             # Use with ANSI sequences.
27 8         10 $self->{'mode_ansi'} = undef;
28              
29             # Use description.
30 8         13 $self->{'mode_desc'} = 1;
31              
32             # Output separator.
33 8         13 $self->{'output_separator'} = "\n";
34              
35             # Process parameters.
36 8         26 set_params($self, @params);
37              
38             # Check 'lang'.
39 8         64 check_language_639_1($self, 'lang');
40              
41             # Check 'mode_ansi'.
42 7         104 check_bool($self, 'mode_ansi');
43              
44             # Check 'mode_desc'.
45 6         47 check_bool($self, 'mode_desc');
46              
47             # Set 'mode_ansi' from env variables.
48 5 50       66 if (! defined $self->{'mode_ansi'}) {
49 5         11 $self->{'mode_ansi'} = check_term_color();
50             }
51              
52             # Check routine for ANSI colors output.
53 5 100       57 if ($self->{'mode_ansi'}) {
54 2         3 eval {
55 2         757 require Term::ANSIColor;
56             };
57 2 50       6930 if ($EVAL_ERROR) {
58 0         0 err "Cannot load 'Term::ANSIColor' module.";
59             }
60             }
61              
62 5 50       30 $self->{'_l'} = MARC::Field008::L10N->get_handle(defined $self->{'lang'} ? $self->{'lang'} : ());
63              
64 5         3720 return $self;
65             }
66              
67             sub print {
68 0     0 1   my ($self, $field008_obj) = @_;
69              
70 0           my @ret;
71             # TODO Print some nice date.
72 0           push @ret, $self->_key('Date entered on file').$field008_obj->date_entered_on_file;
73 0           push @ret, $self->_key('Type of date/Publication status').
74             $self->_print($field008_obj, 'type_of_date');
75 0           push @ret, $self->_key('Date 1').$field008_obj->date1;
76 0           push @ret, $self->_key('Date 2').$field008_obj->date2;
77             # TODO Translate?
78 0           push @ret, $self->_key('Place of publication, production, or execution').
79             $field008_obj->place_of_publication;
80             # TODO Translate?
81 0           push @ret, $self->_key('Material').$field008_obj->material_type;
82 0           my $material = $field008_obj->material;
83 0 0         if ($field008_obj->material_type eq 'book') {
    0          
    0          
    0          
    0          
    0          
84 0           push @ret, $self->_key('Illustrations').
85             $self->_print_multi($material, 'illustrations', 'book');
86 0           push @ret, $self->_key('Target audience').
87             $self->_print($material, 'target_audience');
88 0           push @ret, $self->_key('Form of item').
89             $self->_print($material, 'form_of_item');
90 0           push @ret, $self->_key('Nature of contents').
91             $self->_print_multi($material, 'nature_of_content');
92 0           push @ret, $self->_key('Government publication').
93             $self->_print($material, 'government_publication');
94 0           push @ret, $self->_key('Conference publication').
95             $self->_print($material, 'conference_publication');
96 0           push @ret, $self->_key('Festschrift').
97             $self->_print($material, 'festschrift', 'book');
98 0           push @ret, $self->_key('Index').
99             $self->_print($material, 'index');
100 0           push @ret, $self->_key('Literary form').
101             $self->_print($material, 'literary_form', 'book');
102 0           push @ret, $self->_key('Biography').
103             $self->_print($material, 'biography', 'book');
104             } elsif ($field008_obj->material_type eq 'computer_file') {
105 0           push @ret, $self->_key('Target audience').
106             $self->_print($material, 'target_audience');
107 0           push @ret, $self->_key('Form of item').
108             $self->_print($material, 'form_of_item', 'computer_file');
109 0           push @ret, $self->_key('Type of computer file').
110             $self->_print($material, 'type_of_computer_file', 'computer_file');
111 0           push @ret, $self->_key('Government publication').
112             $self->_print($material, 'government_publication');
113             } elsif ($field008_obj->material_type eq 'continuing_resource') {
114 0           push @ret, $self->_key('Frequency').
115             $self->_print($material, 'frequency', 'continuing_resource');
116 0           push @ret, $self->_key('Regularity').
117             $self->_print($material, 'regularity', 'continuing_resource');
118 0           push @ret, $self->_key('Type of continuing resource').
119             $self->_print($material, 'type_of_continuing_resource',
120             'continuing_resource');
121 0           push @ret, $self->_key('Form of original item').
122             $self->_print($material, 'form_of_original_item',
123             'continuing_resource');
124 0           push @ret, $self->_key('Form of item').
125             $self->_print($material, 'form_of_item');
126 0           push @ret, $self->_key('Nature of entire work').
127             $self->_print($material, 'nature_of_entire_work',
128             'continuing_resource');
129 0           push @ret, $self->_key('Nature of contents').
130             $self->_print_multi($material, 'nature_of_content');
131 0           push @ret, $self->_key('Government publication').
132             $self->_print($material, 'government_publication');
133 0           push @ret, $self->_key('Conference publication').
134             $self->_print($material, 'conference_publication');
135 0           push @ret, $self->_key('Original alphabet or script of title').
136             $self->_print($material, 'original_alphabet_or_script_of_title',
137             'continuing_resource');
138 0           push @ret, $self->_key('Entry convention').
139             $self->_print($material, 'entry_convention',
140             'continuing_resource');
141             } elsif ($field008_obj->material_type eq 'map') {
142 0           push @ret, $self->_key('Relief').
143             $self->_print_multi($material, 'relief', 'map');
144 0           push @ret, $self->_key('Projection').
145             $self->_print($material, 'projection', 'map');
146 0           push @ret, $self->_key('Type of cartographic material').
147             $self->_print($material, 'type_of_cartographic_material', 'map');
148 0           push @ret, $self->_key('Government publication').
149             $self->_print($material, 'government_publication');
150 0           push @ret, $self->_key('Form of item').
151             $self->_print($material, 'form_of_item');
152 0           push @ret, $self->_key('Index').
153             $self->_print($material, 'index');
154 0           push @ret, $self->_key('Special format characteristics').
155             $self->_print_multi($material, 'special_format_characteristics', 'map');
156             } elsif ($field008_obj->material_type eq 'mixed_material') {
157 0           push @ret, $self->_key('Form of item').
158             $self->_print($material, 'form_of_item');
159             } elsif ($field008_obj->material_type eq 'music') {
160 0           push @ret, $self->_key('Form of composition').
161             $self->_print($material, 'form_of_composition', 'music');
162 0           push @ret, $self->_key('Format of music').
163             $self->_print($material, 'format_of_music', 'music');
164 0           push @ret, $self->_key('Music parts').
165             $self->_print($material, 'music_parts', 'music');
166 0           push @ret, $self->_key('Target audience').
167             $self->_print($material, 'target_audience');
168 0           push @ret, $self->_key('Form of item').
169             $self->_print($material, 'form_of_item');
170 0           push @ret, $self->_key('Accompanying matter').
171             $self->_print_multi($material, 'accompanying_matter', 'music');
172 0           push @ret, $self->_key('Literary text for sound recordings').
173             $self->_print_multi($material, 'literary_text_for_sound_recordings',
174             'music');
175 0           push @ret, $self->_key('Transposition and arrangement').
176             $self->_print($material, 'transposition_and_arrangement',
177             'music');
178              
179             # visual_material
180             } else {
181             # XXX For time from 001 to 999 is language key 001.
182 0           my $lang_key;
183 0 0 0       if ($material->running_time_for_motion_pictures_and_videorecordings ne '000'
184             && $material->running_time_for_motion_pictures_and_videorecordings =~ m/^\d+$/ms) {
185              
186 0           $lang_key = '001';
187             }
188             # TODO Value.
189 0           push @ret, $self->_key('Running time for motion pictures and videorecordings').
190             $self->_print($material, 'running_time_for_motion_pictures_and_videorecordings',
191             'visual_material', $lang_key);
192 0           push @ret, $self->_key('Target audience').
193             $self->_print($material, 'target_audience');
194 0           push @ret, $self->_key('Government publication').
195             $self->_print($material, 'government_publication');
196 0           push @ret, $self->_key('Form of item').
197             $self->_print($material, 'form_of_item');
198 0           push @ret, $self->_key('Type of visual material').
199             $self->_print($material, 'type_of_visual_material', 'visual_material');
200 0           push @ret, $self->_key('Technique').
201             $self->_print($material, 'technique', 'visual_material');
202             }
203             # TODO Translate?
204 0           push @ret, $self->_key('Language').$field008_obj->language;
205 0           push @ret, $self->_key('Modified record').
206             $self->_print($field008_obj, 'modified_record');
207 0           push @ret, $self->_key('Cataloging source').
208             $self->_print($field008_obj, 'cataloging_source');
209              
210 0 0         return wantarray ? @ret : (join $self->{'output_separator'}, @ret);
211             }
212              
213             sub _key {
214 0     0     my ($self, $key) = @_;
215              
216 0           my $ret;
217 0           my $value = $self->{'_l'}->maketext($key);
218 0 0         if ($self->{'mode_ansi'}) {
219 0           $ret = Term::ANSIColor::color('cyan').$value.Term::ANSIColor::color('reset');
220             } else {
221 0           $ret = $value;
222             }
223 0           $ret .= ': ';
224              
225 0           return $ret;
226             }
227              
228             sub _print {
229 0     0     my ($self, $obj, $method_name, $prefix, $lang_key) = @_;
230              
231 0           my $ret_value = $obj->$method_name;
232 0           my $ret;
233 0 0         if ($self->{'mode_desc'}) {
234 0 0         if (! defined $lang_key) {
235 0           my $ret_value_fixed = $ret_value;
236 0           $ret_value_fixed =~ s/\ /_/msg;
237 0           $lang_key = $method_name.'.'.$ret_value_fixed;
238 0 0         if (defined $prefix) {
239 0           $lang_key = $prefix.'.'.$lang_key;
240             }
241             }
242 0           $ret = $self->{'_l'}->maketext($lang_key);
243             } else {
244 0           $ret = $ret_value;
245             }
246              
247 0           return $ret;
248             }
249              
250             sub _print_multi {
251 0     0     my ($self, $obj, $method_name, $prefix) = @_;
252              
253 0           my $ret_value = $obj->$method_name;
254 0           my @ret_values = split m//ms, $ret_value;
255 0           my @ret;
256 0           my $not_coded = 0;
257 0           foreach my $process_ret_value (@ret_values) {
258 0 0         if ($process_ret_value eq ' ') {
259 0           next;
260             }
261 0 0         if ($process_ret_value eq '|') {
262 0 0         if (! $not_coded) {
263 0           $not_coded = 1;
264             } else {
265 0           next;
266             }
267             }
268 0 0         if ($self->{'mode_desc'}) {
269 0           my $ret_value_fixed = $process_ret_value;
270 0           $ret_value_fixed =~ s/\ /_/msg;
271 0           my $lang_key = $method_name.'.'.$ret_value_fixed;
272 0 0         if (defined $prefix) {
273 0           $lang_key = $prefix.'.'.$lang_key;
274             }
275 0           push @ret, $self->{'_l'}->maketext($lang_key);
276             } else {
277 0           push @ret, $process_ret_value;
278             }
279             }
280              
281 0 0         return wantarray ? @ret : (join ', ', @ret);
282             }
283              
284             1;
285              
286             __END__