Filename | /usr/share/perl5/MARC/File.pm |
Statements | Executed 40027 statements in 139ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5000 | 1 | 1 | 90.9ms | 90.8s | next | MARC::File::
5000 | 1 | 1 | 50.1ms | 50.1ms | warnings | MARC::File::
1 | 1 | 1 | 191µs | 195µs | BEGIN@10 | MARC::File::
1 | 1 | 1 | 50µs | 68µs | in | MARC::File::
1 | 1 | 1 | 22µs | 27µs | BEGIN@9 | MARC::File::
1 | 1 | 1 | 18µs | 18µs | CORE:open (opcode) | MARC::File::
1 | 1 | 1 | 16µs | 28µs | BEGIN@57 | MARC::File::
1 | 1 | 1 | 12µs | 49µs | BEGIN@12 | MARC::File::
0 | 0 | 0 | 0s | 0s | _gripe | MARC::File::
0 | 0 | 0 | 0s | 0s | _unimplemented | MARC::File::
0 | 0 | 0 | 0s | 0s | _warn | MARC::File::
0 | 0 | 0 | 0s | 0s | close | MARC::File::
0 | 0 | 0 | 0s | 0s | decode | MARC::File::
0 | 0 | 0 | 0s | 0s | out | MARC::File::
0 | 0 | 0 | 0s | 0s | skip | MARC::File::
0 | 0 | 0 | 0s | 0s | write | MARC::File::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package MARC::File; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
- - | |||||
9 | 3 | 45µs | 2 | 32µs | # spent 27µs (22+5) within MARC::File::BEGIN@9 which was called:
# once (22µs+5µs) by base::import at line 9 # spent 27µs making 1 call to MARC::File::BEGIN@9
# spent 5µs making 1 call to strict::import |
10 | 3 | 213µs | 2 | 199µs | # spent 195µs (191+4) within MARC::File::BEGIN@10 which was called:
# once (191µs+4µs) by base::import at line 10 # spent 195µs making 1 call to MARC::File::BEGIN@10
# spent 4µs making 1 call to integer::import |
11 | |||||
12 | 3 | 95µs | 2 | 86µs | # spent 49µs (12+37) within MARC::File::BEGIN@12 which was called:
# once (12µs+37µs) by base::import at line 12 # spent 49µs making 1 call to MARC::File::BEGIN@12
# spent 37µs making 1 call to vars::import |
13 | |||||
14 | =head1 SYNOPSIS | ||||
15 | |||||
- - | |||||
51 | # spent 68µs (50+18) within MARC::File::in which was called:
# once (50µs+18µs) by MARC::Batch::next at line 150 of MARC/Batch.pm | ||||
52 | 7 | 22µs | my $class = shift; | ||
53 | my $arg = shift; | ||||
54 | my ( $filename, $fh ); | ||||
55 | |||||
56 | ## if a valid filehandle was passed in | ||||
57 | 4 | 695µs | 2 | 40µs | # spent 28µs (16+12) within MARC::File::BEGIN@57 which was called:
# once (16µs+12µs) by base::import at line 57 # spent 28µs making 1 call to MARC::File::BEGIN@57
# spent 12µs making 1 call to strict::unimport |
58 | 3 | 7µs | if ( $ishandle ) { | ||
59 | $filename = scalar( $arg ); | ||||
60 | $fh = $arg; | ||||
61 | } | ||||
62 | |||||
63 | ## otherwise check if it's a filename, and | ||||
64 | ## return undef if we weren't able to open it | ||||
65 | else { | ||||
66 | $filename = $arg; | ||||
67 | 3 | 33µs | 1 | 18µs | $fh = eval { local *FH; open( FH, $arg ) or die; *FH{IO}; }; # spent 18µs making 1 call to MARC::File::CORE:open |
68 | if ( $@ ) { | ||||
69 | $MARC::File::ERROR = "Couldn't open $filename: $@"; | ||||
70 | return; | ||||
71 | } | ||||
72 | } | ||||
73 | |||||
74 | my $self = { | ||||
75 | filename => $filename, | ||||
76 | fh => $fh, | ||||
77 | recnum => 0, | ||||
78 | warnings => [], | ||||
79 | }; | ||||
80 | |||||
81 | return( bless $self, $class ); | ||||
82 | |||||
83 | } # new() | ||||
84 | |||||
85 | sub out { | ||||
86 | die "Not yet written"; | ||||
87 | } | ||||
88 | |||||
89 | =head2 next( [\&filter_func] ) | ||||
90 | |||||
- - | |||||
101 | # spent 90.8s (90.9ms+90.8) within MARC::File::next which was called 5000 times, avg 18.2ms/call:
# 5000 times (90.9ms+90.8s) by MARC::Batch::next at line 111 of MARC/Batch.pm, avg 18.2ms/call | ||||
102 | 20000 | 86.5ms | my $self = shift; | ||
103 | $self->{recnum}++; | ||||
104 | 5000 | 482ms | my $rec = $self->_next() or return; # spent 482ms making 5000 calls to MARC::File::XML::_next, avg 96µs/call | ||
105 | 5000 | 90.3s | return $self->decode($rec, @_); # spent 90.3s making 5000 calls to MARC::File::XML::decode, avg 18.1ms/call | ||
106 | } | ||||
107 | |||||
108 | =head2 skip() | ||||
109 | |||||
- - | |||||
118 | sub skip { | ||||
119 | my $self = shift; | ||||
120 | my $rec = $self->_next() or return; | ||||
121 | return 1; | ||||
122 | } | ||||
123 | |||||
124 | =head2 warnings() | ||||
125 | |||||
- - | |||||
132 | # spent 50.1ms within MARC::File::warnings which was called 5000 times, avg 10µs/call:
# 5000 times (50.1ms+0s) by MARC::Batch::next at line 117 of MARC/Batch.pm, avg 10µs/call | ||||
133 | 20000 | 51.8ms | my $self = shift; | ||
134 | my @warnings = @{ $self->{warnings} }; | ||||
135 | $self->{warnings} = []; | ||||
136 | return(@warnings); | ||||
137 | } | ||||
138 | |||||
139 | =head2 close() | ||||
140 | |||||
- - | |||||
145 | sub close { | ||||
146 | my $self = shift; | ||||
147 | close( $self->{fh} ); | ||||
148 | delete $self->{fh}; | ||||
149 | delete $self->{filename}; | ||||
150 | return; | ||||
151 | } | ||||
152 | |||||
153 | sub _unimplemented() { | ||||
154 | my $self = shift; | ||||
155 | my $method = shift; | ||||
156 | warn "Method $method must be overridden"; | ||||
157 | } | ||||
158 | |||||
159 | =head2 write() | ||||
160 | |||||
- - | |||||
171 | sub write { $_[0]->_unimplemented("write"); } | ||||
172 | sub decode { $_[0]->_unimplemented("decode"); } | ||||
173 | |||||
174 | # NOTE: _warn must be called as an object method | ||||
175 | |||||
176 | sub _warn { | ||||
177 | my ($self,$warning) = @_; | ||||
178 | push( @{ $self->{warnings} }, "$warning in record ".$self->{recnum} ); | ||||
179 | return( $self ); | ||||
180 | } | ||||
181 | |||||
182 | # NOTE: _gripe can be called as an object method, or not. Your choice. | ||||
183 | # NOTE: it's use is now depracated use _warn instead | ||||
184 | sub _gripe(@) { | ||||
185 | my @parms = @_; | ||||
186 | if ( @parms ) { | ||||
187 | my $self = shift @parms; | ||||
188 | |||||
189 | if ( ref($self) =~ /^MARC::File/ ) { | ||||
190 | push( @parms, " at byte ", tell($self->{fh}) ) | ||||
191 | if $self->{fh}; | ||||
192 | push( @parms, " in file ", $self->{filename} ) if $self->{filename}; | ||||
193 | } else { | ||||
194 | unshift( @parms, $self ); | ||||
195 | } | ||||
196 | |||||
197 | $ERROR = join( "", @parms ); | ||||
198 | warn $ERROR; | ||||
199 | } | ||||
200 | |||||
201 | return; | ||||
202 | } | ||||
203 | |||||
204 | 1 | 4µs | 1; | ||
205 | |||||
206 | __END__ | ||||
# spent 18µs within MARC::File::CORE:open which was called:
# once (18µs+0s) by MARC::File::in at line 67 |