| Filename | /usr/share/perl5/MARC/Charset/Table.pm |
| Statements | Executed 32 statements in 1.28ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 885µs | 4.30ms | MARC::Charset::Table::BEGIN@38 |
| 1 | 1 | 1 | 581µs | 1.40ms | MARC::Charset::Table::BEGIN@37 |
| 1 | 1 | 1 | 41µs | 245µs | MARC::Charset::Table::new |
| 1 | 1 | 1 | 22µs | 4.86ms | MARC::Charset::Table::BEGIN@36 |
| 1 | 1 | 1 | 22µs | 122µs | MARC::Charset::Table::_init |
| 1 | 1 | 1 | 22µs | 27µs | MARC::Charset::Table::BEGIN@34 |
| 1 | 1 | 1 | 20µs | 77µs | MARC::Charset::Table::BEGIN@40 |
| 1 | 1 | 1 | 17µs | 40µs | MARC::Charset::Table::BEGIN@35 |
| 1 | 1 | 1 | 13µs | 306µs | MARC::Charset::Table::BEGIN@39 |
| 1 | 1 | 1 | 12µs | 16µs | MARC::Charset::Table::db_path |
| 1 | 1 | 1 | 4µs | 4µs | MARC::Charset::Table::CORE:subst (opcode) |
| 0 | 0 | 0 | 0s | 0s | MARC::Charset::Table::add_code |
| 0 | 0 | 0 | 0s | 0s | MARC::Charset::Table::brand_new |
| 0 | 0 | 0 | 0s | 0s | MARC::Charset::Table::db |
| 0 | 0 | 0 | 0s | 0s | MARC::Charset::Table::get_code |
| 0 | 0 | 0 | 0s | 0s | MARC::Charset::Table::lookup_by_marc8 |
| 0 | 0 | 0 | 0s | 0s | MARC::Charset::Table::lookup_by_utf8 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package MARC::Charset::Table; | ||||
| 2 | |||||
| 3 | =head1 NAME | ||||
| 4 | |||||
| - - | |||||
| 34 | 3 | 35µs | 2 | 32µs | # spent 27µs (22+5) within MARC::Charset::Table::BEGIN@34 which was called:
# once (22µs+5µs) by MARC::Charset::BEGIN@13 at line 34 # spent 27µs making 1 call to MARC::Charset::Table::BEGIN@34
# spent 5µs making 1 call to strict::import |
| 35 | 3 | 36µs | 2 | 63µs | # spent 40µs (17+23) within MARC::Charset::Table::BEGIN@35 which was called:
# once (17µs+23µs) by MARC::Charset::BEGIN@13 at line 35 # spent 40µs making 1 call to MARC::Charset::Table::BEGIN@35
# spent 23µs making 1 call to warnings::import |
| 36 | 3 | 88µs | 2 | 9.69ms | # spent 4.86ms (22µs+4.84) within MARC::Charset::Table::BEGIN@36 which was called:
# once (22µs+4.84ms) by MARC::Charset::BEGIN@13 at line 36 # spent 4.86ms making 1 call to MARC::Charset::Table::BEGIN@36
# spent 4.84ms making 1 call to POSIX::import |
| 37 | 3 | 209µs | 2 | 1.60ms | # spent 1.40ms (581µs+818µs) within MARC::Charset::Table::BEGIN@37 which was called:
# once (581µs+818µs) by MARC::Charset::BEGIN@13 at line 37 # spent 1.40ms making 1 call to MARC::Charset::Table::BEGIN@37
# spent 196µs making 1 call to Exporter::import |
| 38 | 3 | 146µs | 2 | 4.31ms | # spent 4.30ms (885µs+3.41) within MARC::Charset::Table::BEGIN@38 which was called:
# once (885µs+3.41ms) by MARC::Charset::BEGIN@13 at line 38 # spent 4.30ms making 1 call to MARC::Charset::Table::BEGIN@38
# spent 9µs making 1 call to Class::Accessor::import |
| 39 | 3 | 40µs | 2 | 599µs | # spent 306µs (13+293) within MARC::Charset::Table::BEGIN@39 which was called:
# once (13µs+293µs) by MARC::Charset::BEGIN@13 at line 39 # spent 306µs making 1 call to MARC::Charset::Table::BEGIN@39
# spent 293µs making 1 call to Exporter::import |
| 40 | 3 | 556µs | 2 | 135µs | # spent 77µs (20+57) within MARC::Charset::Table::BEGIN@40 which was called:
# once (20µs+57µs) by MARC::Charset::BEGIN@13 at line 40 # spent 77µs making 1 call to MARC::Charset::Table::BEGIN@40
# spent 57µs making 1 call to Exporter::import |
| 41 | |||||
| 42 | =head2 new() | ||||
| 43 | |||||
| - - | |||||
| 48 | sub new | ||||
| 49 | # spent 245µs (41+203) within MARC::Charset::Table::new which was called:
# once (41µs+203µs) by MARC::File::SAX::BEGIN@14 at line 44 of MARC/Charset.pm | ||||
| 50 | 1 | 3µs | my $class = shift; | ||
| 51 | 1 | 20µs | my $self = bless {}, ref($class) || $class; | ||
| 52 | 1 | 10µs | 2 | 195µs | $self->_init(&GDBM_READER); # spent 122µs making 1 call to MARC::Charset::Table::_init
# spent 73µs making 1 call to GDBM_File::AUTOLOAD |
| 53 | 1 | 5µs | return $self; | ||
| 54 | } | ||||
| 55 | |||||
| 56 | |||||
| 57 | =head2 add_code() | ||||
| 58 | |||||
| - - | |||||
| 64 | sub add_code | ||||
| 65 | { | ||||
| 66 | my ($self, $code) = @_; | ||||
| 67 | |||||
| 68 | # the Code object is serialized | ||||
| 69 | my $frozen = nfreeze($code); | ||||
| 70 | |||||
| 71 | # to support lookup by marc8 and utf8 values we | ||||
| 72 | # stash away the rule in the db using two keys | ||||
| 73 | my $marc8_key = $code->marc8_hash_code(); | ||||
| 74 | my $utf8_key = $code->utf8_hash_code(); | ||||
| 75 | |||||
| 76 | # stash away the marc8 lookup key | ||||
| 77 | $self->{db}->{$marc8_key} = $frozen; | ||||
| 78 | |||||
| 79 | # stash away the utf8 lookup key (only if it's not already there!) | ||||
| 80 | # this means that the sets that appear in the xml file will have | ||||
| 81 | # precedence ascii/ansel | ||||
| 82 | $self->{db}->{$utf8_key} = $frozen unless exists $self->{db}->{$utf8_key}; | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | |||||
| 86 | =head2 get_code() | ||||
| 87 | |||||
| - - | |||||
| 92 | sub get_code | ||||
| 93 | { | ||||
| 94 | my ($self, $key) = @_; | ||||
| 95 | my $db = $self->db(); | ||||
| 96 | my $frozen = $db->{$key}; | ||||
| 97 | return thaw($frozen) if $frozen; | ||||
| 98 | return undef; | ||||
| 99 | } | ||||
| 100 | |||||
| 101 | |||||
| 102 | =head2 lookup_by_marc8() | ||||
| 103 | |||||
| - - | |||||
| 112 | sub lookup_by_marc8 | ||||
| 113 | { | ||||
| 114 | my ($self, $charset, $marc8) = @_; | ||||
| 115 | $charset = BASIC_LATIN if $charset eq ASCII_DEFAULT; | ||||
| 116 | return $self->get_code(sprintf('%s:%s', $charset, $marc8)); | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | |||||
| 120 | =head2 lookup_by_utf8() | ||||
| 121 | |||||
| - - | |||||
| 126 | sub lookup_by_utf8 | ||||
| 127 | { | ||||
| 128 | my ($self, $value) = @_; | ||||
| 129 | return $self->get_code(ord($value)); | ||||
| 130 | } | ||||
| 131 | |||||
| - - | |||||
| 135 | =head2 db() | ||||
| 136 | |||||
| - - | |||||
| 142 | sub db | ||||
| 143 | { | ||||
| 144 | return shift->{db}; | ||||
| 145 | } | ||||
| 146 | |||||
| 147 | |||||
| 148 | =head2 db_path() | ||||
| 149 | |||||
| - - | |||||
| 157 | sub db_path | ||||
| 158 | # spent 16µs (12+4) within MARC::Charset::Table::db_path which was called:
# once (12µs+4µs) by MARC::Charset::Table::_init at line 187 | ||||
| 159 | 1 | 2µs | my $path = $INC{'MARC/Charset/Table.pm'}; | ||
| 160 | 1 | 11µs | 1 | 4µs | $path =~ s/\.pm$//; # spent 4µs making 1 call to MARC::Charset::Table::CORE:subst |
| 161 | 1 | 4µs | return $path; | ||
| 162 | } | ||||
| 163 | |||||
| 164 | |||||
| 165 | =head2 brand_new() | ||||
| 166 | |||||
| - - | |||||
| 173 | sub brand_new | ||||
| 174 | { | ||||
| 175 | my $class = shift; | ||||
| 176 | my $self = bless {}, ref($class) || $class; | ||||
| 177 | $self->_init(&GDBM_WRCREAT); | ||||
| 178 | return $self; | ||||
| 179 | } | ||||
| 180 | |||||
| 181 | |||||
| 182 | # helper function for initializing table internals | ||||
| 183 | |||||
| 184 | sub _init | ||||
| 185 | # spent 122µs (22+100) within MARC::Charset::Table::_init which was called:
# once (22µs+100µs) by MARC::Charset::Table::new at line 52 | ||||
| 186 | 1 | 1µs | my ($self,$opts) = @_; | ||
| 187 | 1 | 100µs | 2 | 100µs | tie my %db, 'GDBM_File', db_path(), $opts, 0644; # spent 84µs making 1 call to GDBM_File::TIEHASH
# spent 16µs making 1 call to MARC::Charset::Table::db_path |
| 188 | 1 | 7µs | $self->{db} = \%db; | ||
| 189 | } | ||||
| 190 | |||||
| - - | |||||
| 195 | 1 | 9µs | 1; | ||
# spent 4µs within MARC::Charset::Table::CORE:subst which was called:
# once (4µs+0s) by MARC::Charset::Table::db_path at line 160 |