| Filename | /usr/share/perl5/MARC/Field.pm |
| Statements | Executed 129389 statements in 284ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1497 | 8 | 4 | 70.8ms | 75.0ms | MARC::Field::subfield |
| 1650 | 7 | 5 | 58.6ms | 85.6ms | MARC::Field::new |
| 10945 | 6 | 4 | 31.9ms | 31.9ms | MARC::Field::tag |
| 1283 | 4 | 4 | 25.7ms | 29.2ms | MARC::Field::subfields |
| 7585 | 4 | 1 | 17.9ms | 18.5ms | MARC::Field::CORE:match (opcode) |
| 2194 | 2 | 2 | 16.6ms | 22.1ms | MARC::Field::is_controlfield_tag |
| 2182 | 6 | 4 | 16.1ms | 21.4ms | MARC::Field::indicator |
| 5740 | 6 | 3 | 15.5ms | 15.5ms | MARC::Field::is_control_field |
| 569 | 2 | 2 | 8.78ms | 10.5ms | MARC::Field::replace_with |
| 512 | 1 | 1 | 1.98ms | 1.98ms | MARC::Field::warnings |
| 32 | 1 | 1 | 304µs | 413µs | MARC::Field::data |
| 1 | 1 | 1 | 17µs | 25µs | MARC::Field::BEGIN@3 |
| 1 | 1 | 1 | 11µs | 64µs | MARC::Field::BEGIN@7 |
| 1 | 1 | 1 | 9µs | 52µs | MARC::Field::BEGIN@5 |
| 1 | 1 | 1 | 9µs | 11µs | MARC::Field::BEGIN@4 |
| 1 | 1 | 1 | 9µs | 40µs | MARC::Field::BEGIN@8 |
| 1 | 1 | 1 | 8µs | 31µs | MARC::Field::BEGIN@10 |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::_gripe |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::_normalize_arrayref |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::_warn |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::add_subfields |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::allow_controlfield_tags |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::as_formatted |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::as_string |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::as_usmarc |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::clone |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::delete_subfield |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::delete_subfields |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::disallow_controlfield_tags |
| 0 | 0 | 0 | 0s | 0s | MARC::Field::update |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package MARC::Field; | ||||
| 2 | |||||
| 3 | 3 | 28µs | 2 | 33µs | # spent 25µs (17+8) within MARC::Field::BEGIN@3 which was called:
# once (17µs+8µs) by MARC::Record::BEGIN@14 at line 3 # spent 25µs making 1 call to MARC::Field::BEGIN@3
# spent 8µs making 1 call to strict::import |
| 4 | 3 | 23µs | 2 | 14µs | # spent 11µs (9+3) within MARC::Field::BEGIN@4 which was called:
# once (9µs+3µs) by MARC::Record::BEGIN@14 at line 4 # spent 11µs making 1 call to MARC::Field::BEGIN@4
# spent 3µs making 1 call to integer::import |
| 5 | 3 | 36µs | 2 | 96µs | # spent 52µs (9+43) within MARC::Field::BEGIN@5 which was called:
# once (9µs+43µs) by MARC::Record::BEGIN@14 at line 5 # spent 52µs making 1 call to MARC::Field::BEGIN@5
# spent 43µs making 1 call to Exporter::import |
| 6 | |||||
| 7 | 3 | 38µs | 2 | 117µs | # spent 64µs (11+53) within MARC::Field::BEGIN@7 which was called:
# once (11µs+53µs) by MARC::Record::BEGIN@14 at line 7 # spent 64µs making 1 call to MARC::Field::BEGIN@7
# spent 53µs making 1 call to constant::import |
| 8 | 3 | 30µs | 2 | 72µs | # spent 40µ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 40µs making 1 call to MARC::Field::BEGIN@8
# spent 32µs making 1 call to constant::import |
| 9 | |||||
| 10 | 3 | 2.00ms | 2 | 53µs | # spent 31µs (8+23) within MARC::Field::BEGIN@10 which was called:
# once (8µs+23µs) by MARC::Record::BEGIN@14 at line 10 # spent 31µs making 1 call to MARC::Field::BEGIN@10
# spent 22µs making 1 call to vars::import |
| 11 | |||||
| 12 | =head1 NAME | ||||
| 13 | |||||
| - - | |||||
| 48 | 1 | 2µs | my %extra_controlfield_tags = (); | ||
| 49 | |||||
| 50 | |||||
| 51 | =head1 METHODS | ||||
| 52 | |||||
| - - | |||||
| 71 | # spent 85.6ms (58.6+27.0) within MARC::Field::new which was called 1650 times, avg 52µs/call:
# 512 times (19.4ms+7.30ms) by MARC::File::USMARC::decode at line 222 of MARC/File/USMARC.pm, avg 52µs/call
# 512 times (18.0ms+8.07ms) by C4::Charset::SetUTF8Flag at line 142 of /usr/share/koha/lib/C4/Charset.pm, avg 51µs/call
# 480 times (15.2ms+7.94ms) by MARC::File::SAX::end_element at line 92 of MARC/File/SAX.pm, avg 48µs/call
# 57 times (3.34ms+1.66ms) by C4::XSLT::transformMARCXML4XSLT at line 96 of /usr/share/koha/lib/C4/XSLT.pm, avg 88µs/call
# 32 times (948µs+1.28ms) by MARC::File::SAX::end_element at line 83 of MARC/File/SAX.pm, avg 70µs/call
# 32 times (893µs+403µs) by MARC::File::USMARC::decode at line 192 of MARC/File/USMARC.pm, avg 41µs/call
# 25 times (845µs+340µs) by C4::Biblio::_koha_marc_update_bib_ids at line 2854 of /usr/share/koha/lib/C4/Biblio.pm, avg 47µs/call | ||||
| 72 | 1650 | 1.49ms | my $class = shift; | ||
| 73 | 1650 | 751µs | $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 | 1650 | 987µs | my $tagno = shift; | ||
| 82 | 1650 | 12.2ms | 1650 | 6.60ms | ($tagno =~ /^[0-9A-Za-z]{3}$/) # spent 6.60ms making 1650 calls to MARC::Field::CORE:match, avg 4µs/call |
| 83 | or croak( "Tag \"$tagno\" is not a valid tag." ); | ||||
| 84 | 1650 | 5.20ms | 1650 | 15.7ms | my $is_control = $class->is_controlfield_tag($tagno); # spent 15.7ms making 1650 calls to MARC::Field::is_controlfield_tag, avg 10µs/call |
| 85 | |||||
| 86 | 1650 | 9.30ms | my $self = bless { | ||
| 87 | _tag => $tagno, | ||||
| 88 | _warnings => [], | ||||
| 89 | _is_control_field => $is_control, | ||||
| 90 | }, $class; | ||||
| 91 | |||||
| 92 | 1650 | 1.50ms | if ( $is_control ) { | ||
| 93 | 64 | 146µs | $self->{_data} = shift; | ||
| 94 | 64 | 73µs | $self->_warn("Too much data for control field '$tagno'") if (@_); | ||
| 95 | } else { | ||||
| 96 | 1586 | 2.48ms | for my $indcode ( qw( _ind1 _ind2 ) ) { | ||
| 97 | 3172 | 1.96ms | my $indicator = shift; | ||
| 98 | 3172 | 1.26ms | scalar(@_) or croak("Field $tagno must have indicators (use ' ' for empty indicators)"); | ||
| 99 | 3172 | 13.4ms | 3172 | 4.71ms | if ($indicator !~ /^[0-9A-Za-z ]$/ ) { # spent 4.71ms making 3172 calls to MARC::Field::CORE:match, avg 1µs/call |
| 100 | 50 | 36µs | $self->_warn( "Invalid indicator \"$indicator\" forced to blank" ) unless ($indicator eq ""); | ||
| 101 | 50 | 30µs | $indicator = " "; | ||
| 102 | } | ||||
| 103 | 3172 | 7.46ms | $self->{$indcode} = $indicator; | ||
| 104 | } # for | ||||
| 105 | |||||
| 106 | 1586 | 1.03ms | (@_ >= 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 | 1586 | 5.41ms | $self->{_subfields} = [@_]; | ||
| 111 | } | ||||
| 112 | |||||
| 113 | 1650 | 6.02ms | return $self; | ||
| 114 | } # new() | ||||
| 115 | |||||
| 116 | |||||
| 117 | =head2 tag() | ||||
| 118 | |||||
| - - | |||||
| 123 | # spent 31.9ms within MARC::Field::tag which was called 10945 times, avg 3µs/call:
# 7827 times (21.8ms+0s) by MARC::Record::field at line 210 of MARC/Record.pm, avg 3µs/call
# 974 times (1.88ms+0s) by MARC::Record::insert_fields_ordered at line 366 of MARC/Record.pm, avg 2µs/call
# 544 times (2.25ms+0s) by MARC::File::XML::record at line 345 of MARC/File/XML.pm, avg 4µs/call
# 544 times (2.13ms+0s) by C4::Charset::SetUTF8Flag at line 137 of /usr/share/koha/lib/C4/Charset.pm, avg 4µs/call
# 544 times (2.08ms+0s) by C4::Biblio::TransformMarcToKoha at line 2511 of /usr/share/koha/lib/C4/Biblio.pm, avg 4µs/call
# 512 times (1.72ms+0s) by C4::Charset::SetUTF8Flag at line 142 of /usr/share/koha/lib/C4/Charset.pm, avg 3µs/call | ||||
| 124 | 10945 | 5.43ms | my $self = shift; | ||
| 125 | 10945 | 35.1ms | return $self->{_tag}; | ||
| 126 | } | ||||
| 127 | |||||
| 128 | =head2 indicator(indno) | ||||
| 129 | |||||
| - - | |||||
| 136 | # spent 21.4ms (16.1+5.29) within MARC::Field::indicator which was called 2182 times, avg 10µs/call:
# 1024 times (7.18ms+2.36ms) by C4::Charset::SetUTF8Flag at line 142 of /usr/share/koha/lib/C4/Charset.pm, avg 9µs/call
# 512 times (3.86ms+1.20ms) by MARC::File::XML::record at line 351 of MARC/File/XML.pm, avg 10µs/call
# 512 times (3.40ms+1.19ms) by MARC::File::XML::record at line 352 of MARC/File/XML.pm, avg 9µs/call
# 114 times (1.51ms+476µs) by C4::XSLT::transformMARCXML4XSLT at line 96 of /usr/share/koha/lib/C4/XSLT.pm, avg 17µs/call
# 10 times (121µs+43µs) by C4::Koha::GetNormalizedUPC at line 1311 of /usr/share/koha/lib/C4/Koha.pm, avg 16µs/call
# 10 times (59µs+21µs) by C4::Koha::GetNormalizedEAN at line 1373 of /usr/share/koha/lib/C4/Koha.pm, avg 8µs/call | ||||
| 137 | 2182 | 1.16ms | my $self = shift; | ||
| 138 | 2182 | 831µs | my $indno = shift; | ||
| 139 | |||||
| 140 | 2182 | 4.65ms | 2182 | 5.29ms | $self->_warn( "Control fields (generally, those with tags below 010) do not have indicators" ) # spent 5.29ms making 2182 calls to MARC::Field::is_control_field, avg 2µs/call |
| 141 | if $self->is_control_field; | ||||
| 142 | |||||
| 143 | 2182 | 8.51ms | 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 22.1ms (16.6+5.51) within MARC::Field::is_controlfield_tag which was called 2194 times, avg 10µs/call:
# 1650 times (12.0ms+3.74ms) by MARC::Field::new at line 84, avg 10µs/call
# 544 times (4.66ms+1.77ms) by MARC::File::USMARC::decode at line 192 of MARC/File/USMARC.pm, avg 12µs/call | ||||
| 195 | 2194 | 1.48ms | my $self = shift; | ||
| 196 | 2194 | 1.00ms | my $tag = shift; | ||
| 197 | 2194 | 1.31ms | return 1 if ($extra_controlfield_tags{$tag}); | ||
| 198 | 2194 | 12.4ms | 2195 | 6.17ms | return 1 if (($tag =~ /^\d+$/) && ($tag < 10)); # spent 5.51ms making 2194 calls to MARC::Field::CORE:match, avg 3µs/call
# spent 658µs making 1 call to utf8::SWASHNEW |
| 199 | 2098 | 6.27ms | return 0; # otherwise, it's not a control field | ||
| 200 | } | ||||
| 201 | |||||
| 202 | |||||
| 203 | =head2 is_control_field() | ||||
| 204 | |||||
| - - | |||||
| 209 | # spent 15.5ms within MARC::Field::is_control_field which was called 5740 times, avg 3µs/call:
# 2182 times (5.29ms+0s) by MARC::Field::indicator at line 140, avg 2µs/call
# 1497 times (4.19ms+0s) by MARC::Field::subfield at line 238, avg 3µs/call
# 1283 times (3.45ms+0s) by MARC::Field::subfields at line 271, avg 3µs/call
# 544 times (1.80ms+0s) by MARC::File::XML::record at line 346 of MARC/File/XML.pm, avg 3µs/call
# 202 times (631µs+0s) by C4::Biblio::TransformMarcToKoha at line 2513 of /usr/share/koha/lib/C4/Biblio.pm, avg 3µs/call
# 32 times (109µs+0s) by MARC::Field::data at line 291, avg 3µs/call | ||||
| 210 | 5740 | 2.41ms | my $self = shift; | ||
| 211 | 5740 | 20.2ms | return $self->{_is_control_field}; | ||
| 212 | } | ||||
| 213 | |||||
| 214 | =head2 subfield(code) | ||||
| 215 | |||||
| - - | |||||
| 234 | # spent 75.0ms (70.8+4.19) within MARC::Field::subfield which was called 1497 times, avg 50µs/call:
# 1280 times (67.4ms+3.56ms) by C4::Search::searchResults at line 1839 of /usr/share/koha/lib/C4/Search.pm, avg 55µs/call
# 145 times (2.22ms+401µs) by MARC::Record::subfield at line 239 of MARC/Record.pm, avg 18µs/call
# 25 times (484µs+102µs) by C4::Koha::GetNormalizedOCLCNumber at line 1391 of /usr/share/koha/lib/C4/Koha.pm, avg 23µs/call
# 10 times (153µs+17µs) by C4::Koha::GetNormalizedUPC at line 1312 of /usr/share/koha/lib/C4/Koha.pm, avg 17µs/call
# 10 times (129µs+26µs) by C4::Koha::GetNormalizedEAN at line 1374 of /usr/share/koha/lib/C4/Koha.pm, avg 16µs/call
# 9 times (165µs+40µs) by C4::Biblio::GetCOinSBiblio at line 1402 of /usr/share/koha/lib/C4/Biblio.pm, avg 23µs/call
# 9 times (158µs+22µs) by C4::Search::searchResults at line 1787 of /usr/share/koha/lib/C4/Search.pm, avg 20µs/call
# 9 times (94µs+19µs) by C4::Search::searchResults at line 1788 of /usr/share/koha/lib/C4/Search.pm, avg 13µs/call | ||||
| 235 | 1497 | 895µs | my $self = shift; | ||
| 236 | 1497 | 724µs | my $code_wanted = shift; | ||
| 237 | |||||
| 238 | 1497 | 3.40ms | 1497 | 4.19ms | croak( "Control fields (generally, just tags below 010) do not have subfields, use data()" ) # spent 4.19ms making 1497 calls to MARC::Field::is_control_field, avg 3µs/call |
| 239 | if $self->is_control_field; | ||||
| 240 | |||||
| 241 | 1497 | 11.0ms | my @data = @{$self->{_subfields}}; | ||
| 242 | 1497 | 418µs | my @found; | ||
| 243 | 1497 | 39.2ms | while ( defined( my $code = shift @data ) ) { | ||
| 244 | if ( $code eq $code_wanted ) { | ||||
| 245 | push( @found, shift @data ); | ||||
| 246 | } else { | ||||
| 247 | 23045 | 8.50ms | shift @data; | ||
| 248 | } | ||||
| 249 | } | ||||
| 250 | 1497 | 717µs | if ( wantarray() ) { return @found; } | ||
| 251 | 1442 | 6.71ms | return( $found[0] ); | ||
| 252 | } | ||||
| 253 | |||||
| 254 | =head2 subfields() | ||||
| 255 | |||||
| - - | |||||
| 268 | # spent 29.2ms (25.7+3.45) within MARC::Field::subfields which was called 1283 times, avg 23µs/call:
# 512 times (9.29ms+1.55ms) by C4::Charset::SetUTF8Flag at line 139 of /usr/share/koha/lib/C4/Charset.pm, avg 21µs/call
# 512 times (8.96ms+1.19ms) by MARC::File::XML::record at line 354 of MARC/File/XML.pm, avg 20µs/call
# 202 times (4.22ms+482µs) by C4::Biblio::TransformMarcToKoha at line 2530 of /usr/share/koha/lib/C4/Biblio.pm, avg 23µs/call
# 57 times (3.28ms+221µs) by C4::XSLT::transformMARCXML4XSLT at line 90 of /usr/share/koha/lib/C4/XSLT.pm, avg 61µs/call | ||||
| 269 | 1283 | 805µs | my $self = shift; | ||
| 270 | |||||
| 271 | 1283 | 2.78ms | 1283 | 3.45ms | $self->_warn( "Control fields (generally, just tags below 010) do not have subfields" ) # spent 3.45ms making 1283 calls to MARC::Field::is_control_field, avg 3µs/call |
| 272 | if $self->is_control_field; | ||||
| 273 | |||||
| 274 | 1283 | 435µs | my @list; | ||
| 275 | 1283 | 6.50ms | my @data = @{$self->{_subfields}}; | ||
| 276 | 1283 | 9.25ms | while ( defined( my $code = shift @data ) ) { | ||
| 277 | push( @list, [$code, shift @data] ); | ||||
| 278 | } | ||||
| 279 | 1283 | 5.55ms | return @list; | ||
| 280 | } | ||||
| 281 | |||||
| 282 | =head2 data() | ||||
| 283 | |||||
| - - | |||||
| 288 | # spent 413µs (304+109) within MARC::Field::data which was called 32 times, avg 13µs/call:
# 32 times (304µs+109µs) by MARC::File::XML::record at line 347 of MARC/File/XML.pm, avg 13µs/call | ||||
| 289 | 32 | 25µs | my $self = shift; | ||
| 290 | |||||
| 291 | 32 | 89µs | 32 | 109µs | croak( "data() is only for control fields (generally, just tags below 010) , use subfield()" ) # spent 109µs making 32 calls to MARC::Field::is_control_field, avg 3µs/call |
| 292 | unless $self->is_control_field; | ||||
| 293 | |||||
| 294 | 32 | 23µs | $self->{_data} = $_[0] if @_; | ||
| 295 | |||||
| 296 | 32 | 159µs | 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.5ms (8.78+1.69) within MARC::Field::replace_with which was called 569 times, avg 18µs/call:
# 512 times (7.25ms+1.43ms) by C4::Charset::SetUTF8Flag at line 148 of /usr/share/koha/lib/C4/Charset.pm, avg 17µs/call
# 57 times (1.53ms+267µs) by C4::XSLT::transformMARCXML4XSLT at line 96 of /usr/share/koha/lib/C4/XSLT.pm, avg 31µs/call | ||||
| 485 | |||||
| 486 | 569 | 515µs | my ($self,$new) = @_; | ||
| 487 | 569 | 3.46ms | 569 | 1.69ms | ref($new) =~ /^MARC::Field$/ # spent 1.69ms making 569 calls to MARC::Field::CORE:match, avg 3µs/call |
| 488 | or croak("Must pass a MARC::Field object"); | ||||
| 489 | |||||
| 490 | 569 | 6.91ms | %$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.98ms within MARC::Field::warnings which was called 512 times, avg 4µs/call:
# 512 times (1.98ms+0s) by MARC::File::USMARC::decode at line 223 of MARC/File/USMARC.pm, avg 4µs/call | ||||
| 651 | 512 | 283µs | my $self = shift; | ||
| 652 | |||||
| 653 | 512 | 1.83ms | 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 | 6µs | 1; | ||
| 680 | |||||
| 681 | __END__ | ||||
# spent 18.5ms (17.9+658µs) within MARC::Field::CORE:match which was called 7585 times, avg 2µs/call:
# 3172 times (4.71ms+0s) by MARC::Field::new at line 99, avg 1µs/call
# 2194 times (4.85ms+658µs) by MARC::Field::is_controlfield_tag at line 198, avg 3µs/call
# 1650 times (6.60ms+0s) by MARC::Field::new at line 82, avg 4µs/call
# 569 times (1.69ms+0s) by MARC::Field::replace_with at line 487, avg 3µs/call |