| Filename | /usr/share/perl5/MARC/Record.pm |
| Statements | Executed 28081 statements in 104ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 471 | 12 | 5 | 57.8ms | 96.8ms | MARC::Record::field |
| 7840 | 2 | 1 | 8.41ms | 8.41ms | MARC::Record::CORE:regcomp (opcode) |
| 1131 | 3 | 1 | 7.54ms | 9.46ms | MARC::Record::_all_parms_are_fields |
| 1081 | 5 | 3 | 7.24ms | 16.4ms | MARC::Record::append_fields |
| 7827 | 1 | 1 | 6.22ms | 6.22ms | MARC::Record::CORE:match (opcode) |
| 596 | 6 | 5 | 3.57ms | 3.57ms | MARC::Record::fields |
| 544 | 1 | 1 | 3.57ms | 5.37ms | MARC::Record::encoding |
| 694 | 7 | 5 | 2.87ms | 2.87ms | MARC::Record::leader |
| 25 | 1 | 1 | 2.67ms | 4.87ms | MARC::Record::insert_fields_ordered |
| 1 | 1 | 1 | 2.06ms | 2.30ms | MARC::Record::BEGIN@14 |
| 186 | 12 | 2 | 1.71ms | 28.1ms | MARC::Record::subfield |
| 75 | 3 | 3 | 1.10ms | 1.10ms | MARC::Record::new |
| 25 | 1 | 1 | 615µs | 809µs | MARC::Record::delete_fields |
| 25 | 1 | 1 | 155µs | 964µs | MARC::Record::delete_field |
| 13 | 1 | 1 | 59µs | 59µs | MARC::Record::CORE:qr (opcode) |
| 1 | 1 | 1 | 23µs | 71µs | MARC::Record::BEGIN@23 |
| 1 | 1 | 1 | 17µs | 20µs | MARC::Record::BEGIN@9 |
| 1 | 1 | 1 | 15µs | 87µs | MARC::Record::BEGIN@34 |
| 1 | 1 | 1 | 14µs | 39µs | MARC::Record::BEGIN@26 |
| 1 | 1 | 1 | 14µs | 62µs | MARC::Record::BEGIN@15 |
| 1 | 1 | 1 | 12µs | 15µs | MARC::Record::BEGIN@10 |
| 1 | 1 | 1 | 10µs | 38µs | MARC::Record::BEGIN@32 |
| 1 | 1 | 1 | 9µs | 127µs | MARC::Record::BEGIN@27 |
| 1 | 1 | 1 | 8µs | 33µs | MARC::Record::BEGIN@12 |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::_gripe |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::_warn |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::add_fields |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::as_formatted |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::as_usmarc |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::author |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::clone |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::edition |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::insert_fields_after |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::insert_fields_before |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::insert_grouped_field |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::new_from_usmarc |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::publication_date |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::set_leader_lengths |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::title |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::title_proper |
| 0 | 0 | 0 | 0s | 0s | MARC::Record::warnings |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package MARC::Record; | ||||
| 2 | |||||
| 3 | =head1 NAME | ||||
| 4 | |||||
| - - | |||||
| 9 | 3 | 29µs | 2 | 24µs | # spent 20µs (17+4) within MARC::Record::BEGIN@9 which was called:
# once (17µs+4µs) by C4::Biblio::BEGIN@27 at line 9 # spent 20µs making 1 call to MARC::Record::BEGIN@9
# spent 4µs making 1 call to strict::import |
| 10 | 3 | 42µs | 2 | 19µs | # spent 15µs (12+3) within MARC::Record::BEGIN@10 which was called:
# once (12µs+3µs) by C4::Biblio::BEGIN@27 at line 10 # spent 15µs making 1 call to MARC::Record::BEGIN@10
# spent 3µs making 1 call to integer::import |
| 11 | |||||
| 12 | 3 | 28µs | 2 | 58µs | # spent 33µs (8+25) within MARC::Record::BEGIN@12 which was called:
# once (8µs+25µs) by C4::Biblio::BEGIN@27 at line 12 # spent 33µs making 1 call to MARC::Record::BEGIN@12
# spent 25µs making 1 call to vars::import |
| 13 | |||||
| 14 | 3 | 127µs | 2 | 2.31ms | # spent 2.30ms (2.06+239µs) within MARC::Record::BEGIN@14 which was called:
# once (2.06ms+239µs) by C4::Biblio::BEGIN@27 at line 14 # spent 2.30ms making 1 call to MARC::Record::BEGIN@14
# spent 5µs making 1 call to UNIVERSAL::import |
| 15 | 3 | 80µs | 2 | 111µs | # spent 62µs (14+49) within MARC::Record::BEGIN@15 which was called:
# once (14µs+49µs) by C4::Biblio::BEGIN@27 at line 15 # spent 62µs making 1 call to MARC::Record::BEGIN@15
# spent 48µs making 1 call to Exporter::import |
| 16 | |||||
| 17 | =head1 VERSION | ||||
| 18 | |||||
| - - | |||||
| 23 | 3 | 51µs | 2 | 119µs | # spent 71µs (23+48) within MARC::Record::BEGIN@23 which was called:
# once (23µs+48µs) by C4::Biblio::BEGIN@27 at line 23 # spent 71µs making 1 call to MARC::Record::BEGIN@23
# spent 48µs making 1 call to vars::import |
| 24 | 1 | 700ns | $VERSION = '2.0.2'; | ||
| 25 | |||||
| 26 | 3 | 35µs | 2 | 63µs | # spent 39µs (14+24) within MARC::Record::BEGIN@26 which was called:
# once (14µs+24µs) by C4::Biblio::BEGIN@27 at line 26 # spent 39µs making 1 call to MARC::Record::BEGIN@26
# spent 24µs making 1 call to Exporter::import |
| 27 | 3 | 63µs | 2 | 244µs | # spent 127µs (9+117) within MARC::Record::BEGIN@27 which was called:
# once (9µs+117µs) by C4::Biblio::BEGIN@27 at line 27 # spent 127µs making 1 call to MARC::Record::BEGIN@27
# spent 117µs making 1 call to vars::import |
| 28 | 1 | 13µs | @ISA = qw( Exporter ); | ||
| 29 | 1 | 400ns | @EXPORTS = qw(); | ||
| 30 | 1 | 700ns | @EXPORT_OK = qw( LEADER_LEN ); | ||
| 31 | |||||
| 32 | 4 | 50µs | 2 | 65µs | # spent 38µs (10+28) within MARC::Record::BEGIN@32 which was called:
# once (10µs+28µs) by C4::Biblio::BEGIN@27 at line 32 # spent 38µs making 1 call to MARC::Record::BEGIN@32
# spent 28µs making 1 call to vars::import |
| 33 | |||||
| 34 | 3 | 1.99ms | 2 | 160µs | # spent 87µs (15+72) within MARC::Record::BEGIN@34 which was called:
# once (15µs+72µs) by C4::Biblio::BEGIN@27 at line 34 # spent 87µs making 1 call to MARC::Record::BEGIN@34
# spent 72µs making 1 call to constant::import |
| 35 | |||||
| 36 | =head1 DESCRIPTION | ||||
| 37 | |||||
| - - | |||||
| 56 | # spent 1.10ms within MARC::Record::new which was called 75 times, avg 15µs/call:
# 25 times (460µs+0s) by MARC::File::USMARC::decode at line 119 of MARC/File/USMARC.pm, avg 18µs/call
# 25 times (402µs+0s) by C4::Biblio::GetMarcBiblio at line 1260 of /usr/share/koha/lib/C4/Biblio.pm, avg 16µs/call
# 25 times (239µs+0s) by MARC::File::SAX::start_element at line 51 of MARC/File/SAX.pm, avg 10µs/call | ||||
| 57 | 75 | 97µs | my $class = shift; | ||
| 58 | 75 | 494µs | my $self = { | ||
| 59 | _leader => ' ' x 24, | ||||
| 60 | _fields => [], | ||||
| 61 | _warnings => [], | ||||
| 62 | }; | ||||
| 63 | 75 | 619µs | 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 3.57ms within MARC::Record::fields which was called 596 times, avg 6µs/call:
# 471 times (2.26ms+0s) by MARC::Record::field at line 209, avg 5µs/call
# 25 times (435µs+0s) by C4::XSLT::transformMARCXML4XSLT at line 82 of /usr/share/koha/lib/C4/XSLT.pm, avg 17µs/call
# 25 times (299µs+0s) by MARC::File::XML::record at line 344 of MARC/File/XML.pm, avg 12µs/call
# 25 times (227µs+0s) by C4::Biblio::TransformMarcToKoha at line 2510 of /usr/share/koha/lib/C4/Biblio.pm, avg 9µs/call
# 25 times (180µs+0s) by C4::Charset::SetUTF8Flag at line 136 of /usr/share/koha/lib/C4/Charset.pm, avg 7µs/call
# 25 times (176µs+0s) by C4::Charset::SetUTF8Flag at line 135 of /usr/share/koha/lib/C4/Charset.pm, avg 7µs/call | ||||
| 178 | 596 | 517µs | my $self = shift; | ||
| 179 | 596 | 4.19ms | return @{$self->{_fields}}; | ||
| 180 | } | ||||
| 181 | |||||
| 182 | =head2 field( I<tagspec(s)> ) | ||||
| 183 | |||||
| - - | |||||
| 193 | 1 | 400ns | my %field_regex; | ||
| 194 | |||||
| 195 | # spent 96.8ms (57.8+38.9) within MARC::Record::field which was called 471 times, avg 205µs/call:
# 186 times (14.2ms+9.82ms) by MARC::Record::subfield at line 238, avg 129µs/call
# 50 times (9.39ms+6.46ms) by C4::XSLT::transformMARCXML4XSLT at line 87 of /usr/share/koha/lib/C4/XSLT.pm, avg 317µs/call
# 34 times (3.16ms+2.05ms) by C4::Biblio::GetCOinSBiblio at line 1402 of /usr/share/koha/lib/C4/Biblio.pm, avg 153µs/call
# 25 times (4.38ms+3.35ms) by C4::Koha::GetNormalizedUPC at line 1309 of /usr/share/koha/lib/C4/Koha.pm, avg 309µs/call
# 25 times (4.30ms+2.85ms) by C4::Search::searchResults at line 1786 of /usr/share/koha/lib/C4/Search.pm, avg 286µs/call
# 25 times (4.25ms+2.75ms) by C4::Search::searchResults at line 1777 of /usr/share/koha/lib/C4/Search.pm, avg 280µs/call
# 25 times (4.21ms+2.54ms) by C4::Koha::GetNormalizedEAN at line 1371 of /usr/share/koha/lib/C4/Koha.pm, avg 270µs/call
# 25 times (3.94ms+2.56ms) by C4::Koha::GetNormalizedISBN at line 1345 of /usr/share/koha/lib/C4/Koha.pm, avg 260µs/call
# 25 times (4.03ms+2.41ms) by C4::Koha::GetNormalizedOCLCNumber at line 1389 of /usr/share/koha/lib/C4/Koha.pm, avg 258µs/call
# 25 times (3.48ms+2.37ms) by C4::Biblio::_koha_marc_update_bib_ids at line 2861 of /usr/share/koha/lib/C4/Biblio.pm, avg 234µs/call
# 25 times (2.35ms+1.66ms) by C4::Biblio::GetCOinSBiblio at line 1397 of /usr/share/koha/lib/C4/Biblio.pm, avg 160µs/call
# once (136µs+107µs) by C4::Biblio::GetCOinSBiblio at line 1411 of /usr/share/koha/lib/C4/Biblio.pm | ||||
| 196 | 471 | 356µs | my $self = shift; | ||
| 197 | 471 | 566µs | my @specs = @_; | ||
| 198 | |||||
| 199 | 471 | 230µs | my @list = (); | ||
| 200 | 471 | 573µs | for my $tag ( @specs ) { | ||
| 201 | 471 | 553µs | my $regex = $field_regex{ $tag }; | ||
| 202 | |||||
| 203 | # Compile & stash it if necessary | ||||
| 204 | 471 | 237µs | if ( not defined $regex ) { | ||
| 205 | 13 | 334µs | 26 | 236µs | $regex = qr/^$tag$/; # spent 177µs making 13 calls to MARC::Record::CORE:regcomp, avg 14µs/call
# spent 59µs making 13 calls to MARC::Record::CORE:qr, avg 5µs/call |
| 206 | 13 | 32µs | $field_regex{ $tag } = $regex; | ||
| 207 | } # not defined | ||||
| 208 | |||||
| 209 | 471 | 1.87ms | 471 | 2.26ms | for my $maybe ( $self->fields ) { # spent 2.26ms making 471 calls to MARC::Record::fields, avg 5µs/call |
| 210 | 7827 | 59.4ms | 23481 | 36.4ms | if ( $maybe->tag =~ $regex ) { # spent 22.0ms making 7827 calls to MARC::Field::tag, avg 3µs/call
# spent 8.24ms making 7827 calls to MARC::Record::CORE:regcomp, avg 1µs/call
# spent 6.22ms making 7827 calls to MARC::Record::CORE:match, avg 795ns/call |
| 211 | 342 | 851µs | return $maybe unless wantarray; | ||
| 212 | |||||
| 213 | 143 | 166µs | push( @list, $maybe ); | ||
| 214 | } # if | ||||
| 215 | } # for $maybe | ||||
| 216 | } # for $tag | ||||
| 217 | |||||
| 218 | 272 | 286µs | return unless wantarray; | ||
| 219 | 200 | 834µs | return @list; | ||
| 220 | } | ||||
| 221 | |||||
| 222 | =head2 subfield( $tag, $subfield ) | ||||
| 223 | |||||
| - - | |||||
| 233 | # spent 28.1ms (1.71+26.4) within MARC::Record::subfield which was called 186 times, avg 151µs/call:
# 25 times (385µs+6.93ms) by C4::Search::searchResults at line 1702 of /usr/share/koha/lib/C4/Search.pm, avg 293µs/call
# 25 times (240µs+2.02ms) by C4::Biblio::GetCOinSBiblio at line 1407 of /usr/share/koha/lib/C4/Biblio.pm, avg 90µs/call
# 25 times (228µs+1.92ms) by C4::Biblio::GetCOinSBiblio at line 1408 of /usr/share/koha/lib/C4/Biblio.pm, avg 86µs/call
# 24 times (110µs+5.41ms) by C4::Biblio::GetCOinSBiblio at line 1429 of /usr/share/koha/lib/C4/Biblio.pm, avg 230µs/call
# 24 times (143µs+4.25ms) by C4::Biblio::GetCOinSBiblio at line 1430 of /usr/share/koha/lib/C4/Biblio.pm, avg 183µs/call
# 24 times (195µs+2.22ms) by C4::Biblio::GetCOinSBiblio at line 1427 of /usr/share/koha/lib/C4/Biblio.pm, avg 101µs/call
# 24 times (256µs+2.14ms) by C4::Biblio::GetCOinSBiblio at line 1428 of /usr/share/koha/lib/C4/Biblio.pm, avg 100µs/call
# 11 times (128µs+790µs) by C4::Biblio::GetCOinSBiblio at line 1397 of /usr/share/koha/lib/C4/Biblio.pm, avg 83µs/call
# once (7µs+217µs) by C4::Biblio::GetCOinSBiblio at line 1420 of /usr/share/koha/lib/C4/Biblio.pm
# once (8µs+180µs) by C4::Biblio::GetCOinSBiblio at line 1413 of /usr/share/koha/lib/C4/Biblio.pm
# once (7µs+179µs) by C4::Biblio::GetCOinSBiblio at line 1415 of /usr/share/koha/lib/C4/Biblio.pm
# once (7µs+179µs) by C4::Biblio::GetCOinSBiblio at line 1414 of /usr/share/koha/lib/C4/Biblio.pm | ||||
| 234 | 186 | 118µs | my $self = shift; | ||
| 235 | 186 | 96µs | my $tag = shift; | ||
| 236 | 186 | 118µs | my $subfield = shift; | ||
| 237 | |||||
| 238 | 186 | 602µs | 186 | 24.0ms | my $field = $self->field($tag) or return; # spent 24.0ms making 186 calls to MARC::Record::field, avg 129µs/call |
| 239 | 145 | 732µs | 145 | 2.40ms | return $field->subfield($subfield); # spent 2.40ms making 145 calls to MARC::Field::subfield, avg 17µs/call |
| 240 | } # subfield() | ||||
| 241 | |||||
| 242 | =for internal | ||||
| 243 | |||||
| - - | |||||
| 246 | # spent 9.46ms (7.54+1.91) within MARC::Record::_all_parms_are_fields which was called 1131 times, avg 8µs/call:
# 1081 times (7.26ms+1.85ms) by MARC::Record::append_fields at line 268, avg 8µs/call
# 25 times (153µs+42µs) by MARC::Record::delete_fields at line 438, avg 8µs/call
# 25 times (125µs+27µs) by MARC::Record::insert_fields_ordered at line 358, avg 6µs/call | ||||
| 247 | 1131 | 1.48ms | for ( @_ ) { | ||
| 248 | 1131 | 6.14ms | 1131 | 1.91ms | return 0 unless UNIVERSAL::isa($_, 'MARC::Field'); # spent 1.91ms making 1131 calls to UNIVERSAL::isa, avg 2µs/call |
| 249 | } | ||||
| 250 | 1131 | 2.78ms | return 1; | ||
| 251 | } | ||||
| 252 | |||||
| 253 | =head2 append_fields( @fields ) | ||||
| 254 | |||||
| - - | |||||
| 265 | # spent 16.4ms (7.24+9.11) within MARC::Record::append_fields which was called 1081 times, avg 15µs/call:
# 512 times (3.39ms+4.17ms) by MARC::File::USMARC::decode at line 226 of MARC/File/USMARC.pm, avg 15µs/call
# 480 times (3.06ms+3.94ms) by MARC::File::SAX::end_element at line 92 of MARC/File/SAX.pm, avg 15µs/call
# 32 times (381µs+431µs) by MARC::File::USMARC::decode at line 192 of MARC/File/USMARC.pm, avg 25µs/call
# 32 times (277µs+408µs) by MARC::File::SAX::end_element at line 83 of MARC/File/SAX.pm, avg 21µs/call
# 25 times (131µs+162µs) by MARC::Record::insert_fields_ordered at line 374, avg 12µs/call | ||||
| 266 | 1081 | 574µs | my $self = shift; | ||
| 267 | |||||
| 268 | 1081 | 2.04ms | 1081 | 9.11ms | _all_parms_are_fields(@_) or croak('Arguments must be MARC::Field objects'); # spent 9.11ms making 1081 calls to MARC::Record::_all_parms_are_fields, avg 8µs/call |
| 269 | |||||
| 270 | 1081 | 1.66ms | push(@{ $self->{_fields} }, @_); | ||
| 271 | 1081 | 2.67ms | 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 | my $found = 0; | ||||
| 331 | foreach my $f (@$fields) { | ||||
| 332 | if ($f == $after) { | ||||
| 333 | $found = 1; | ||||
| 334 | last; | ||||
| 335 | } | ||||
| 336 | $pos++; | ||||
| 337 | } | ||||
| 338 | |||||
| 339 | ## insert after $after | ||||
| 340 | unless ($found) { | ||||
| 341 | $self->_warn("Couldn't find field to insert after"); | ||||
| 342 | return; | ||||
| 343 | } | ||||
| 344 | splice(@$fields,$pos+1,0,@new); | ||||
| 345 | return scalar @new; | ||||
| 346 | } | ||||
| 347 | |||||
| 348 | =head2 insert_fields_ordered( @new_fields ) | ||||
| 349 | |||||
| - - | |||||
| 355 | # spent 4.87ms (2.67+2.20) within MARC::Record::insert_fields_ordered which was called 25 times, avg 195µs/call:
# 25 times (2.67ms+2.20ms) by C4::Biblio::_koha_marc_update_bib_ids at line 2863 of /usr/share/koha/lib/C4/Biblio.pm, avg 195µs/call | ||||
| 356 | 25 | 43µs | my ( $self, @new ) = @_; | ||
| 357 | |||||
| 358 | 25 | 46µs | 25 | 151µs | _all_parms_are_fields(@new) # spent 151µs making 25 calls to MARC::Record::_all_parms_are_fields, avg 6µs/call |
| 359 | or croak('All arguments must be MARC::Field objects'); | ||||
| 360 | |||||
| 361 | ## go through each new field | ||||
| 362 | 25 | 40µs | NEW_FIELD: foreach my $newField ( @new ) { | ||
| 363 | |||||
| 364 | ## find location before which it should be inserted | ||||
| 365 | 25 | 44µs | EXISTING_FIELD: foreach my $field ( @{ $self->{_fields} } ) { | ||
| 366 | 487 | 1.58ms | 974 | 1.75ms | if ( $field->tag() >= $newField->tag() ) { # spent 1.75ms making 974 calls to MARC::Field::tag, avg 2µs/call |
| 367 | $self->insert_fields_before( $field, $newField ); | ||||
| 368 | next NEW_FIELD; | ||||
| 369 | } | ||||
| 370 | } | ||||
| 371 | |||||
| 372 | ## if we fell through then this new field is higher than | ||||
| 373 | ## all the existing fields, so we append. | ||||
| 374 | 25 | 73µs | 25 | 292µs | $self->append_fields( $newField ); # spent 292µs making 25 calls to MARC::Record::append_fields, avg 12µs/call |
| 375 | |||||
| 376 | } | ||||
| 377 | 25 | 88µs | return( scalar( @new ) ); | ||
| 378 | } | ||||
| 379 | |||||
| 380 | =head2 insert_grouped_field( $field ) | ||||
| 381 | |||||
| - - | |||||
| 398 | sub insert_grouped_field { | ||||
| 399 | my ($self,$new) = @_; | ||||
| 400 | _all_parms_are_fields($new) or croak('Argument must be MARC::Field object'); | ||||
| 401 | |||||
| 402 | ## try to find the end of the field group and insert it there | ||||
| 403 | my $limit = int($new->tag() / 100); | ||||
| 404 | my $found = 0; | ||||
| 405 | foreach my $field ($self->fields()) { | ||||
| 406 | if ( int($field->tag() / 100) > $limit ) { | ||||
| 407 | $self->insert_fields_before($field,$new); | ||||
| 408 | $found = 1; | ||||
| 409 | last; | ||||
| 410 | } | ||||
| 411 | } | ||||
| 412 | |||||
| 413 | ## if we couldn't find the end of the group, then we must not have | ||||
| 414 | ## any tags this high yet, so just append it | ||||
| 415 | if (!$found) { | ||||
| 416 | $self->append_fields($new); | ||||
| 417 | } | ||||
| 418 | |||||
| 419 | return(1); | ||||
| 420 | |||||
| 421 | } | ||||
| 422 | |||||
| 423 | |||||
| 424 | =head2 delete_fields( $field ) | ||||
| 425 | |||||
| - - | |||||
| 436 | # spent 809µs (615+195) within MARC::Record::delete_fields which was called 25 times, avg 32µs/call:
# 25 times (615µs+195µs) by MARC::Record::delete_field at line 458, avg 32µs/call | ||||
| 437 | 25 | 21µs | my $self = shift; | ||
| 438 | 25 | 60µs | 25 | 195µs | _all_parms_are_fields(@_) or croak('Arguments must be MARC::Field object'); # spent 195µs making 25 calls to MARC::Record::_all_parms_are_fields, avg 8µs/call |
| 439 | 25 | 91µs | my @fields = @{$self->{_fields}}; | ||
| 440 | 25 | 20µs | my $original_count = @fields; | ||
| 441 | |||||
| 442 | 25 | 35µs | foreach my $deleter (@_) { | ||
| 443 | 25 | 185µs | @fields = grep { $_ != $deleter } @fields; | ||
| 444 | } | ||||
| 445 | 25 | 55µs | $self->{_fields} = \@fields; | ||
| 446 | |||||
| 447 | 25 | 145µs | return $original_count - @fields; | ||
| 448 | } | ||||
| 449 | |||||
| 450 | =head2 delete_field() | ||||
| 451 | |||||
| - - | |||||
| 457 | # spent 964µs (155+810) within MARC::Record::delete_field which was called 25 times, avg 39µs/call:
# 25 times (155µs+810µs) by C4::Biblio::_koha_marc_update_bib_ids at line 2862 of /usr/share/koha/lib/C4/Biblio.pm, avg 39µs/call | ||||
| 458 | 25 | 144µs | 25 | 809µs | return delete_fields(@_); # spent 809µs making 25 calls to MARC::Record::delete_fields, avg 32µs/call |
| 459 | } | ||||
| 460 | |||||
| 461 | =head2 as_usmarc() | ||||
| 462 | |||||
| - - | |||||
| 468 | sub as_usmarc() { | ||||
| 469 | my $self = shift; | ||||
| 470 | |||||
| 471 | require MARC::File::USMARC; | ||||
| 472 | |||||
| 473 | return MARC::File::USMARC::encode( $self ); | ||||
| 474 | } | ||||
| 475 | |||||
| 476 | =head2 as_formatted() | ||||
| 477 | |||||
| - - | |||||
| 482 | sub as_formatted() { | ||||
| 483 | my $self = shift; | ||||
| 484 | |||||
| 485 | my @lines = ( "LDR " . ($self->{_leader} || "") ); | ||||
| 486 | for my $field ( @{$self->{_fields}} ) { | ||||
| 487 | push( @lines, $field->as_formatted() ); | ||||
| 488 | } | ||||
| 489 | |||||
| 490 | return join( "\n", @lines ); | ||||
| 491 | } # as_formatted | ||||
| 492 | |||||
| 493 | |||||
| 494 | =head2 leader() | ||||
| 495 | |||||
| - - | |||||
| 501 | # spent 2.87ms within MARC::Record::leader which was called 694 times, avg 4µs/call:
# 544 times (1.79ms+0s) by MARC::Record::encoding at line 538, avg 3µs/call
# 25 times (286µs+0s) by MARC::File::USMARC::decode at line 133 of MARC/File/USMARC.pm, avg 11µs/call
# 25 times (231µs+0s) by MARC::File::SAX::end_element at line 108 of MARC/File/SAX.pm, avg 9µs/call
# 25 times (209µs+0s) by C4::Biblio::GetCOinSBiblio at line 1309 of /usr/share/koha/lib/C4/Biblio.pm, avg 8µs/call
# 25 times (207µs+0s) by MARC::File::XML::record at line 316 of MARC/File/XML.pm, avg 8µs/call
# 25 times (79µs+0s) by MARC::File::XML::record at line 342 of MARC/File/XML.pm, avg 3µs/call
# 25 times (65µs+0s) by C4::Biblio::GetCOinSBiblio at line 1310 of /usr/share/koha/lib/C4/Biblio.pm, avg 3µs/call | ||||
| 502 | 694 | 365µs | my $self = shift; | ||
| 503 | 694 | 375µs | my $text = shift; | ||
| 504 | |||||
| 505 | 694 | 297µs | if ( defined $text ) { | ||
| 506 | 50 | 90µs | (length($text) eq 24) | ||
| 507 | or $self->_warn( "Leader must be 24 bytes long" ); | ||||
| 508 | 50 | 84µs | $self->{_leader} = $text; | ||
| 509 | } # set the leader | ||||
| 510 | |||||
| 511 | 694 | 2.49ms | return $self->{_leader}; | ||
| 512 | } # leader() | ||||
| 513 | |||||
| 514 | =head2 encoding() | ||||
| 515 | |||||
| - - | |||||
| 535 | # spent 5.37ms (3.57+1.79) within MARC::Record::encoding which was called 544 times, avg 10µs/call:
# 544 times (3.57ms+1.79ms) by MARC::File::USMARC::decode at line 171 of MARC/File/USMARC.pm, avg 10µs/call | ||||
| 536 | 544 | 403µs | my ($self,$arg) = @_; | ||
| 537 | # we basically report from and modify the leader directly | ||||
| 538 | 544 | 1.01ms | 544 | 1.79ms | my $leader = $self->leader(); # spent 1.79ms making 544 calls to MARC::Record::leader, avg 3µs/call |
| 539 | |||||
| 540 | # when setting | ||||
| 541 | 544 | 165µs | if ( defined($arg) ) { | ||
| 542 | if ( $arg =~ /UTF-?8/i ) { | ||||
| 543 | substr($leader,9,1) = 'a'; | ||||
| 544 | } | ||||
| 545 | elsif ( $arg =~ /MARC-?8/i ) { | ||||
| 546 | substr($leader,9,1) = ' '; | ||||
| 547 | } | ||||
| 548 | $self->leader($leader); | ||||
| 549 | } | ||||
| 550 | |||||
| 551 | 544 | 1.79ms | return substr($leader,9,1) eq 'a' ? 'UTF-8' : 'MARC-8'; | ||
| 552 | } | ||||
| 553 | |||||
| 554 | =head2 set_leader_lengths( $reclen, $baseaddr ) | ||||
| 555 | |||||
| - - | |||||
| 560 | sub set_leader_lengths { | ||||
| 561 | my $self = shift; | ||||
| 562 | my $reclen = shift; | ||||
| 563 | my $baseaddr = shift; | ||||
| 564 | if ($reclen > 99999) { | ||||
| 565 | carp( "Record length of $reclen is larger than the MARC spec allows (99999 bytes)." ); | ||||
| 566 | } | ||||
| 567 | substr($self->{_leader},0,5) = sprintf("%05d",$reclen); | ||||
| 568 | substr($self->{_leader},12,5) = sprintf("%05d",$baseaddr); | ||||
| 569 | # MARC21 defaults: http://www.loc.gov/marc/bibliographic/ecbdldrd.html | ||||
| 570 | substr($self->{_leader},10,2) = '22'; | ||||
| 571 | substr($self->{_leader},20,4) = '4500'; | ||||
| 572 | } | ||||
| 573 | |||||
| 574 | =head2 clone() | ||||
| 575 | |||||
| - - | |||||
| 596 | sub clone { | ||||
| 597 | my $self = shift; | ||||
| 598 | my @keeper_tags = @_; | ||||
| 599 | |||||
| 600 | # create a new object of whatever type we happen to be | ||||
| 601 | my $class = ref( $self ); | ||||
| 602 | my $clone = $class->new(); | ||||
| 603 | |||||
| 604 | $clone->{_leader} = $self->{_leader}; | ||||
| 605 | |||||
| 606 | my $filtered = @keeper_tags ? [$self->field( @keeper_tags )] : undef; | ||||
| 607 | |||||
| 608 | for my $field ( $self->fields() ) { | ||||
| 609 | if ( !$filtered || (grep {$field eq $_} @$filtered ) ) { | ||||
| 610 | $clone->append_fields( $field->clone ); | ||||
| 611 | } | ||||
| 612 | } | ||||
| 613 | |||||
| 614 | # XXX FIX THIS $clone->update_leader(); | ||||
| 615 | |||||
| 616 | return $clone; | ||||
| 617 | } | ||||
| 618 | |||||
| 619 | =head2 warnings() | ||||
| 620 | |||||
| - - | |||||
| 635 | sub warnings() { | ||||
| 636 | my $self = shift; | ||||
| 637 | my @warnings = @{$self->{_warnings}}; | ||||
| 638 | $self->{_warnings} = []; | ||||
| 639 | return @warnings; | ||||
| 640 | } | ||||
| 641 | |||||
| 642 | =head2 add_fields() | ||||
| 643 | |||||
| - - | |||||
| 682 | sub add_fields { | ||||
| 683 | my $self = shift; | ||||
| 684 | |||||
| 685 | my $nfields = 0; | ||||
| 686 | my $fields = $self->{_fields}; | ||||
| 687 | |||||
| 688 | while ( my $parm = shift ) { | ||||
| 689 | # User handed us a list of data (most common possibility) | ||||
| 690 | if ( ref($parm) eq "" ) { | ||||
| 691 | my $field = MARC::Field->new( $parm, @_ ) | ||||
| 692 | or return _gripe( $MARC::Field::ERROR ); | ||||
| 693 | push( @$fields, $field ); | ||||
| 694 | ++$nfields; | ||||
| 695 | last; # Bail out, we're done eating parms | ||||
| 696 | |||||
| 697 | # User handed us an object. | ||||
| 698 | } elsif ( UNIVERSAL::isa($parm, 'MARC::Field') ) { | ||||
| 699 | push( @$fields, $parm ); | ||||
| 700 | ++$nfields; | ||||
| 701 | |||||
| 702 | # User handed us an anonymous list of parms | ||||
| 703 | } elsif ( ref($parm) eq "ARRAY" ) { | ||||
| 704 | my $field = MARC::Field->new(@$parm) | ||||
| 705 | or return _gripe( $MARC::Field::ERROR ); | ||||
| 706 | push( @$fields, $field ); | ||||
| 707 | ++$nfields; | ||||
| 708 | |||||
| 709 | } else { | ||||
| 710 | croak( "Unknown parm of type", ref($parm), " passed to add_fields()" ); | ||||
| 711 | } # if | ||||
| 712 | |||||
| 713 | } # while | ||||
| 714 | |||||
| 715 | return $nfields; | ||||
| 716 | } | ||||
| 717 | |||||
| 718 | # NOTE: _warn is an object method | ||||
| 719 | sub _warn { | ||||
| 720 | my $self = shift; | ||||
| 721 | push( @{$self->{_warnings}}, join( "", @_ ) ); | ||||
| 722 | return( $self ); | ||||
| 723 | } | ||||
| 724 | |||||
| 725 | |||||
| 726 | # NOTE: _gripe is NOT an object method | ||||
| 727 | sub _gripe { | ||||
| 728 | $ERROR = join( "", @_ ); | ||||
| 729 | |||||
| 730 | warn $ERROR; | ||||
| 731 | |||||
| 732 | return; | ||||
| 733 | } | ||||
| 734 | |||||
| 735 | |||||
| 736 | 1 | 6µs | 1; | ||
| 737 | |||||
| 738 | __END__ | ||||
# spent 6.22ms within MARC::Record::CORE:match which was called 7827 times, avg 795ns/call:
# 7827 times (6.22ms+0s) by MARC::Record::field at line 210, avg 795ns/call | |||||
# spent 59µs within MARC::Record::CORE:qr which was called 13 times, avg 5µs/call:
# 13 times (59µs+0s) by MARC::Record::field at line 205, avg 5µs/call | |||||
sub MARC::Record::CORE:regcomp; # opcode |