Filename | /usr/share/perl5/MARC/Field.pm |
Statements | Executed 129389 statements in 263ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1497 | 8 | 4 | 57.8ms | 61.5ms | subfield | MARC::Field::
1650 | 7 | 5 | 53.8ms | 78.6ms | new | MARC::Field::
10945 | 6 | 4 | 32.5ms | 32.5ms | tag | MARC::Field::
1283 | 4 | 4 | 24.7ms | 28.1ms | subfields | MARC::Field::
2182 | 6 | 4 | 17.1ms | 22.6ms | indicator | MARC::Field::
7585 | 4 | 1 | 16.1ms | 16.8ms | CORE:match (opcode) | MARC::Field::
2194 | 2 | 2 | 15.3ms | 20.4ms | is_controlfield_tag | MARC::Field::
5740 | 6 | 3 | 15.0ms | 15.0ms | is_control_field | MARC::Field::
569 | 2 | 2 | 9.19ms | 10.7ms | replace_with | MARC::Field::
512 | 1 | 1 | 1.45ms | 1.45ms | warnings | MARC::Field::
32 | 1 | 1 | 300µs | 380µs | data | MARC::Field::
1 | 1 | 1 | 17µs | 21µs | BEGIN@3 | MARC::Field::
1 | 1 | 1 | 11µs | 69µs | BEGIN@7 | MARC::Field::
1 | 1 | 1 | 10µs | 42µs | BEGIN@10 | MARC::Field::
1 | 1 | 1 | 9µs | 11µs | BEGIN@4 | MARC::Field::
1 | 1 | 1 | 9µs | 41µs | BEGIN@8 | MARC::Field::
1 | 1 | 1 | 9µs | 50µs | BEGIN@5 | MARC::Field::
0 | 0 | 0 | 0s | 0s | _gripe | MARC::Field::
0 | 0 | 0 | 0s | 0s | _normalize_arrayref | MARC::Field::
0 | 0 | 0 | 0s | 0s | _warn | MARC::Field::
0 | 0 | 0 | 0s | 0s | add_subfields | MARC::Field::
0 | 0 | 0 | 0s | 0s | allow_controlfield_tags | MARC::Field::
0 | 0 | 0 | 0s | 0s | as_formatted | MARC::Field::
0 | 0 | 0 | 0s | 0s | as_string | MARC::Field::
0 | 0 | 0 | 0s | 0s | as_usmarc | MARC::Field::
0 | 0 | 0 | 0s | 0s | clone | MARC::Field::
0 | 0 | 0 | 0s | 0s | delete_subfield | MARC::Field::
0 | 0 | 0 | 0s | 0s | delete_subfields | MARC::Field::
0 | 0 | 0 | 0s | 0s | disallow_controlfield_tags | MARC::Field::
0 | 0 | 0 | 0s | 0s | update | MARC::Field::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package MARC::Field; | ||||
2 | |||||
3 | 3 | 27µs | 2 | 24µs | # spent 21µs (17+4) within MARC::Field::BEGIN@3 which was called:
# once (17µs+4µs) by MARC::Record::BEGIN@14 at line 3 # spent 21µs making 1 call to MARC::Field::BEGIN@3
# spent 4µs making 1 call to strict::import |
4 | 3 | 23µs | 2 | 13µs | # spent 11µs (9+2) within MARC::Field::BEGIN@4 which was called:
# once (9µs+2µs) by MARC::Record::BEGIN@14 at line 4 # spent 11µs making 1 call to MARC::Field::BEGIN@4
# spent 2µs making 1 call to integer::import |
5 | 3 | 36µs | 2 | 92µs | # spent 50µs (9+42) within MARC::Field::BEGIN@5 which was called:
# once (9µs+42µs) by MARC::Record::BEGIN@14 at line 5 # spent 50µs making 1 call to MARC::Field::BEGIN@5
# spent 42µs making 1 call to Exporter::import |
6 | |||||
7 | 3 | 38µs | 2 | 127µs | # spent 69µs (11+58) within MARC::Field::BEGIN@7 which was called:
# once (11µs+58µs) by MARC::Record::BEGIN@14 at line 7 # spent 69µs making 1 call to MARC::Field::BEGIN@7
# spent 58µs making 1 call to constant::import |
8 | 3 | 30µs | 2 | 72µs | # spent 41µs (9+32) within MARC::Field::BEGIN@8 which was called:
# once (9µs+32µs) by MARC::Record::BEGIN@14 at line 8 # spent 41µs making 1 call to MARC::Field::BEGIN@8
# spent 32µs making 1 call to constant::import |
9 | |||||
10 | 3 | 1.85ms | 2 | 74µs | # spent 42µs (10+32) within MARC::Field::BEGIN@10 which was called:
# once (10µs+32µs) by MARC::Record::BEGIN@14 at line 10 # spent 42µs making 1 call to MARC::Field::BEGIN@10
# spent 32µs making 1 call to vars::import |
11 | |||||
12 | =head1 NAME | ||||
13 | |||||
- - | |||||
48 | 1 | 1µs | my %extra_controlfield_tags = (); | ||
49 | |||||
50 | |||||
51 | =head1 METHODS | ||||
52 | |||||
- - | |||||
71 | # spent 78.6ms (53.8+24.8) within MARC::Field::new which was called 1650 times, avg 48µs/call:
# 512 times (17.9ms+8.53ms) by C4::Charset::SetUTF8Flag at line 142 of /usr/share/koha/lib/C4/Charset.pm, avg 52µs/call
# 512 times (16.0ms+5.92ms) by MARC::File::USMARC::decode at line 222 of MARC/File/USMARC.pm, avg 43µs/call
# 480 times (14.1ms+7.02ms) by MARC::File::SAX::end_element at line 92 of MARC/File/SAX.pm, avg 44µs/call
# 57 times (3.60ms+1.65ms) by C4::XSLT::transformMARCXML4XSLT at line 96 of /usr/share/koha/lib/C4/XSLT.pm, avg 92µs/call
# 32 times (730µs+1.17ms) by MARC::File::SAX::end_element at line 83 of MARC/File/SAX.pm, avg 60µs/call
# 32 times (710µs+241µs) by MARC::File::USMARC::decode at line 192 of MARC/File/USMARC.pm, avg 30µs/call
# 25 times (751µs+282µs) by C4::Biblio::_koha_marc_update_bib_ids at line 2854 of /usr/share/koha/lib/C4/Biblio.pm, avg 41µs/call | ||||
72 | 30874 | 64.5ms | my $class = shift; | ||
73 | $class = $class; | ||||
74 | |||||
75 | ## MARC spec indicates that tags can have alphabetical | ||||
76 | ## characters in them! If they do appear we assume that | ||||
77 | ## they have indicators like tags > 010 unless they've | ||||
78 | ## been previously defined as control tags using | ||||
79 | ## add_controlfield | ||||
80 | |||||
81 | my $tagno = shift; | ||||
82 | 1650 | 5.79ms | ($tagno =~ /^[0-9A-Za-z]{3}$/) # spent 5.79ms making 1650 calls to MARC::Field::CORE:match, avg 4µs/call | ||
83 | or croak( "Tag \"$tagno\" is not a valid tag." ); | ||||
84 | 1650 | 14.7ms | my $is_control = $class->is_controlfield_tag($tagno); # spent 14.7ms making 1650 calls to MARC::Field::is_controlfield_tag, avg 9µs/call | ||
85 | |||||
86 | my $self = bless { | ||||
87 | _tag => $tagno, | ||||
88 | _warnings => [], | ||||
89 | _is_control_field => $is_control, | ||||
90 | }, $class; | ||||
91 | |||||
92 | if ( $is_control ) { | ||||
93 | $self->{_data} = shift; | ||||
94 | $self->_warn("Too much data for control field '$tagno'") if (@_); | ||||
95 | } else { | ||||
96 | for my $indcode ( qw( _ind1 _ind2 ) ) { | ||||
97 | my $indicator = shift; | ||||
98 | scalar(@_) or croak("Field $tagno must have indicators (use ' ' for empty indicators)"); | ||||
99 | 3172 | 4.34ms | if ($indicator !~ /^[0-9A-Za-z ]$/ ) { # spent 4.34ms making 3172 calls to MARC::Field::CORE:match, avg 1µs/call | ||
100 | $self->_warn( "Invalid indicator \"$indicator\" forced to blank" ) unless ($indicator eq ""); | ||||
101 | $indicator = " "; | ||||
102 | } | ||||
103 | $self->{$indcode} = $indicator; | ||||
104 | } # for | ||||
105 | |||||
106 | (@_ >= 2) | ||||
107 | or croak( "Field $tagno must have at least one subfield" ); | ||||
108 | |||||
109 | # Normally, we go thru add_subfields(), but internally we can cheat | ||||
110 | $self->{_subfields} = [@_]; | ||||
111 | } | ||||
112 | |||||
113 | return $self; | ||||
114 | } # new() | ||||
115 | |||||
116 | |||||
117 | =head2 tag() | ||||
118 | |||||
- - | |||||
123 | # spent 32.5ms within MARC::Field::tag which was called 10945 times, avg 3µs/call:
# 7827 times (22.0ms+0s) by MARC::Record::field at line 210 of MARC/Record.pm, avg 3µs/call
# 974 times (1.75ms+0s) by MARC::Record::insert_fields_ordered at line 366 of MARC/Record.pm, avg 2µs/call
# 544 times (2.54ms+0s) by C4::Charset::SetUTF8Flag at line 137 of /usr/share/koha/lib/C4/Charset.pm, avg 5µs/call
# 544 times (2.29ms+0s) by MARC::File::XML::record at line 345 of MARC/File/XML.pm, avg 4µs/call
# 544 times (1.67ms+0s) by C4::Biblio::TransformMarcToKoha at line 2511 of /usr/share/koha/lib/C4/Biblio.pm, avg 3µs/call
# 512 times (2.24ms+0s) by C4::Charset::SetUTF8Flag at line 142 of /usr/share/koha/lib/C4/Charset.pm, avg 4µs/call | ||||
124 | 21890 | 41.1ms | my $self = shift; | ||
125 | return $self->{_tag}; | ||||
126 | } | ||||
127 | |||||
128 | =head2 indicator(indno) | ||||
129 | |||||
- - | |||||
136 | # spent 22.6ms (17.1+5.51) within MARC::Field::indicator which was called 2182 times, avg 10µs/call:
# 1024 times (7.46ms+2.57ms) by C4::Charset::SetUTF8Flag at line 142 of /usr/share/koha/lib/C4/Charset.pm, avg 10µs/call
# 512 times (4.02ms+1.25ms) by MARC::File::XML::record at line 352 of MARC/File/XML.pm, avg 10µs/call
# 512 times (3.97ms+1.18ms) by MARC::File::XML::record at line 351 of MARC/File/XML.pm, avg 10µs/call
# 114 times (1.47ms+462µs) by C4::XSLT::transformMARCXML4XSLT at line 96 of /usr/share/koha/lib/C4/XSLT.pm, avg 17µs/call
# 10 times (122µs+35µs) by C4::Koha::GetNormalizedUPC at line 1311 of /usr/share/koha/lib/C4/Koha.pm, avg 16µs/call
# 10 times (63µs+22µs) by C4::Koha::GetNormalizedEAN at line 1373 of /usr/share/koha/lib/C4/Koha.pm, avg 9µs/call | ||||
137 | 8728 | 16.0ms | my $self = shift; | ||
138 | my $indno = shift; | ||||
139 | |||||
140 | 2182 | 5.51ms | $self->_warn( "Control fields (generally, those with tags below 010) do not have indicators" ) # spent 5.51ms making 2182 calls to MARC::Field::is_control_field, avg 3µs/call | ||
141 | if $self->is_control_field; | ||||
142 | |||||
143 | if ( $indno == 1 ) { | ||||
144 | return $self->{_ind1}; | ||||
145 | } elsif ( $indno == 2 ) { | ||||
146 | return $self->{_ind2}; | ||||
147 | } else { | ||||
148 | croak( "Indicator number must be 1 or 2" ); | ||||
149 | } | ||||
150 | } | ||||
151 | |||||
152 | =head2 allow_controlfield_tags($tag, $tag2, ...) | ||||
153 | |||||
- - | |||||
159 | sub allow_controlfield_tags { | ||||
160 | my $self = shift; | ||||
161 | foreach my $tag (@_) { | ||||
162 | $extra_controlfield_tags{$tag} = 1; | ||||
163 | } | ||||
164 | } | ||||
165 | |||||
166 | =head2 disallow_controlfield_tags($tag, $tag2, ...) | ||||
167 | |||||
- - | |||||
176 | sub disallow_controlfield_tags { | ||||
177 | my $self = shift; | ||||
178 | if ($_[0] eq '*') { | ||||
179 | %extra_controlfield_tags = (); | ||||
180 | return; | ||||
181 | } | ||||
182 | foreach my $tag (@_) { | ||||
183 | delete $extra_controlfield_tags{$tag}; | ||||
184 | } | ||||
185 | } | ||||
186 | |||||
187 | =head2 is_controlfield_tag($tag) -- does the given tag denote a control field? | ||||
188 | |||||
- - | |||||
193 | sub is_controlfield_tag | ||||
194 | # spent 20.4ms (15.3+5.07) within MARC::Field::is_controlfield_tag which was called 2194 times, avg 9µs/call:
# 1650 times (11.3ms+3.38ms) by MARC::Field::new at line 84, avg 9µs/call
# 544 times (3.98ms+1.70ms) by MARC::File::USMARC::decode at line 192 of MARC/File/USMARC.pm, avg 10µs/call | ||||
195 | 10874 | 20.9ms | my $self = shift; | ||
196 | my $tag = shift; | ||||
197 | return 1 if ($extra_controlfield_tags{$tag}); | ||||
198 | 1 | 14µs | 2195 | 5.68ms | return 1 if (($tag =~ /^\d+$/) && ($tag < 10)); # spent 5.07ms making 2194 calls to MARC::Field::CORE:match, avg 2µs/call
# spent 613µs making 1 call to utf8::SWASHNEW |
199 | return 0; # otherwise, it's not a control field | ||||
200 | } | ||||
201 | |||||
202 | |||||
203 | =head2 is_control_field() | ||||
204 | |||||
- - | |||||
209 | # spent 15.0ms within MARC::Field::is_control_field which was called 5740 times, avg 3µs/call:
# 2182 times (5.51ms+0s) by MARC::Field::indicator at line 140, avg 3µs/call
# 1497 times (3.63ms+0s) by MARC::Field::subfield at line 238, avg 2µs/call
# 1283 times (3.37ms+0s) by MARC::Field::subfields at line 271, avg 3µs/call
# 544 times (1.84ms+0s) by MARC::File::XML::record at line 346 of MARC/File/XML.pm, avg 3µs/call
# 202 times (582µs+0s) by C4::Biblio::TransformMarcToKoha at line 2513 of /usr/share/koha/lib/C4/Biblio.pm, avg 3µs/call
# 32 times (80µs+0s) by MARC::Field::data at line 291, avg 3µs/call | ||||
210 | 11480 | 23.1ms | my $self = shift; | ||
211 | return $self->{_is_control_field}; | ||||
212 | } | ||||
213 | |||||
214 | =head2 subfield(code) | ||||
215 | |||||
- - | |||||
234 | # spent 61.5ms (57.8+3.63) within MARC::Field::subfield which was called 1497 times, avg 41µs/call:
# 1280 times (54.7ms+3.09ms) by C4::Search::searchResults at line 1839 of /usr/share/koha/lib/C4/Search.pm, avg 45µs/call
# 145 times (2.07ms+328µs) by MARC::Record::subfield at line 239 of MARC/Record.pm, avg 17µs/call
# 25 times (400µs+108µs) by C4::Koha::GetNormalizedOCLCNumber at line 1391 of /usr/share/koha/lib/C4/Koha.pm, avg 20µs/call
# 10 times (150µs+20µs) by C4::Koha::GetNormalizedUPC at line 1312 of /usr/share/koha/lib/C4/Koha.pm, avg 17µs/call
# 10 times (106µs+20µs) by C4::Koha::GetNormalizedEAN at line 1374 of /usr/share/koha/lib/C4/Koha.pm, avg 13µs/call
# 9 times (173µs+26µs) by C4::Search::searchResults at line 1787 of /usr/share/koha/lib/C4/Search.pm, avg 22µs/call
# 9 times (127µs+25µs) by C4::Biblio::GetCOinSBiblio at line 1402 of /usr/share/koha/lib/C4/Biblio.pm, avg 17µs/call
# 9 times (90µs+17µs) by C4::Search::searchResults at line 1788 of /usr/share/koha/lib/C4/Search.pm, avg 12µs/call | ||||
235 | 34966 | 57.9ms | my $self = shift; | ||
236 | my $code_wanted = shift; | ||||
237 | |||||
238 | 1497 | 3.63ms | croak( "Control fields (generally, just tags below 010) do not have subfields, use data()" ) # spent 3.63ms making 1497 calls to MARC::Field::is_control_field, avg 2µs/call | ||
239 | if $self->is_control_field; | ||||
240 | |||||
241 | my @data = @{$self->{_subfields}}; | ||||
242 | my @found; | ||||
243 | while ( defined( my $code = shift @data ) ) { | ||||
244 | if ( $code eq $code_wanted ) { | ||||
245 | push( @found, shift @data ); | ||||
246 | } else { | ||||
247 | shift @data; | ||||
248 | } | ||||
249 | } | ||||
250 | if ( wantarray() ) { return @found; } | ||||
251 | return( $found[0] ); | ||||
252 | } | ||||
253 | |||||
254 | =head2 subfields() | ||||
255 | |||||
- - | |||||
268 | # spent 28.1ms (24.7+3.37) within MARC::Field::subfields which was called 1283 times, avg 22µs/call:
# 512 times (9.60ms+1.47ms) by C4::Charset::SetUTF8Flag at line 139 of /usr/share/koha/lib/C4/Charset.pm, avg 22µs/call
# 512 times (9.00ms+1.34ms) by MARC::File::XML::record at line 354 of MARC/File/XML.pm, avg 20µs/call
# 202 times (3.79ms+376µs) by C4::Biblio::TransformMarcToKoha at line 2530 of /usr/share/koha/lib/C4/Biblio.pm, avg 21µs/call
# 57 times (2.29ms+187µs) by C4::XSLT::transformMARCXML4XSLT at line 90 of /usr/share/koha/lib/C4/XSLT.pm, avg 44µs/call | ||||
269 | 7698 | 24.5ms | my $self = shift; | ||
270 | |||||
271 | 1283 | 3.37ms | $self->_warn( "Control fields (generally, just tags below 010) do not have subfields" ) # spent 3.37ms making 1283 calls to MARC::Field::is_control_field, avg 3µs/call | ||
272 | if $self->is_control_field; | ||||
273 | |||||
274 | my @list; | ||||
275 | my @data = @{$self->{_subfields}}; | ||||
276 | while ( defined( my $code = shift @data ) ) { | ||||
277 | push( @list, [$code, shift @data] ); | ||||
278 | } | ||||
279 | return @list; | ||||
280 | } | ||||
281 | |||||
282 | =head2 data() | ||||
283 | |||||
- - | |||||
288 | # spent 380µs (300+80) within MARC::Field::data which was called 32 times, avg 12µs/call:
# 32 times (300µs+80µs) by MARC::File::XML::record at line 347 of MARC/File/XML.pm, avg 12µs/call | ||||
289 | 128 | 296µs | my $self = shift; | ||
290 | |||||
291 | 32 | 80µs | croak( "data() is only for control fields (generally, just tags below 010) , use subfield()" ) # spent 80µs making 32 calls to MARC::Field::is_control_field, avg 3µs/call | ||
292 | unless $self->is_control_field; | ||||
293 | |||||
294 | $self->{_data} = $_[0] if @_; | ||||
295 | |||||
296 | return $self->{_data}; | ||||
297 | } | ||||
298 | |||||
299 | =head2 add_subfields(code,text[,code,text ...]) | ||||
300 | |||||
- - | |||||
309 | sub add_subfields { | ||||
310 | my $self = shift; | ||||
311 | |||||
312 | croak( "Subfields are only for data fields (generally, just tags >= 010)" ) | ||||
313 | if $self->is_control_field; | ||||
314 | |||||
315 | push( @{$self->{_subfields}}, @_ ); | ||||
316 | return @_/2; | ||||
317 | } | ||||
318 | |||||
319 | =head2 delete_subfield() | ||||
320 | |||||
- - | |||||
345 | sub delete_subfield { | ||||
346 | my ($self, %options) = @_; | ||||
347 | my $codes = _normalize_arrayref($options{code}); | ||||
348 | my $positions = _normalize_arrayref($options{'pos'}); | ||||
349 | my $match = $options{match}; | ||||
350 | |||||
351 | croak 'match must be a compiled regex' | ||||
352 | if $match and ref($match) ne 'Regexp'; | ||||
353 | |||||
354 | my @current_subfields = @{$self->{_subfields}}; | ||||
355 | my @new_subfields = (); | ||||
356 | my $removed = 0; | ||||
357 | my $subfield_num = $[ - 1; # users $[ preferences control indexing | ||||
358 | |||||
359 | while (@current_subfields > 0) { | ||||
360 | $subfield_num += 1; | ||||
361 | my $subfield_code = shift @current_subfields; | ||||
362 | my $subfield_value = shift @current_subfields; | ||||
363 | if ((@$codes==0 or grep {$_ eq $subfield_code} @$codes) | ||||
364 | and (!$match or $subfield_value =~ $match) | ||||
365 | and (@$positions==0 or grep {$_ == $subfield_num} @$positions)) { | ||||
366 | $removed += 1; | ||||
367 | next; | ||||
368 | } | ||||
369 | push( @new_subfields, $subfield_code, $subfield_value); | ||||
370 | } | ||||
371 | $self->{_subfields} = \@new_subfields; | ||||
372 | return $removed; | ||||
373 | } | ||||
374 | |||||
375 | =head2 delete_subfields() | ||||
376 | |||||
- - | |||||
382 | sub delete_subfields { | ||||
383 | my ($self, $code) = @_; | ||||
384 | return $self->delete_subfield(code => $code); | ||||
385 | } | ||||
386 | |||||
387 | =head2 update() | ||||
388 | |||||
- - | |||||
418 | sub update { | ||||
419 | my $self = shift; | ||||
420 | |||||
421 | ## tags 000 - 009 don't have indicators or subfields | ||||
422 | if ( $self->is_control_field ) { | ||||
423 | $self->{_data} = shift; | ||||
424 | return(1); | ||||
425 | } | ||||
426 | |||||
427 | ## otherwise we need to update subfields and indicators | ||||
428 | my @data = @{$self->{_subfields}}; | ||||
429 | my $changes = 0; | ||||
430 | |||||
431 | while ( @_ ) { | ||||
432 | |||||
433 | my $arg = shift; | ||||
434 | my $val = shift; | ||||
435 | |||||
436 | ## indicator update | ||||
437 | if ($arg =~ /^ind[12]$/) { | ||||
438 | $self->{"_$arg"} = $val; | ||||
439 | $changes++; | ||||
440 | } | ||||
441 | |||||
442 | ## subfield update | ||||
443 | else { | ||||
444 | my $found = 0; | ||||
445 | ## update existing subfield | ||||
446 | for ( my $i=0; $i<@data; $i+=2 ) { | ||||
447 | if ($data[$i] eq $arg) { | ||||
448 | $data[$i+1] = $val; | ||||
449 | $found = 1; | ||||
450 | $changes++; | ||||
451 | last; | ||||
452 | } | ||||
453 | } # for | ||||
454 | |||||
455 | ## append new subfield | ||||
456 | if ( !$found ) { | ||||
457 | push( @data, $arg, $val ); | ||||
458 | $changes++; | ||||
459 | } | ||||
460 | } | ||||
461 | |||||
462 | } # while | ||||
463 | |||||
464 | ## synchronize our subfields | ||||
465 | $self->{_subfields} = \@data; | ||||
466 | return($changes); | ||||
467 | |||||
468 | } | ||||
469 | |||||
470 | =head2 replace_with() | ||||
471 | |||||
- - | |||||
484 | # spent 10.7ms (9.19+1.56) within MARC::Field::replace_with which was called 569 times, avg 19µs/call:
# 512 times (7.53ms+1.34ms) by C4::Charset::SetUTF8Flag at line 148 of /usr/share/koha/lib/C4/Charset.pm, avg 17µs/call
# 57 times (1.67ms+215µs) by C4::XSLT::transformMARCXML4XSLT at line 96 of /usr/share/koha/lib/C4/XSLT.pm, avg 33µs/call | ||||
485 | |||||
486 | 1707 | 11.2ms | my ($self,$new) = @_; | ||
487 | 569 | 1.56ms | ref($new) =~ /^MARC::Field$/ # spent 1.56ms making 569 calls to MARC::Field::CORE:match, avg 3µs/call | ||
488 | or croak("Must pass a MARC::Field object"); | ||||
489 | |||||
490 | %$self = %$new; | ||||
491 | |||||
492 | } | ||||
493 | |||||
494 | |||||
495 | =head2 as_string( [$subfields] ) | ||||
496 | |||||
- - | |||||
520 | sub as_string() { | ||||
521 | my $self = shift; | ||||
522 | my $subfields = shift; | ||||
523 | |||||
524 | if ( $self->is_control_field ) { | ||||
525 | return $self->{_data}; | ||||
526 | } | ||||
527 | |||||
528 | my @subs; | ||||
529 | |||||
530 | my $subs = $self->{_subfields}; | ||||
531 | my $nfields = @$subs / 2; | ||||
532 | for my $i ( 1..$nfields ) { | ||||
533 | my $offset = ($i-1)*2; | ||||
534 | my $code = $subs->[$offset]; | ||||
535 | my $text = $subs->[$offset+1]; | ||||
536 | push( @subs, $text ) if !$subfields || $code =~ /^[$subfields]$/; | ||||
537 | } # for | ||||
538 | |||||
539 | return join( " ", @subs ); | ||||
540 | } | ||||
541 | |||||
542 | |||||
543 | =head2 as_formatted() | ||||
544 | |||||
- - | |||||
549 | sub as_formatted() { | ||||
550 | my $self = shift; | ||||
551 | |||||
552 | my @lines; | ||||
553 | |||||
554 | if ( $self->is_control_field ) { | ||||
555 | push( @lines, sprintf( "%03s %s", $self->{_tag}, $self->{_data} ) ); | ||||
556 | } else { | ||||
557 | my $hanger = sprintf( "%03s %1.1s%1.1s", $self->{_tag}, $self->{_ind1}, $self->{_ind2} ); | ||||
558 | |||||
559 | my $subs = $self->{_subfields}; | ||||
560 | my $nfields = @$subs / 2; | ||||
561 | my $offset = 0; | ||||
562 | for my $i ( 1..$nfields ) { | ||||
563 | push( @lines, sprintf( "%-6.6s _%1.1s%s", $hanger, $subs->[$offset++], $subs->[$offset++] ) ); | ||||
564 | $hanger = ""; | ||||
565 | } # for | ||||
566 | } | ||||
567 | |||||
568 | return join( "\n", @lines ); | ||||
569 | } | ||||
570 | |||||
571 | |||||
572 | =head2 as_usmarc() | ||||
573 | |||||
- - | |||||
579 | sub as_usmarc() { | ||||
580 | my $self = shift; | ||||
581 | |||||
582 | # Control fields are pretty easy | ||||
583 | if ( $self->is_control_field ) { | ||||
584 | return $self->data . END_OF_FIELD; | ||||
585 | } else { | ||||
586 | my @subs; | ||||
587 | my @subdata = @{$self->{_subfields}}; | ||||
588 | while ( @subdata ) { | ||||
589 | push( @subs, join( "", SUBFIELD_INDICATOR, shift @subdata, shift @subdata ) ); | ||||
590 | } # while | ||||
591 | |||||
592 | return | ||||
593 | join( "", | ||||
594 | $self->indicator(1), | ||||
595 | $self->indicator(2), | ||||
596 | @subs, | ||||
597 | END_OF_FIELD, ); | ||||
598 | } | ||||
599 | } | ||||
600 | |||||
601 | =head2 clone() | ||||
602 | |||||
- - | |||||
615 | sub clone { | ||||
616 | my $self = shift; | ||||
617 | |||||
618 | my $tagno = $self->{_tag}; | ||||
619 | my $is_control = $self->is_controlfield_tag($tagno); | ||||
620 | |||||
621 | my $clone = | ||||
622 | bless { | ||||
623 | _tag => $tagno, | ||||
624 | _warnings => [], | ||||
625 | _is_control_field => $is_control, | ||||
626 | }, ref($self); | ||||
627 | |||||
628 | if ( $is_control ) { | ||||
629 | $clone->{_data} = $self->{_data}; | ||||
630 | } else { | ||||
631 | $clone->{_ind1} = $self->{_ind1}; | ||||
632 | $clone->{_ind2} = $self->{_ind2}; | ||||
633 | $clone->{_subfields} = [@{$self->{_subfields}}]; | ||||
634 | } | ||||
635 | |||||
636 | return $clone; | ||||
637 | } | ||||
638 | |||||
639 | =head2 warnings() | ||||
640 | |||||
- - | |||||
650 | # spent 1.45ms within MARC::Field::warnings which was called 512 times, avg 3µs/call:
# 512 times (1.45ms+0s) by MARC::File::USMARC::decode at line 223 of MARC/File/USMARC.pm, avg 3µs/call | ||||
651 | 1024 | 1.70ms | my $self = shift; | ||
652 | |||||
653 | return @{$self->{_warnings}}; | ||||
654 | } | ||||
655 | |||||
656 | # NOTE: _warn is an object method | ||||
657 | sub _warn($) { | ||||
658 | my $self = shift; | ||||
659 | |||||
660 | push( @{$self->{_warnings}}, join( "", @_ ) ); | ||||
661 | } | ||||
662 | |||||
663 | sub _gripe(@) { | ||||
664 | $ERROR = join( "", @_ ); | ||||
665 | |||||
666 | warn $ERROR; | ||||
667 | |||||
668 | return; | ||||
669 | } | ||||
670 | |||||
671 | sub _normalize_arrayref { | ||||
672 | my $ref = shift; | ||||
673 | if (ref($ref) eq 'ARRAY') { return $ref } | ||||
674 | elsif (defined $ref) { return [$ref] } | ||||
675 | return []; | ||||
676 | } | ||||
677 | |||||
678 | |||||
679 | 1 | 4µs | 1; | ||
680 | |||||
681 | __END__ | ||||
# spent 16.8ms (16.1+613µs) within MARC::Field::CORE:match which was called 7585 times, avg 2µs/call:
# 3172 times (4.34ms+0s) by MARC::Field::new at line 99, avg 1µs/call
# 2194 times (4.46ms+613µs) by MARC::Field::is_controlfield_tag at line 198, avg 2µs/call
# 1650 times (5.79ms+0s) by MARC::Field::new at line 82, avg 4µs/call
# 569 times (1.56ms+0s) by MARC::Field::replace_with at line 487, avg 3µs/call |