Subject: | don't call eval & require on each request. |
Please don't call `eval "require $body"' on each request.eval and
require is very slow function in the perl builtin functions.
=== lib/HTTP/Body.pm
==================================================================
--- lib/HTTP/Body.pm (revision 32900)
+++ lib/HTTP/Body.pm (local)
@@ -97,12 +97,8 @@
my $body = $TYPES->{ $type || 'application/octet-stream' };
- eval "require $body";
+ HTTP::Body::_require_once($body);
- if ($@) {
- die $@;
- }
-
my $self = {
buffer => '',
chunk_buffer => '',
@@ -368,6 +364,17 @@
return $self->{tmpdir};
}
+{
+ my $required;
+ sub _require_once {
+ my $pkg = shift;
+ return if $required->{$pkg};
+ eval "require $pkg";
+ Carp::croak $@ if $@;
+ $required->{$pkg}++;
+ }
+}
+
=back
=head1 AUTHOR