Filename | /usr/share/perl5/MARC/Batch.pm |
Statements | Executed 50026 statements in 122ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
5001 | 2 | 2 | 126ms | 18.1s | next (recurses: max depth 1, inclusive time 17.4ms) | MARC::Batch::
1 | 1 | 1 | 63µs | 64µs | new | MARC::Batch::
1 | 1 | 1 | 22µs | 29µs | BEGIN@26 | MARC::Batch::
1 | 1 | 1 | 18µs | 23µs | BEGIN@27 | MARC::Batch::
1 | 1 | 1 | 17µs | 72µ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 | 150µs | 2 | 36µs | # spent 29µs (22+7) within MARC::Batch::BEGIN@26 which was called:
# once (22µs+7µs) by main::BEGIN@5 at line 26 # spent 29µs making 1 call to MARC::Batch::BEGIN@26
# spent 7µs making 1 call to strict::import |
27 | 3 | 46µs | 2 | 28µs | # spent 23µs (18+5) within MARC::Batch::BEGIN@27 which was called:
# once (18µs+5µs) by main::BEGIN@5 at line 27 # spent 23µs making 1 call to MARC::Batch::BEGIN@27
# spent 5µs making 1 call to integer::import |
28 | 3 | 748µs | 2 | 127µs | # spent 72µs (17+55) within MARC::Batch::BEGIN@28 which was called:
# once (17µs+55µs) by main::BEGIN@5 at line 28 # spent 72µs making 1 call to MARC::Batch::BEGIN@28
# spent 55µ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 | 2µs | my $class = shift; | ||
58 | 1 | 1µs | my $type = shift; | ||
59 | |||||
60 | 1 | 9µ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 | 5µ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 | 8µs | return $self; | ||
80 | } # new() | ||||
81 | |||||
82 | |||||
83 | =head2 next() | ||||
84 | |||||
- - | |||||
102 | # spent 18.1s (126ms+18.0) within MARC::Batch::next which was called 5001 times, avg 3.62ms/call:
# 5000 times (126ms+18.0s) by main::RUNTIME at line 10 of conv.pl, avg 3.62ms/call
# once (38µs+-38µs) by MARC::Batch::next at line 153 | ||||
103 | 5001 | 8.04ms | my ( $self, $filter ) = @_; | ||
104 | 5001 | 5.56ms | if ( $filter and ref($filter) ne 'CODE' ) { | ||
105 | croak( "filter function in next() must be a subroutine reference" ); | ||||
106 | } | ||||
107 | |||||
108 | 5001 | 7.64ms | if ( $self->{file} ) { | ||
109 | |||||
110 | # get the next record | ||||
111 | 5000 | 23.7ms | 5000 | 17.9s | my $rec = $self->{file}->next( $filter ); # spent 17.9s making 5000 calls to MARC::File::next, avg 3.58ms/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 | 27.2ms | 5000 | 43.1ms | my @warnings = $self->{file}->warnings(); # spent 43.1ms making 5000 calls to MARC::File::warnings, avg 9µs/call |
118 | 5000 | 5.99ms | if ( @warnings ) { | ||
119 | $self->warnings( @warnings ); | ||||
120 | return if $self->{ strict }; | ||||
121 | } | ||||
122 | |||||
123 | 5000 | 5.87ms | 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 | 8.06ms | my @warnings = @{ $rec->{_warnings} }; | ||
132 | |||||
133 | 5000 | 5.01ms | if (@warnings) { | ||
134 | $self->warnings( @warnings ); | ||||
135 | return if $self->{ strict }; | ||||
136 | } | ||||
137 | |||||
138 | # return the MARC::Record object | ||||
139 | 5000 | 23.9ms | 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 | 2µs | my $marcclass = $self->{marcclass}; | ||
150 | 1 | 9µs | 1 | 79µs | $self->{file} = $marcclass->in( $self->{filename} ) or return; # spent 79µ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 17.4ms making 1 call to MARC::Batch::next, recursion: max depth 1, sum of overlapping time 17.4ms |
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 | 3µ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 |