Filename | /usr/share/perl5/MARC/Record.pm |
Statements | Executed 681824 statements in 2.14s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
79541 | 2 | 1 | 967ms | 1.69s | append_fields | MARC::Record::
79541 | 1 | 1 | 722ms | 722ms | _all_parms_are_fields | MARC::Record::
5000 | 1 | 1 | 120ms | 120ms | set_leader_lengths | MARC::Record::
10000 | 2 | 2 | 102ms | 102ms | leader | MARC::Record::
5000 | 1 | 1 | 62.0ms | 62.0ms | new | MARC::Record::
5000 | 1 | 1 | 61.7ms | 7.98s | as_usmarc | MARC::Record::
5000 | 1 | 1 | 34.9ms | 34.9ms | fields | MARC::Record::
1 | 1 | 1 | 2.50ms | 5.83ms | BEGIN@14 | MARC::Record::
1 | 1 | 1 | 23µs | 29µs | BEGIN@9 | MARC::Record::
1 | 1 | 1 | 23µs | 63µs | BEGIN@26 | MARC::Record::
1 | 1 | 1 | 18µs | 57µs | BEGIN@12 | MARC::Record::
1 | 1 | 1 | 17µs | 120µs | BEGIN@15 | MARC::Record::
1 | 1 | 1 | 16µs | 106µs | BEGIN@27 | MARC::Record::
1 | 1 | 1 | 16µs | 19µs | BEGIN@10 | MARC::Record::
1 | 1 | 1 | 15µs | 55µs | BEGIN@23 | MARC::Record::
1 | 1 | 1 | 15µs | 52µs | BEGIN@32 | MARC::Record::
1 | 1 | 1 | 13µs | 87µs | BEGIN@34 | MARC::Record::
0 | 0 | 0 | 0s | 0s | _gripe | MARC::Record::
0 | 0 | 0 | 0s | 0s | _warn | MARC::Record::
0 | 0 | 0 | 0s | 0s | add_fields | MARC::Record::
0 | 0 | 0 | 0s | 0s | as_formatted | MARC::Record::
0 | 0 | 0 | 0s | 0s | author | MARC::Record::
0 | 0 | 0 | 0s | 0s | clone | MARC::Record::
0 | 0 | 0 | 0s | 0s | delete_field | MARC::Record::
0 | 0 | 0 | 0s | 0s | edition | MARC::Record::
0 | 0 | 0 | 0s | 0s | encoding | MARC::Record::
0 | 0 | 0 | 0s | 0s | field | MARC::Record::
0 | 0 | 0 | 0s | 0s | insert_fields_after | MARC::Record::
0 | 0 | 0 | 0s | 0s | insert_fields_before | MARC::Record::
0 | 0 | 0 | 0s | 0s | insert_fields_ordered | MARC::Record::
0 | 0 | 0 | 0s | 0s | insert_grouped_field | MARC::Record::
0 | 0 | 0 | 0s | 0s | new_from_usmarc | MARC::Record::
0 | 0 | 0 | 0s | 0s | publication_date | MARC::Record::
0 | 0 | 0 | 0s | 0s | subfield | MARC::Record::
0 | 0 | 0 | 0s | 0s | title | MARC::Record::
0 | 0 | 0 | 0s | 0s | title_proper | MARC::Record::
0 | 0 | 0 | 0s | 0s | warnings | MARC::Record::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package MARC::Record; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
- - | |||||
9 | 3 | 43µs | 2 | 35µs | # spent 29µs (23+6) within MARC::Record::BEGIN@9 which was called:
# once (23µs+6µs) by MARC::File::XML::BEGIN@7 at line 9 # spent 29µs making 1 call to MARC::Record::BEGIN@9
# spent 6µs making 1 call to strict::import |
10 | 3 | 45µs | 2 | 22µs | # spent 19µs (16+3) within MARC::Record::BEGIN@10 which was called:
# once (16µs+3µs) by MARC::File::XML::BEGIN@7 at line 10 # spent 19µs making 1 call to MARC::Record::BEGIN@10
# spent 3µs making 1 call to integer::import |
11 | |||||
12 | 3 | 48µs | 2 | 96µs | # spent 57µs (18+39) within MARC::Record::BEGIN@12 which was called:
# once (18µs+39µs) by MARC::File::XML::BEGIN@7 at line 12 # spent 57µs making 1 call to MARC::Record::BEGIN@12
# spent 39µs making 1 call to vars::import |
13 | |||||
14 | 3 | 163µs | 1 | 5.83ms | # spent 5.83ms (2.50+3.33) within MARC::Record::BEGIN@14 which was called:
# once (2.50ms+3.33ms) by MARC::File::XML::BEGIN@7 at line 14 # spent 5.83ms making 1 call to MARC::Record::BEGIN@14 |
15 | 3 | 47µs | 2 | 223µs | # spent 120µs (17+103) within MARC::Record::BEGIN@15 which was called:
# once (17µs+103µs) by MARC::File::XML::BEGIN@7 at line 15 # spent 120µs making 1 call to MARC::Record::BEGIN@15
# spent 103µs making 1 call to Exporter::import |
16 | |||||
17 | =head1 VERSION | ||||
18 | |||||
- - | |||||
23 | 3 | 65µs | 2 | 95µs | # spent 55µs (15+40) within MARC::Record::BEGIN@23 which was called:
# once (15µs+40µs) by MARC::File::XML::BEGIN@7 at line 23 # spent 55µs making 1 call to MARC::Record::BEGIN@23
# spent 40µs making 1 call to vars::import |
24 | 1 | 2µs | $VERSION = '2.0.0'; | ||
25 | |||||
26 | 3 | 44µs | 2 | 103µs | # spent 63µs (23+40) within MARC::Record::BEGIN@26 which was called:
# once (23µs+40µs) by MARC::File::XML::BEGIN@7 at line 26 # spent 63µs making 1 call to MARC::Record::BEGIN@26
# spent 40µs making 1 call to Exporter::import |
27 | 3 | 69µs | 2 | 196µs | # spent 106µs (16+90) within MARC::Record::BEGIN@27 which was called:
# once (16µs+90µs) by MARC::File::XML::BEGIN@7 at line 27 # spent 106µs making 1 call to MARC::Record::BEGIN@27
# spent 90µs making 1 call to vars::import |
28 | 1 | 10µs | @ISA = qw( Exporter ); | ||
29 | 1 | 1µs | @EXPORTS = qw(); | ||
30 | 1 | 2µs | @EXPORT_OK = qw( LEADER_LEN ); | ||
31 | |||||
32 | 4 | 49µs | 2 | 89µs | # spent 52µs (15+37) within MARC::Record::BEGIN@32 which was called:
# once (15µs+37µs) by MARC::File::XML::BEGIN@7 at line 32 # spent 52µs making 1 call to MARC::Record::BEGIN@32
# spent 37µs making 1 call to vars::import |
33 | |||||
34 | 3 | 2.46ms | 2 | 161µs | # spent 87µs (13+74) within MARC::Record::BEGIN@34 which was called:
# once (13µs+74µs) by MARC::File::XML::BEGIN@7 at line 34 # spent 87µs making 1 call to MARC::Record::BEGIN@34
# spent 74µs making 1 call to constant::import |
35 | |||||
36 | =head1 DESCRIPTION | ||||
37 | |||||
- - | |||||
56 | # spent 62.0ms within MARC::Record::new which was called 5000 times, avg 12µs/call:
# 5000 times (62.0ms+0s) by MARC::File::SAX::start_element at line 51 of MARC/File/SAX.pm, avg 12µs/call | ||||
57 | 5000 | 7.61ms | my $class = shift; | ||
58 | 5000 | 29.1ms | my $self = { | ||
59 | _leader => ' ' x 24, | ||||
60 | _fields => [], | ||||
61 | _warnings => [], | ||||
62 | }; | ||||
63 | 5000 | 31.4ms | return bless $self, $class; | ||
64 | } # new() | ||||
65 | |||||
66 | =head2 new_from_usmarc( $marcblob [, \&filter_func($tagno,$tagdata)] ) | ||||
67 | |||||
- - | |||||
75 | sub new_from_usmarc { | ||||
76 | my $blob = shift; | ||||
77 | $blob = shift if (ref($blob) || ($blob eq "MARC::Record")); | ||||
78 | |||||
79 | require MARC::File::USMARC; | ||||
80 | |||||
81 | return MARC::File::USMARC::decode( $blob, @_ ); | ||||
82 | } | ||||
83 | |||||
84 | =head1 COMMON FIELD RETRIEVAL METHODS | ||||
85 | |||||
- - | |||||
104 | sub title() { | ||||
105 | my $self = shift; | ||||
106 | |||||
107 | my $field = $self->field(245); | ||||
108 | return $field ? $field->as_string : ""; | ||||
109 | } | ||||
110 | |||||
111 | =head2 title_proper() | ||||
112 | |||||
- - | |||||
117 | sub title_proper() { | ||||
118 | my $self = shift; | ||||
119 | |||||
120 | my $field = $self->field(245); | ||||
121 | |||||
122 | if ( $field ) { | ||||
123 | return $field->as_string('anp'); | ||||
124 | } else { | ||||
125 | return ""; | ||||
126 | } | ||||
127 | } | ||||
128 | |||||
129 | =head2 author() | ||||
130 | |||||
- - | |||||
135 | sub author() { | ||||
136 | my $self = shift; | ||||
137 | |||||
138 | my $field = $self->field('100|110|111'); | ||||
139 | return $field ? $field->as_string : ""; | ||||
140 | } | ||||
141 | |||||
142 | =head2 edition() | ||||
143 | |||||
- - | |||||
148 | sub edition() { | ||||
149 | my $self = shift; | ||||
150 | |||||
151 | my $str = $self->subfield(250,'a'); | ||||
152 | return defined $str ? $str : ""; | ||||
153 | } | ||||
154 | |||||
155 | =head2 publication_date() | ||||
156 | |||||
- - | |||||
161 | sub publication_date() { | ||||
162 | my $self = shift; | ||||
163 | |||||
164 | my $str = $self->subfield(260,'c'); | ||||
165 | return defined $str ? $str : ""; | ||||
166 | } | ||||
167 | |||||
168 | =head1 FIELD & SUBFIELD ACCESS METHODS | ||||
169 | |||||
- - | |||||
177 | # spent 34.9ms within MARC::Record::fields which was called 5000 times, avg 7µs/call:
# 5000 times (34.9ms+0s) by MARC::File::USMARC::_build_tag_directory at line 270 of MARC/File/USMARC.pm, avg 7µs/call | ||||
178 | 5000 | 6.71ms | my $self = shift; | ||
179 | 5000 | 34.4ms | return @{$self->{_fields}}; | ||
180 | } | ||||
181 | |||||
182 | =head2 field( I<tagspec(s)> ) | ||||
183 | |||||
- - | |||||
193 | 1 | 1µs | my %field_regex; | ||
194 | |||||
195 | sub field { | ||||
196 | my $self = shift; | ||||
197 | my @specs = @_; | ||||
198 | |||||
199 | my @list = (); | ||||
200 | for my $tag ( @specs ) { | ||||
201 | my $regex = $field_regex{ $tag }; | ||||
202 | |||||
203 | # Compile & stash it if necessary | ||||
204 | if ( not defined $regex ) { | ||||
205 | $regex = qr/^$tag$/; | ||||
206 | $field_regex{ $tag } = $regex; | ||||
207 | } # not defined | ||||
208 | |||||
209 | for my $maybe ( $self->fields ) { | ||||
210 | if ( $maybe->tag =~ $regex ) { | ||||
211 | return $maybe unless wantarray; | ||||
212 | |||||
213 | push( @list, $maybe ); | ||||
214 | } # if | ||||
215 | } # for $maybe | ||||
216 | } # for $tag | ||||
217 | |||||
218 | return unless wantarray; | ||||
219 | return @list; | ||||
220 | } | ||||
221 | |||||
222 | =head2 subfield( $tag, $subfield ) | ||||
223 | |||||
- - | |||||
233 | sub subfield { | ||||
234 | my $self = shift; | ||||
235 | my $tag = shift; | ||||
236 | my $subfield = shift; | ||||
237 | |||||
238 | my $field = $self->field($tag) or return; | ||||
239 | return $field->subfield($subfield); | ||||
240 | } # subfield() | ||||
241 | |||||
242 | =for internal | ||||
243 | |||||
- - | |||||
246 | # spent 722ms within MARC::Record::_all_parms_are_fields which was called 79541 times, avg 9µs/call:
# 79541 times (722ms+0s) by MARC::Record::append_fields at line 268, avg 9µs/call | ||||
247 | 79541 | 212ms | for ( @_ ) { | ||
248 | 79541 | 268ms | return 0 unless ref($_) eq 'MARC::Field'; | ||
249 | } | ||||
250 | 79541 | 350ms | return 1; | ||
251 | } | ||||
252 | |||||
253 | =head2 append_fields( @fields ) | ||||
254 | |||||
- - | |||||
265 | # spent 1.69s (967ms+722ms) within MARC::Record::append_fields which was called 79541 times, avg 21µs/call:
# 59541 times (728ms+541ms) by MARC::File::SAX::end_element at line 92 of MARC/File/SAX.pm, avg 21µs/call
# 20000 times (240ms+181ms) by MARC::File::SAX::end_element at line 83 of MARC/File/SAX.pm, avg 21µs/call | ||||
266 | 79541 | 97.6ms | my $self = shift; | ||
267 | |||||
268 | 79541 | 330ms | 79541 | 722ms | _all_parms_are_fields(@_) or croak('Arguments must be MARC::Field objects'); # spent 722ms making 79541 calls to MARC::Record::_all_parms_are_fields, avg 9µs/call |
269 | |||||
270 | 79541 | 152ms | push(@{ $self->{_fields} }, @_); | ||
271 | 79541 | 323ms | return scalar @_; | ||
272 | } | ||||
273 | |||||
274 | =head2 insert_fields_before( $before_field, @new_fields ) | ||||
275 | |||||
- - | |||||
287 | sub insert_fields_before { | ||||
288 | my $self = shift; | ||||
289 | |||||
290 | _all_parms_are_fields(@_) | ||||
291 | or croak('All arguments must be MARC::Field objects'); | ||||
292 | |||||
293 | my ($before,@new) = @_; | ||||
294 | |||||
295 | ## find position of $before | ||||
296 | my $fields = $self->{_fields}; | ||||
297 | my $pos = 0; | ||||
298 | foreach my $f (@$fields) { | ||||
299 | last if ($f == $before); | ||||
300 | $pos++; | ||||
301 | } | ||||
302 | |||||
303 | ## insert before $before | ||||
304 | if ($pos >= @$fields) { | ||||
305 | $self->_warn("Couldn't find field to insert before"); | ||||
306 | return; | ||||
307 | } | ||||
308 | splice(@$fields,$pos,0,@new); | ||||
309 | return scalar @new; | ||||
310 | |||||
311 | } | ||||
312 | |||||
313 | =head2 insert_fields_after( $after_field, @new_fields ) | ||||
314 | |||||
- - | |||||
321 | sub insert_fields_after { | ||||
322 | my $self = shift; | ||||
323 | |||||
324 | _all_parms_are_fields(@_) or croak('All arguments must be MARC::Field objects'); | ||||
325 | my ($after,@new) = @_; | ||||
326 | |||||
327 | ## find position of $after | ||||
328 | my $fields = $self->{_fields}; | ||||
329 | my $pos = 0; | ||||
330 | foreach my $f (@$fields) { | ||||
331 | last if ($f == $after); | ||||
332 | $pos++; | ||||
333 | } | ||||
334 | |||||
335 | ## insert after $after | ||||
336 | if ($pos+1 >= @$fields) { | ||||
337 | $self->_warn("Couldn't find field to insert after"); | ||||
338 | return; | ||||
339 | } | ||||
340 | splice(@$fields,$pos+1,0,@new); | ||||
341 | return scalar @new; | ||||
342 | } | ||||
343 | |||||
344 | =head2 insert_fields_ordered( @new_fields ) | ||||
345 | |||||
- - | |||||
351 | sub insert_fields_ordered { | ||||
352 | my ( $self, @new ) = @_; | ||||
353 | |||||
354 | _all_parms_are_fields(@new) | ||||
355 | or croak('All arguments must be MARC::Field objects'); | ||||
356 | |||||
357 | ## go through each new field | ||||
358 | NEW_FIELD: foreach my $newField ( @new ) { | ||||
359 | |||||
360 | ## find location before which it should be inserted | ||||
361 | EXISTING_FIELD: foreach my $field ( @{ $self->{_fields} } ) { | ||||
362 | if ( $field->tag() >= $newField->tag() ) { | ||||
363 | $self->insert_fields_before( $field, $newField ); | ||||
364 | next NEW_FIELD; | ||||
365 | } | ||||
366 | } | ||||
367 | |||||
368 | ## if we fell through then this new field is higher than | ||||
369 | ## all the existing fields, so we append. | ||||
370 | $self->append_fields( $newField ); | ||||
371 | |||||
372 | } | ||||
373 | return( scalar( @new ) ); | ||||
374 | } | ||||
375 | |||||
376 | =head2 insert_grouped_field( $field ) | ||||
377 | |||||
- - | |||||
394 | sub insert_grouped_field { | ||||
395 | my ($self,$new) = @_; | ||||
396 | _all_parms_are_fields($new) or croak('Argument must be MARC::Field object'); | ||||
397 | |||||
398 | ## try to find the end of the field group and insert it there | ||||
399 | my $limit = int($new->tag() / 100); | ||||
400 | my $found = 0; | ||||
401 | foreach my $field ($self->fields()) { | ||||
402 | if ( int($field->tag() / 100) > $limit ) { | ||||
403 | $self->insert_fields_before($field,$new); | ||||
404 | $found = 1; | ||||
405 | last; | ||||
406 | } | ||||
407 | } | ||||
408 | |||||
409 | ## if we couldn't find the end of the group, then we must not have | ||||
410 | ## any tags this high yet, so just append it | ||||
411 | if (!$found) { | ||||
412 | $self->append_fields($new); | ||||
413 | } | ||||
414 | |||||
415 | return(1); | ||||
416 | |||||
417 | } | ||||
418 | |||||
419 | |||||
420 | =head2 delete_field( $field ) | ||||
421 | |||||
- - | |||||
437 | sub delete_field { | ||||
438 | my $self = shift; | ||||
439 | my $deleter = shift; | ||||
440 | my $list = $self->{_fields}; | ||||
441 | |||||
442 | my $old_count = @$list; | ||||
443 | @$list = grep { $_ != $deleter } @$list; | ||||
444 | return $old_count - @$list; | ||||
445 | } | ||||
446 | |||||
447 | =head2 as_usmarc() | ||||
448 | |||||
- - | |||||
454 | # spent 7.98s (61.7ms+7.92) within MARC::Record::as_usmarc which was called 5000 times, avg 1.60ms/call:
# 5000 times (61.7ms+7.92s) by main::RUNTIME at line 12 of conv.pl, avg 1.60ms/call | ||||
455 | 5000 | 6.47ms | my $self = shift; | ||
456 | |||||
457 | 5000 | 9.29ms | require MARC::File::USMARC; | ||
458 | |||||
459 | 5000 | 39.8ms | 5000 | 7.92s | return MARC::File::USMARC::encode( $self ); # spent 7.92s making 5000 calls to MARC::File::USMARC::encode, avg 1.58ms/call |
460 | } | ||||
461 | |||||
462 | =head2 as_formatted() | ||||
463 | |||||
- - | |||||
468 | sub as_formatted() { | ||||
469 | my $self = shift; | ||||
470 | |||||
471 | my @lines = ( "LDR " . ($self->{_leader} || "") ); | ||||
472 | for my $field ( @{$self->{_fields}} ) { | ||||
473 | push( @lines, $field->as_formatted() ); | ||||
474 | } | ||||
475 | |||||
476 | return join( "\n", @lines ); | ||||
477 | } # as_formatted | ||||
478 | |||||
479 | |||||
480 | =head2 leader() | ||||
481 | |||||
- - | |||||
487 | # spent 102ms within MARC::Record::leader which was called 10000 times, avg 10µs/call:
# 5000 times (60.7ms+0s) by MARC::File::SAX::end_element at line 108 of MARC/File/SAX.pm, avg 12µs/call
# 5000 times (41.7ms+0s) by MARC::File::USMARC::encode at line 315 of MARC/File/USMARC.pm, avg 8µs/call | ||||
488 | 10000 | 12.8ms | my $self = shift; | ||
489 | 10000 | 12.1ms | my $text = shift; | ||
490 | |||||
491 | 10000 | 16.4ms | if ( defined $text ) { | ||
492 | 5000 | 9.71ms | (length($text) eq 24) | ||
493 | or $self->_warn( "Leader must be 24 bytes long" ); | ||||
494 | 5000 | 9.41ms | $self->{_leader} = $text; | ||
495 | } # set the leader | ||||
496 | |||||
497 | 10000 | 53.2ms | return $self->{_leader}; | ||
498 | } # leader() | ||||
499 | |||||
500 | =head2 encoding() | ||||
501 | |||||
- - | |||||
521 | sub encoding { | ||||
522 | my ($self,$arg) = @_; | ||||
523 | # we basically report from and modify the leader directly | ||||
524 | my $leader = $self->leader(); | ||||
525 | |||||
526 | # when setting | ||||
527 | if ( defined($arg) ) { | ||||
528 | if ( $arg =~ /UTF-8/i ) { | ||||
529 | substr($leader,9,1) = 'a'; | ||||
530 | } | ||||
531 | elsif ( $arg =~ /MARC-8/i ) { | ||||
532 | substr($leader,9,1) = ' '; | ||||
533 | } | ||||
534 | $self->leader($leader); | ||||
535 | } | ||||
536 | |||||
537 | return substr($leader,9,1) eq 'a' ? 'UTF-8' : 'MARC-8'; | ||||
538 | } | ||||
539 | |||||
540 | =head2 set_leader_lengths( $reclen, $baseaddr ) | ||||
541 | |||||
- - | |||||
546 | # spent 120ms within MARC::Record::set_leader_lengths which was called 5000 times, avg 24µs/call:
# 5000 times (120ms+0s) by MARC::File::USMARC::encode at line 312 of MARC/File/USMARC.pm, avg 24µs/call | ||||
547 | 5000 | 6.62ms | my $self = shift; | ||
548 | 5000 | 5.68ms | my $reclen = shift; | ||
549 | 5000 | 5.51ms | my $baseaddr = shift; | ||
550 | 5000 | 39.2ms | substr($self->{_leader},0,5) = sprintf("%05d",$reclen); | ||
551 | 5000 | 18.9ms | substr($self->{_leader},12,5) = sprintf("%05d",$baseaddr); | ||
552 | # MARC21 defaults: http://www.loc.gov/marc/bibliographic/ecbdldrd.html | ||||
553 | 5000 | 14.3ms | substr($self->{_leader},10,2) = '22'; | ||
554 | 5000 | 34.4ms | substr($self->{_leader},20,4) = '4500'; | ||
555 | } | ||||
556 | |||||
557 | =head2 clone() | ||||
558 | |||||
- - | |||||
579 | sub clone { | ||||
580 | my $self = shift; | ||||
581 | my @keeper_tags = @_; | ||||
582 | |||||
583 | # create a new object of whatever type we happen to be | ||||
584 | my $class = ref( $self ); | ||||
585 | my $clone = $class->new(); | ||||
586 | |||||
587 | $clone->{_leader} = $self->{_leader}; | ||||
588 | |||||
589 | my $filtered = @keeper_tags ? [$self->field( @keeper_tags )] : undef; | ||||
590 | |||||
591 | for my $field ( $self->fields() ) { | ||||
592 | if ( !$filtered || (grep {$field eq $_} @$filtered ) ) { | ||||
593 | $clone->append_fields( $field->clone ); | ||||
594 | } | ||||
595 | } | ||||
596 | |||||
597 | # XXX FIX THIS $clone->update_leader(); | ||||
598 | |||||
599 | return $clone; | ||||
600 | } | ||||
601 | |||||
602 | =head2 warnings() | ||||
603 | |||||
- - | |||||
618 | sub warnings() { | ||||
619 | my $self = shift; | ||||
620 | my @warnings = @{$self->{_warnings}}; | ||||
621 | $self->{_warnings} = []; | ||||
622 | return @warnings; | ||||
623 | } | ||||
624 | |||||
625 | =head2 add_fields() | ||||
626 | |||||
- - | |||||
665 | sub add_fields { | ||||
666 | my $self = shift; | ||||
667 | |||||
668 | my $nfields = 0; | ||||
669 | my $fields = $self->{_fields}; | ||||
670 | |||||
671 | while ( my $parm = shift ) { | ||||
672 | # User handed us a list of data (most common possibility) | ||||
673 | if ( ref($parm) eq "" ) { | ||||
674 | my $field = MARC::Field->new( $parm, @_ ) | ||||
675 | or return _gripe( $MARC::Field::ERROR ); | ||||
676 | push( @$fields, $field ); | ||||
677 | ++$nfields; | ||||
678 | last; # Bail out, we're done eating parms | ||||
679 | |||||
680 | # User handed us an object. | ||||
681 | } elsif ( ref($parm) eq "MARC::Field" ) { | ||||
682 | push( @$fields, $parm ); | ||||
683 | ++$nfields; | ||||
684 | |||||
685 | # User handed us an anonymous list of parms | ||||
686 | } elsif ( ref($parm) eq "ARRAY" ) { | ||||
687 | my $field = MARC::Field->new(@$parm) | ||||
688 | or return _gripe( $MARC::Field::ERROR ); | ||||
689 | push( @$fields, $field ); | ||||
690 | ++$nfields; | ||||
691 | |||||
692 | } else { | ||||
693 | croak( "Unknown parm of type", ref($parm), " passed to add_fields()" ); | ||||
694 | } # if | ||||
695 | |||||
696 | } # while | ||||
697 | |||||
698 | return $nfields; | ||||
699 | } | ||||
700 | |||||
701 | # NOTE: _warn is an object method | ||||
702 | sub _warn { | ||||
703 | my $self = shift; | ||||
704 | push( @{$self->{_warnings}}, join( "", @_ ) ); | ||||
705 | return( $self ); | ||||
706 | } | ||||
707 | |||||
708 | |||||
709 | # NOTE: _gripe is NOT an object method | ||||
710 | sub _gripe { | ||||
711 | $ERROR = join( "", @_ ); | ||||
712 | |||||
713 | warn $ERROR; | ||||
714 | |||||
715 | return; | ||||
716 | } | ||||
717 | |||||
718 | |||||
719 | 1 | 8µs | 1; | ||
720 | |||||
721 | __END__ |