From: Andrew Rodland Date: Tue, 3 Apr 2012 17:12:26 +0000 (-0400) Subject: Fix match parsing with perl 5.8.8 X-Git-Tag: v0.014~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=6153800d4bc0320055aad12b7afafd35818d127a Fix match parsing with perl 5.8.8 Runtime-loading the ParamParser loads Encode, which blows away $_ and pos. Carefully save these values around the module load so that things don't blow up. --- diff --git a/Changes b/Changes index 86f7dbc..9341251 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,6 @@ + - Fix a weird interaction between match-spec parsing and module loading + that was causing brokenness and test failures with perl 5.8.8 + 0.012 - 2012-01-30 - Added match predicates match_true and match_false - Added '~' to match an empty path diff --git a/lib/Web/Dispatch/Predicates.pm b/lib/Web/Dispatch/Predicates.pm index 6a489a5..452a5e2 100644 --- a/lib/Web/Dispatch/Predicates.pm +++ b/lib/Web/Dispatch/Predicates.pm @@ -125,7 +125,16 @@ sub match_uploads { sub _param_matcher { my ($type, $spec) = @_; - require Web::Dispatch::ParamParser; + # We're probably parsing a match spec while building the parser, and + # on 5.8.8, loading ParamParser loads Encode which blows away $_ and pos. + # Furthermore, localizing $_ doesn't restore pos afterwards. So do this + # stupid thing instead to work on 5.8.8 + my $saved_pos = pos; + { + local $_; + require Web::Dispatch::ParamParser; + } + pos = $saved_pos; my $unpack = Web::Dispatch::ParamParser->can("get_unpacked_${type}_from"); sub { _extract_params($unpack->($_[0]), $spec)