Filename | /usr/share/perl5/MARC/File.pm |
Statements | Executed 40027 statements in 123ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5000 | 1 | 1 | 80.5ms | 17.9s | next | MARC::File::
5000 | 1 | 1 | 43.1ms | 43.1ms | warnings | MARC::File::
1 | 1 | 1 | 206µs | 211µs | BEGIN@10 | MARC::File::
1 | 1 | 1 | 50µs | 79µs | in | MARC::File::
1 | 1 | 1 | 29µs | 29µs | CORE:open (opcode) | MARC::File::
1 | 1 | 1 | 22µs | 27µs | BEGIN@9 | MARC::File::
1 | 1 | 1 | 15µs | 54µs | BEGIN@12 | MARC::File::
1 | 1 | 1 | 14µs | 25µs | BEGIN@57 | 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 | 39µ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 | 227µs | 2 | 216µs | # spent 211µs (206+5) within MARC::File::BEGIN@10 which was called:
# once (206µs+5µs) by base::import at line 10 # spent 211µs making 1 call to MARC::File::BEGIN@10
# spent 5µs making 1 call to integer::import |
11 | |||||
12 | 3 | 88µs | 2 | 93µs | # spent 54µs (15+39) within MARC::File::BEGIN@12 which was called:
# once (15µs+39µs) by base::import at line 12 # spent 54µs making 1 call to MARC::File::BEGIN@12
# spent 39µs making 1 call to vars::import |
13 | |||||
14 | =head1 SYNOPSIS | ||||
15 | |||||
- - | |||||
51 | # spent 79µs (50+29) within MARC::File::in which was called:
# once (50µs+29µs) by MARC::Batch::next at line 150 of MARC/Batch.pm | ||||
52 | 7 | 26µs | my $class = shift; | ||
53 | my $arg = shift; | ||||
54 | my ( $filename, $fh ); | ||||
55 | |||||
56 | ## if a valid filehandle was passed in | ||||
57 | 4 | 705µs | 2 | 36µs | # spent 25µs (14+11) within MARC::File::BEGIN@57 which was called:
# once (14µs+11µs) by base::import at line 57 # spent 25µs making 1 call to MARC::File::BEGIN@57
# spent 11µs making 1 call to strict::unimport |
58 | 3 | 6µ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 | 42µs | 1 | 29µs | $fh = eval { local *FH; open( FH, $arg ) or die; *FH{IO}; }; # spent 29µ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 17.9s (80.5ms+17.8) within MARC::File::next which was called 5000 times, avg 3.58ms/call:
# 5000 times (80.5ms+17.8s) by MARC::Batch::next at line 111 of MARC/Batch.pm, avg 3.58ms/call | ||||
102 | 20000 | 75.5ms | my $self = shift; | ||
103 | $self->{recnum}++; | ||||
104 | 5000 | 419ms | my $rec = $self->_next() or return; # spent 419ms making 5000 calls to MARC::File::XML::_next, avg 84µs/call | ||
105 | 15000 | 17.5s | return $self->decode($rec, @_); # spent 17.4s making 5000 calls to MARC::File::XML::decode, avg 3.48ms/call
# spent 121ms making 10000 calls to XML::LibXML::Node::DESTROY, avg 12µs/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 43.1ms within MARC::File::warnings which was called 5000 times, avg 9µs/call:
# 5000 times (43.1ms+0s) by MARC::Batch::next at line 117 of MARC/Batch.pm, avg 9µs/call | ||||
133 | 20000 | 46.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 | 3µs | 1; | ||
205 | |||||
206 | __END__ | ||||
# spent 29µs within MARC::File::CORE:open which was called:
# once (29µs+0s) by MARC::File::in at line 67 |