Filename | /usr/share/perl5/MARC/Batch.pm |
Statements | Executed 50026 statements in 138ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5001 | 2 | 2 | 140ms | 91.0s | next (recurses: max depth 1, inclusive time 47.8ms) | MARC::Batch::
1 | 1 | 1 | 63µs | 64µs | new | MARC::Batch::
1 | 1 | 1 | 26µs | 35µs | BEGIN@26 | MARC::Batch::
1 | 1 | 1 | 18µs | 24µs | BEGIN@27 | MARC::Batch::
1 | 1 | 1 | 14µs | 70µs | BEGIN@28 | MARC::Batch::
1 | 1 | 1 | 1µs | 1µs | CORE:match (opcode) | MARC::Batch::
0 | 0 | 0 | 0s | 0s | filename | MARC::Batch::
0 | 0 | 0 | 0s | 0s | strict_off | MARC::Batch::
0 | 0 | 0 | 0s | 0s | strict_on | MARC::Batch::
0 | 0 | 0 | 0s | 0s | warnings | MARC::Batch::
0 | 0 | 0 | 0s | 0s | warnings_off | MARC::Batch::
0 | 0 | 0 | 0s | 0s | warnings_on | MARC::Batch::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package MARC::Batch; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
- - | |||||
26 | 3 | 44µs | 2 | 44µs | # spent 35µs (26+9) within MARC::Batch::BEGIN@26 which was called:
# once (26µs+9µs) by main::BEGIN@5 at line 26 # spent 35µs making 1 call to MARC::Batch::BEGIN@26
# spent 9µs making 1 call to strict::import |
27 | 3 | 44µs | 2 | 30µs | # spent 24µs (18+6) within MARC::Batch::BEGIN@27 which was called:
# once (18µs+6µs) by main::BEGIN@5 at line 27 # spent 24µs making 1 call to MARC::Batch::BEGIN@27
# spent 6µs making 1 call to integer::import |
28 | 3 | 855µs | 2 | 126µs | # spent 70µs (14+56) within MARC::Batch::BEGIN@28 which was called:
# once (14µs+56µs) by main::BEGIN@5 at line 28 # spent 70µs making 1 call to MARC::Batch::BEGIN@28
# spent 56µs making 1 call to Exporter::import |
29 | |||||
30 | =head1 METHODS | ||||
31 | |||||
- - | |||||
56 | # spent 64µs (63+1) within MARC::Batch::new which was called:
# once (63µs+1µs) by main::RUNTIME at line 9 of conv.pl | ||||
57 | 1 | 1µs | my $class = shift; | ||
58 | 1 | 1µs | my $type = shift; | ||
59 | |||||
60 | 1 | 10µs | 1 | 1µs | my $marcclass = ($type =~ /^MARC::File/) ? $type : "MARC::File::$type"; # spent 1µs making 1 call to MARC::Batch::CORE:match |
61 | |||||
62 | 1 | 26µs | eval "require $marcclass"; # spent 5µs executing statements in string eval | ||
63 | 1 | 1µs | croak $@ if $@; | ||
64 | |||||
65 | 1 | 2µs | my @files = @_; | ||
66 | |||||
67 | 1 | 6µs | my $self = { | ||
68 | filestack => \@files, | ||||
69 | filename => undef, | ||||
70 | marcclass => $marcclass, | ||||
71 | file => undef, | ||||
72 | warnings => [], | ||||
73 | 'warn' => 1, | ||||
74 | strict => 1, | ||||
75 | }; | ||||
76 | |||||
77 | 1 | 7µs | bless $self, $class; | ||
78 | |||||
79 | 1 | 7µs | return $self; | ||
80 | } # new() | ||||
81 | |||||
82 | |||||
83 | =head2 next() | ||||
84 | |||||
- - | |||||
102 | # spent 91.0s (140ms+90.9) within MARC::Batch::next which was called 5001 times, avg 18.2ms/call:
# 5000 times (140ms+90.9s) by main::RUNTIME at line 10 of conv.pl, avg 18.2ms/call
# once (48µs+-48µs) by MARC::Batch::next at line 153 | ||||
103 | 5001 | 8.76ms | my ( $self, $filter ) = @_; | ||
104 | 5001 | 5.84ms | if ( $filter and ref($filter) ne 'CODE' ) { | ||
105 | croak( "filter function in next() must be a subroutine reference" ); | ||||
106 | } | ||||
107 | |||||
108 | 5001 | 7.73ms | if ( $self->{file} ) { | ||
109 | |||||
110 | # get the next record | ||||
111 | 5000 | 25.8ms | 5000 | 90.8s | my $rec = $self->{file}->next( $filter ); # spent 90.8s making 5000 calls to MARC::File::next, avg 18.2ms/call |
112 | |||||
113 | # collect warnings from MARC::File::* object | ||||
114 | # we use the warnings() method here since MARC::Batch | ||||
115 | # hides access to MARC::File objects, and we don't | ||||
116 | # need to preserve the warnings buffer. | ||||
117 | 5000 | 35.5ms | 5000 | 50.1ms | my @warnings = $self->{file}->warnings(); # spent 50.1ms making 5000 calls to MARC::File::warnings, avg 10µs/call |
118 | 5000 | 5.99ms | if ( @warnings ) { | ||
119 | $self->warnings( @warnings ); | ||||
120 | return if $self->{ strict }; | ||||
121 | } | ||||
122 | |||||
123 | 5000 | 6.17ms | if ($rec) { | ||
124 | |||||
125 | # collect warnings from the MARC::Record object | ||||
126 | # IMPORTANT: here we don't use warnings() but dig | ||||
127 | # into the the object to get at the warnings without | ||||
128 | # erasing the buffer. This is so a user can call | ||||
129 | # warnings() on the MARC::Record object and get back | ||||
130 | # warnings for that specific record. | ||||
131 | 5000 | 9.12ms | my @warnings = @{ $rec->{_warnings} }; | ||
132 | |||||
133 | 5000 | 5.10ms | if (@warnings) { | ||
134 | $self->warnings( @warnings ); | ||||
135 | return if $self->{ strict }; | ||||
136 | } | ||||
137 | |||||
138 | # return the MARC::Record object | ||||
139 | 5000 | 27.0ms | return($rec); | ||
140 | |||||
141 | } | ||||
142 | |||||
143 | } | ||||
144 | |||||
145 | # Get the next file off the stack, if there is one | ||||
146 | 1 | 2µs | $self->{filename} = shift @{$self->{filestack}} or return; | ||
147 | |||||
148 | # Instantiate a filename for it | ||||
149 | 1 | 1µs | my $marcclass = $self->{marcclass}; | ||
150 | 1 | 8µs | 1 | 68µs | $self->{file} = $marcclass->in( $self->{filename} ) or return; # spent 68µs making 1 call to MARC::File::in |
151 | |||||
152 | # call this method again now that we've got a file open | ||||
153 | 1 | 13µs | 1 | 0s | return( $self->next( $filter ) ); # spent 47.8ms making 1 call to MARC::Batch::next, recursion: max depth 1, sum of overlapping time 47.8ms |
154 | |||||
155 | } | ||||
156 | |||||
157 | =head2 strict_off() | ||||
158 | |||||
- - | |||||
169 | sub strict_off { | ||||
170 | my $self = shift; | ||||
171 | $self->{ strict } = 0; | ||||
172 | return(1); | ||||
173 | } | ||||
174 | |||||
175 | =head2 strict_on() | ||||
176 | |||||
- - | |||||
185 | sub strict_on { | ||||
186 | my $self = shift; | ||||
187 | $self->{ strict } = 1; | ||||
188 | return(1); | ||||
189 | } | ||||
190 | |||||
191 | =head2 warnings() | ||||
192 | |||||
- - | |||||
205 | sub warnings { | ||||
206 | my ($self,@new) = @_; | ||||
207 | if ( @new ) { | ||||
208 | push( @{ $self->{warnings} }, @new ); | ||||
209 | print STDERR join( "\n", @new ) if $self->{'warn'}; | ||||
210 | } else { | ||||
211 | my @old = @{ $self->{warnings} }; | ||||
212 | $self->{warnings} = []; | ||||
213 | return(@old); | ||||
214 | } | ||||
215 | } | ||||
216 | |||||
217 | |||||
218 | =head2 warnings_off() | ||||
219 | |||||
- - | |||||
228 | sub warnings_off { | ||||
229 | my $self = shift; | ||||
230 | $self->{ 'warn' } = 0; | ||||
231 | |||||
232 | return 1; | ||||
233 | } | ||||
234 | |||||
235 | =head2 warnings_on() | ||||
236 | |||||
- - | |||||
245 | sub warnings_on { | ||||
246 | my $self = shift; | ||||
247 | $self->{ 'warn' } = 1; | ||||
248 | } | ||||
249 | |||||
250 | =head2 filename() | ||||
251 | |||||
- - | |||||
257 | sub filename { | ||||
258 | my $self = shift; | ||||
259 | |||||
260 | return $self->{filename}; | ||||
261 | } | ||||
262 | |||||
263 | |||||
264 | 1 | 4µs | 1; | ||
265 | |||||
266 | __END__ | ||||
# spent 1µs within MARC::Batch::CORE:match which was called:
# once (1µs+0s) by MARC::Batch::new at line 60 |