Skip Menu |

This queue is for tickets about the HTTP-Body CPAN distribution.

Report information
The Basics
Id: 41315
Status: resolved
Priority: 0/
Queue: HTTP-Body

People
Owner: Nobody in particular
Requestors: tokuhirom+cpan [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
Good point, actually the eval/require line is not even needed anymore as all type modules are already loaded. I'll release a new version with this line removed.