| Filename | /usr/share/perl5/MARC/File.pm |
| Statements | Executed 13 statements in 868µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 24µs | 30µs | MARC::File::BEGIN@10 |
| 1 | 1 | 1 | 24µs | 30µs | MARC::File::BEGIN@9 |
| 1 | 1 | 1 | 19µs | 27µs | MARC::File::BEGIN@61 |
| 1 | 1 | 1 | 18µs | 73µs | MARC::File::BEGIN@12 |
| 0 | 0 | 0 | 0s | 0s | MARC::File::_gripe |
| 0 | 0 | 0 | 0s | 0s | MARC::File::_unimplemented |
| 0 | 0 | 0 | 0s | 0s | MARC::File::_warn |
| 0 | 0 | 0 | 0s | 0s | MARC::File::close |
| 0 | 0 | 0 | 0s | 0s | MARC::File::decode |
| 0 | 0 | 0 | 0s | 0s | MARC::File::in |
| 0 | 0 | 0 | 0s | 0s | MARC::File::next |
| 0 | 0 | 0 | 0s | 0s | MARC::File::out |
| 0 | 0 | 0 | 0s | 0s | MARC::File::skip |
| 0 | 0 | 0 | 0s | 0s | MARC::File::warnings |
| 0 | 0 | 0 | 0s | 0s | MARC::File::write |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package MARC::File; | ||||
| 2 | |||||
| 3 | =head1 NAME | ||||
| 4 | |||||
| - - | |||||
| 9 | 3 | 57µs | 2 | 35µs | # spent 30µs (24+6) within MARC::File::BEGIN@9 which was called:
# once (24µs+6µs) by MARC::File::USMARC::BEGIN@15 at line 9 # spent 30µs making 1 call to MARC::File::BEGIN@9
# spent 6µs making 1 call to strict::import |
| 10 | 3 | 62µs | 2 | 36µs | # spent 30µs (24+6) within MARC::File::BEGIN@10 which was called:
# once (24µs+6µs) by MARC::File::USMARC::BEGIN@15 at line 10 # spent 30µs making 1 call to MARC::File::BEGIN@10
# spent 6µs making 1 call to integer::import |
| 11 | |||||
| 12 | 3 | 102µs | 2 | 129µs | # spent 73µs (18+55) within MARC::File::BEGIN@12 which was called:
# once (18µs+55µs) by MARC::File::USMARC::BEGIN@15 at line 12 # spent 73µs making 1 call to MARC::File::BEGIN@12
# spent 56µs making 1 call to vars::import |
| 13 | |||||
| 14 | =head1 SYNOPSIS | ||||
| 15 | |||||
| - - | |||||
| 55 | sub in { | ||||
| 56 | my $class = shift; | ||||
| 57 | my $arg = shift; | ||||
| 58 | my ( $filename, $fh ); | ||||
| 59 | |||||
| 60 | ## if a valid filehandle was passed in | ||||
| 61 | 3 | 643µs | 2 | 35µs | # spent 27µs (19+8) within MARC::File::BEGIN@61 which was called:
# once (19µs+8µs) by MARC::File::USMARC::BEGIN@15 at line 61 # spent 27µs making 1 call to MARC::File::BEGIN@61
# spent 8µs making 1 call to strict::unimport |
| 62 | if ( $ishandle ) { | ||||
| 63 | $filename = scalar( $arg ); | ||||
| 64 | $fh = $arg; | ||||
| 65 | } | ||||
| 66 | |||||
| 67 | ## otherwise check if it's a filename, and | ||||
| 68 | ## return undef if we weren't able to open it | ||||
| 69 | else { | ||||
| 70 | $filename = $arg; | ||||
| 71 | $fh = eval { local *FH; open( FH, $arg ) or die; *FH{IO}; }; | ||||
| 72 | if ( $@ ) { | ||||
| 73 | $MARC::File::ERROR = "Couldn't open $filename: $@"; | ||||
| 74 | return; | ||||
| 75 | } | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | my $self = { | ||||
| 79 | filename => $filename, | ||||
| 80 | fh => $fh, | ||||
| 81 | recnum => 0, | ||||
| 82 | warnings => [], | ||||
| 83 | }; | ||||
| 84 | |||||
| 85 | return( bless $self, $class ); | ||||
| 86 | |||||
| 87 | } # new() | ||||
| 88 | |||||
| 89 | sub out { | ||||
| 90 | die "Not yet written"; | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | =head2 next( [\&filter_func] ) | ||||
| 94 | |||||
| - - | |||||
| 105 | sub next { | ||||
| 106 | my $self = shift; | ||||
| 107 | $self->{recnum}++; | ||||
| 108 | my $rec = $self->_next() or return; | ||||
| 109 | return $self->decode($rec, @_); | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | =head2 skip() | ||||
| 113 | |||||
| - - | |||||
| 122 | sub skip { | ||||
| 123 | my $self = shift; | ||||
| 124 | my $rec = $self->_next() or return; | ||||
| 125 | return 1; | ||||
| 126 | } | ||||
| 127 | |||||
| 128 | =head2 warnings() | ||||
| 129 | |||||
| - - | |||||
| 136 | sub warnings { | ||||
| 137 | my $self = shift; | ||||
| 138 | my @warnings = @{ $self->{warnings} }; | ||||
| 139 | $self->{warnings} = []; | ||||
| 140 | return(@warnings); | ||||
| 141 | } | ||||
| 142 | |||||
| 143 | =head2 close() | ||||
| 144 | |||||
| - - | |||||
| 149 | sub close { | ||||
| 150 | my $self = shift; | ||||
| 151 | close( $self->{fh} ); | ||||
| 152 | delete $self->{fh}; | ||||
| 153 | delete $self->{filename}; | ||||
| 154 | return; | ||||
| 155 | } | ||||
| 156 | |||||
| 157 | sub _unimplemented() { | ||||
| 158 | my $self = shift; | ||||
| 159 | my $method = shift; | ||||
| 160 | warn "Method $method must be overridden"; | ||||
| 161 | } | ||||
| 162 | |||||
| 163 | =head2 write() | ||||
| 164 | |||||
| - - | |||||
| 175 | sub write { $_[0]->_unimplemented("write"); } | ||||
| 176 | sub decode { $_[0]->_unimplemented("decode"); } | ||||
| 177 | |||||
| 178 | # NOTE: _warn must be called as an object method | ||||
| 179 | |||||
| 180 | sub _warn { | ||||
| 181 | my ($self,$warning) = @_; | ||||
| 182 | push( @{ $self->{warnings} }, "$warning in record ".$self->{recnum} ); | ||||
| 183 | return( $self ); | ||||
| 184 | } | ||||
| 185 | |||||
| 186 | # NOTE: _gripe can be called as an object method, or not. Your choice. | ||||
| 187 | # NOTE: it's use is now depracated use _warn instead | ||||
| 188 | sub _gripe(@) { | ||||
| 189 | my @parms = @_; | ||||
| 190 | if ( @parms ) { | ||||
| 191 | my $self = shift @parms; | ||||
| 192 | |||||
| 193 | if ( ref($self) =~ /^MARC::File/ ) { | ||||
| 194 | push( @parms, " at byte ", tell($self->{fh}) ) | ||||
| 195 | if $self->{fh}; | ||||
| 196 | push( @parms, " in file ", $self->{filename} ) if $self->{filename}; | ||||
| 197 | } else { | ||||
| 198 | unshift( @parms, $self ); | ||||
| 199 | } | ||||
| 200 | |||||
| 201 | $ERROR = join( "", @parms ); | ||||
| 202 | warn $ERROR; | ||||
| 203 | } | ||||
| 204 | |||||
| 205 | return; | ||||
| 206 | } | ||||
| 207 | |||||
| 208 | 1 | 4µs | 1; | ||
| 209 | |||||
| 210 | __END__ |