The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Build.PL 513
CONTRIBUTORS 45
Changes 06
INSTALL 10
LICENSE 33
MANIFEST 11
META.json 513
META.yml 411
Makefile.PL 615
README 5349
cpanfile 27
dist.ini 412
examples/001-custom-cache.pl 12
lib/WWW/Mechanize/Cached.pm 11279
t/001-load.t 22
t/002-bad-custom-cache.t 513
t/003-basic.t 11
t/004-cached.t 2125
t/005-custom-cache.t 712
t/006-cached-chi.t 2024
t/TestCache.pm 66
t/cache_key.t 1924
t/cache_ok.t 713
t/is_cached.t 11
24 files changed (This is a version diff) 290337
@@ -1,5 +1,5 @@
 
-# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v5.020.
+# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v5.031.
 use strict;
 use warnings;
 
@@ -21,25 +21,31 @@ my %module_build_args = (
     "Olaf Alders <olaf\@wundercounter.com> (current maintainer)"
   ],
   "dist_name" => "WWW-Mechanize-Cached",
-  "dist_version" => "1.44",
+  "dist_version" => "1.46",
   "license" => "perl",
   "module_name" => "WWW::Mechanize::Cached",
-  "recommends" => {},
+  "recommends" => {
+    "CHI" => 0
+  },
   "recursive_test_files" => 1,
   "requires" => {
-    "CHI" => 0,
     "Cache::FileCache" => 0,
     "Carp" => 0,
+    "Class::Load" => 0,
     "Data::Dump" => 0,
-    "Moose" => 0,
+    "Moo" => "1.004005",
+    "MooX::Types::MooseLike::Base" => 0,
     "Storable" => "2.21",
     "WWW::Mechanize" => 0,
+    "namespace::clean" => 0,
     "perl" => "5.006",
     "strict" => 0,
     "warnings" => 0
   },
   "script_files" => [],
   "test_requires" => {
+    "CHI" => 0,
+    "Cache::FileCache" => 0,
     "File::Spec" => 0,
     "Find::Lib" => 0,
     "HTTP::Request" => 0,
@@ -54,6 +60,8 @@ my %module_build_args = (
 
 
 my %fallback_build_requires = (
+  "CHI" => 0,
+  "Cache::FileCache" => 0,
   "File::Spec" => 0,
   "Find::Lib" => 0,
   "HTTP::Request" => 0,
@@ -4,10 +4,11 @@
 This is the (likely incomplete) list of people who have helped
 make this distribution what it is, either via code contributions, 
 patches, bug reports, help with troubleshooting, etc. A huge
-thank to all of them.
+'thank you' to all of them.
 
-    * Kent Fredric <kentfredric@gmail.com>
-    * Neil Bowers <neil@bowers.com>
-    * Olaf Alders <olaf@wundersolutions.com>
+    * Kent Fredric
+    * Mark Gardner
+    * Neil Bowers
+    * Olaf Alders
 
 
@@ -1,5 +1,11 @@
 Revision history for Perl module WWW::Mechanize::Cached
 
+1.46 2015-02-08 21:41:11 America/Toronto
+    - Bump Moo version to fix tester failures (Mark Gardner)
+
+1.45 2015-02-07 18:16:43 America/Toronto
+    - Ported from Moose to Moo (Mark Gardner)
+
 1.44 2014-08-23 11:25:15 America/Toronto
     - Support working with CHI automatically if Cache::FileCache is not installed
     - GH #6 (KentĀ Fredric)
@@ -1,4 +1,3 @@
-
 This is the Perl distribution WWW-Mechanize-Cached.
 
 Installing WWW-Mechanize-Cached is straightforward.
@@ -1,4 +1,4 @@
-This software is copyright (c) 2013 by Iain Truskett and Andy Lester.
+This software is copyright (c) 2015 by Iain Truskett and Andy Lester.
 
 This is free software; you can redistribute it and/or modify it under
 the same terms as the Perl 5 programming language system itself.
@@ -12,7 +12,7 @@ b) the "Artistic License"
 
 --- The GNU General Public License, Version 1, February 1989 ---
 
-This software is Copyright (c) 2013 by Iain Truskett and Andy Lester.
+This software is Copyright (c) 2015 by Iain Truskett and Andy Lester.
 
 This is free software, licensed under:
 
@@ -272,7 +272,7 @@ That's all there is to it!
 
 --- The Artistic License 1.0 ---
 
-This software is Copyright (c) 2013 by Iain Truskett and Andy Lester.
+This software is Copyright (c) 2015 by Iain Truskett and Andy Lester.
 
 This is free software, licensed under:
 
@@ -1,4 +1,4 @@
-# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.020.
+# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.031.
 AUTHORS
 Build.PL
 CONTRIBUTORS
@@ -6,13 +6,13 @@
       "Olaf Alders <olaf@wundercounter.com> (current maintainer)"
    ],
    "dynamic_config" : 0,
-   "generated_by" : "Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.140640",
+   "generated_by" : "Dist::Zilla version 5.031, CPAN::Meta::Converter version 2.143240",
    "license" : [
       "perl_5"
    ],
    "meta-spec" : {
       "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
-      "version" : "2"
+      "version" : 2
    },
    "name" : "WWW-Mechanize-Cached",
    "prereqs" : {
@@ -35,14 +35,19 @@
          }
       },
       "runtime" : {
+         "recommends" : {
+            "CHI" : "0"
+         },
          "requires" : {
-            "CHI" : "0",
             "Cache::FileCache" : "0",
             "Carp" : "0",
+            "Class::Load" : "0",
             "Data::Dump" : "0",
-            "Moose" : "0",
+            "Moo" : "1.004005",
+            "MooX::Types::MooseLike::Base" : "0",
             "Storable" : "2.21",
             "WWW::Mechanize" : "0",
+            "namespace::clean" : "0",
             "perl" : "5.006",
             "strict" : "0",
             "warnings" : "0"
@@ -50,6 +55,8 @@
       },
       "test" : {
          "requires" : {
+            "CHI" : "0",
+            "Cache::FileCache" : "0",
             "File::Spec" : "0",
             "Find::Lib" : "0",
             "HTTP::Request" : "0",
@@ -74,9 +81,10 @@
          "web" : "https://github.com/oalders/www-mechanize-cached"
       }
    },
-   "version" : "1.44",
+   "version" : "1.46",
    "x_contributors" : [
       "Kent Fredric <kentfredric@gmail.com>",
+      "Mark Gardner <mjg@ziprecruiter.com>",
       "Neil Bowers <neil@bowers.com>",
       "Olaf Alders <olaf@wundersolutions.com>"
    ]
@@ -5,6 +5,8 @@ author:
   - 'Andy Lester <petdance@cpan.org> (2004 - July 2009)'
   - 'Olaf Alders <olaf@wundercounter.com> (current maintainer)'
 build_requires:
+  CHI: '0'
+  Cache::FileCache: '0'
   File::Spec: '0'
   Find::Lib: '0'
   HTTP::Request: '0'
@@ -19,20 +21,24 @@ configure_requires:
   ExtUtils::MakeMaker: '0'
   Module::Build: '0.28'
 dynamic_config: 0
-generated_by: 'Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.140640'
+generated_by: 'Dist::Zilla version 5.031, CPAN::Meta::Converter version 2.143240'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
   version: '1.4'
 name: WWW-Mechanize-Cached
-requires:
+recommends:
   CHI: '0'
+requires:
   Cache::FileCache: '0'
   Carp: '0'
+  Class::Load: '0'
   Data::Dump: '0'
-  Moose: '0'
+  Moo: '1.004005'
+  MooX::Types::MooseLike::Base: '0'
   Storable: '2.21'
   WWW::Mechanize: '0'
+  namespace::clean: '0'
   perl: '5.006'
   strict: '0'
   warnings: '0'
@@ -40,8 +46,9 @@ resources:
   bugtracker: http://github.com/oalders/www-mechanize-cached/issues
   homepage: https://github.com/oalders/www-mechanize-cached
   repository: https://github.com/oalders/www-mechanize-cached.git
-version: '1.44'
+version: '1.46'
 x_contributors:
   - 'Kent Fredric <kentfredric@gmail.com>'
+  - 'Mark Gardner <mjg@ziprecruiter.com>'
   - 'Neil Bowers <neil@bowers.com>'
   - 'Olaf Alders <olaf@wundersolutions.com>'
@@ -1,11 +1,11 @@
 
-# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.020.
+# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.031.
 use strict;
 use warnings;
 
 use 5.006;
 
-use ExtUtils::MakeMaker ;
+use ExtUtils::MakeMaker;
 
 
 
@@ -22,19 +22,24 @@ my %WriteMakefileArgs = (
   "DISTNAME" => "WWW-Mechanize-Cached",
   "EXE_FILES" => [],
   "LICENSE" => "perl",
+  "MIN_PERL_VERSION" => "5.006",
   "NAME" => "WWW::Mechanize::Cached",
   "PREREQ_PM" => {
-    "CHI" => 0,
     "Cache::FileCache" => 0,
     "Carp" => 0,
+    "Class::Load" => 0,
     "Data::Dump" => 0,
-    "Moose" => 0,
+    "Moo" => "1.004005",
+    "MooX::Types::MooseLike::Base" => 0,
     "Storable" => "2.21",
     "WWW::Mechanize" => 0,
+    "namespace::clean" => 0,
     "strict" => 0,
     "warnings" => 0
   },
   "TEST_REQUIRES" => {
+    "CHI" => 0,
+    "Cache::FileCache" => 0,
     "File::Spec" => 0,
     "Find::Lib" => 0,
     "HTTP::Request" => 0,
@@ -45,7 +50,7 @@ my %WriteMakefileArgs = (
     "lib" => 0,
     "vars" => 0
   },
-  "VERSION" => "1.44",
+  "VERSION" => "1.46",
   "test" => {
     "TESTS" => "t/*.t"
   }
@@ -56,12 +61,15 @@ my %FallbackPrereqs = (
   "CHI" => 0,
   "Cache::FileCache" => 0,
   "Carp" => 0,
+  "Class::Load" => 0,
   "Data::Dump" => 0,
+  "ExtUtils::MakeMaker" => 0,
   "File::Spec" => 0,
   "Find::Lib" => 0,
   "HTTP::Request" => 0,
   "Module::Build" => "0.28",
-  "Moose" => 0,
+  "Moo" => "1.004005",
+  "MooX::Types::MooseLike::Base" => 0,
   "Path::Class" => 0,
   "Storable" => "2.21",
   "Test::More" => 0,
@@ -69,6 +77,7 @@ my %FallbackPrereqs = (
   "WWW::Mechanize" => 0,
   "constant" => 0,
   "lib" => 0,
+  "namespace::clean" => 0,
   "strict" => 0,
   "vars" => 0,
   "warnings" => 0
@@ -1,28 +1,24 @@
-NAME
-    WWW::Mechanize::Cached - Cache response to be polite
-
-VERSION
-    version 1.44
-
 SYNOPSIS
-        use WWW::Mechanize::Cached;
 
+        use WWW::Mechanize::Cached;
+    
         my $cacher = WWW::Mechanize::Cached->new;
         $cacher->get( $url );
-
+    
         # or, with your own Cache object
         use CHI;
         use WWW::Mechanize::Cached;
-
+    
         my $cache = CHI->new(
             driver   => 'File',
             root_dir => '/tmp/mech-example'
         );
-
+    
         my $mech = WWW::Mechanize::Cached->new( cache => $cache );
         $mech->get("http://www.wikipedia.org");
 
 DESCRIPTION
+
     Uses the Cache::Cache hierarchy by default to implement a caching Mech.
     This lets one perform repeated requests without hammering a server
     impolitely. Please note that Cache::Cache has been superceded by CHI,
@@ -31,25 +27,26 @@ DESCRIPTION
     CHI caching object to override the default.
 
 CONSTRUCTOR
-  new
-    Behaves like, and calls, WWW::Mechanize's "new" method. Any params,
-    other than those explicitly listed here are passed directly to
+
+ new
+
+    Behaves like, and calls, WWW::Mechanize's new method. Any params, other
+    than those explicitly listed here are passed directly to
     WWW::Mechanize's constructor.
 
-    You may pass in a "cache => $cache_object" if you wish. The
-    *$cache_object* must have "get()" and "set()" methods like the
-    "Cache::Cache" family.
+    You may pass in a cache => $cache_object if you wish. The $cache_object
+    must have get() and set() methods like the Cache::Cache family.
 
     The default Cache object is set up with the following params:
 
         my $cache_params = {
             default_expires_in => "1d", namespace => 'www-mechanize-cached',
         };
-
+    
         $cache = Cache::FileCache->new( $cache_params );
 
-    This should be fine if you only want to use a disk-based cache, you only
-    want to cache results for 1 day and you're not in a shared hosting
+    This should be fine if you only want to use a disk-based cache, you
+    only want to cache results for 1 day and you're not in a shared hosting
     environment. If any of this presents a problem for you, you should pass
     in your own Cache object. These defaults will remain unchanged in order
     to maintain backwards compatibility.
@@ -58,29 +55,33 @@ CONSTRUCTOR
 
         use WWW::Mechanize::Cached;
         use CHI;
-
+    
         my $cache = CHI->new(
             driver   => 'File',
             root_dir => '/tmp/mech-example'
         );
-
+    
         my $mech = WWW::Mechanize::Cached->new( cache => $cache );
         $mech->get("http://www.wikipedia.org");
 
 METHODS
+
     Most methods are provided by WWW::Mechanize. See that module's
     documentation for details.
 
-  cache( $cache_object )
+ cache( $cache_object )
+
     Requires an caching object which has a get() and a set() method. Using
     the CHI module to create your cache is the recommended way. See new()
     for examples.
 
-  is_cached()
+ is_cached()
+
     Returns true if the current page is from the cache, or false if not. If
-    it returns "undef", then you don't have any current request.
+    it returns undef, then you don't have any current request.
+
+ positive_cache( 0|1 )
 
-  positive_cache( 0|1 )
     As of v1.36 positive caching is enabled by default. Up to this point,
     this module had employed a negative cache, which means it cached 404
     responses, temporary redirects etc. In most cases, this is not what you
@@ -90,7 +91,8 @@ METHODS
         # cache everything (404s, all 300s etc)
         $mech->positive_cache( 0 );
 
-  ref_in_cache_key( 0|1 )
+ ref_in_cache_key( 0|1 )
+
     Allow the referring URL to be used when creating the cache key. This is
     off by default. In almost all cases, you will not want to enable this,
     but it is available to you for reasons of backwards compatibility and
@@ -108,20 +110,22 @@ METHODS
     See RT #56757 for a detailed example of the bugs this functionality can
     trigger.
 
-  cache_undef_content_length( 0 | 'warn' | 1 )
+ cache_undef_content_length( 0 | 'warn' | 1 )
+
     This is configuration option which adjusts how caching behaviour
     performs when the Content-Length header is not specified by the server.
 
     Default behaviour is 0, which is not to cache.
 
     Setting this value to 1, will cache pages even if the Content-Length
-    header is missing, which was the default behaviour prior to the addition
-    of this feature.
+    header is missing, which was the default behaviour prior to the
+    addition of this feature.
 
-    And thirdly, you can set the value to the string 'warn', to warn if this
-    scenario occurs, and then not cache it.
+    And thirdly, you can set the value to the string 'warn', to warn if
+    this scenario occurs, and then not cache it.
+
+ cache_zero_content_length( 0 | 'warn' | 1 )
 
-  cache_zero_content_length( 0 | 'warn' | 1 )
     This is configuration option which adjusts how caching behaviour
     performs when the Content-Length header is equal to 0.
 
@@ -131,10 +135,11 @@ METHODS
     header is 0, which was the default behaviour prior to the addition of
     this feature.
 
-    And thirdly, you can set the value to the string 'warn', to warn if this
-    scenario occurs, and then not cache it.
+    And thirdly, you can set the value to the string 'warn', to warn if
+    this scenario occurs, and then not cache it.
+
+ cache_mismatch_content_length( 0 | 'warn' | 1 )
 
-  cache_mismatch_content_length( 0 | 'warn' | 1 )
     This is configuration option which adjusts how caching behaviour
     performs when the Content-Length header differs from the length of the
     content itself. ( Which usually indicates a transmission error )
@@ -146,11 +151,12 @@ METHODS
     header conflicts with the content length, which was the default
     behaviour prior to the addition of this feature.
 
-    And thirdly, you can set the value to the string 'warn', to warn if this
-    scenario occurs, and then not cache it. ( This is the default behaviour
-    )
+    And thirdly, you can set the value to the string 'warn', to warn if
+    this scenario occurs, and then not cache it. ( This is the default
+    behaviour )
 
 UPGRADING FROM 1.40 OR EARLIER
+
     Caching behaviour has changed since 1.40, and this may result in pages
     that were previously cached start failing to cache, and in some cases,
     emit warnings.
@@ -162,32 +168,22 @@ UPGRADING FROM 1.40 OR EARLIER
         $mech->cache_mismatch_content_length(1); # Default is 'warn'
 
 THANKS
+
     Iain Truskett for writing this in the first place. Andy Lester for
     graciously handing over maintainership. Kent Fredric for adding content
     length handling.
 
 SUPPORT
+
     You can find documentation for this module with the perldoc command.
 
         perldoc WWW::Mechanize::Cached
 
-    *   Search CPAN
+      * Search CPAN
 
-        <https://metacpan.org/module/WWW::Mechanize::Cached>
+      https://metacpan.org/module/WWW::Mechanize::Cached
 
 SEE ALSO
-    WWW::Mechanize, WWW::Mechanize::Cached::GZip.
-
-AUTHORS
-    *   Iain Truskett (original author)
-
-    *   Andy Lester <petdance@cpan.org> (2004 - July 2009)
 
-    *   Olaf Alders <olaf@wundercounter.com> (current maintainer)
-
-COPYRIGHT AND LICENSE
-    This software is copyright (c) 2013 by Iain Truskett and Andy Lester.
-
-    This is free software; you can redistribute it and/or modify it under
-    the same terms as the Perl 5 programming language system itself.
+    WWW::Mechanize, WWW::Mechanize::Cached::GZip.
 
@@ -1,19 +1,24 @@
-requires "CHI" => "0";
 requires "Cache::FileCache" => "0";
 requires "Carp" => "0";
+requires "Class::Load" => "0";
 requires "Data::Dump" => "0";
-requires "Moose" => "0";
+requires "Moo" => "1.004005";
+requires "MooX::Types::MooseLike::Base" => "0";
 requires "Storable" => "2.21";
 requires "WWW::Mechanize" => "0";
+requires "namespace::clean" => "0";
 requires "perl" => "5.006";
 requires "strict" => "0";
 requires "warnings" => "0";
+recommends "CHI" => "0";
 
 on 'build' => sub {
   requires "Module::Build" => "0.28";
 };
 
 on 'test' => sub {
+  requires "CHI" => "0";
+  requires "Cache::FileCache" => "0";
   requires "File::Spec" => "0";
   requires "Find::Lib" => "0";
   requires "HTTP::Request" => "0";
@@ -5,8 +5,8 @@ author  = Olaf Alders <olaf@wundercounter.com> (current maintainer)
 
 license = Perl_5
 copyright_holder = Iain Truskett and Andy Lester
-copyright_year   = 2013
-version = 1.44
+copyright_year   = 2015
+version = 1.46
 main_module = lib/WWW/Mechanize/Cached.pm
 
 [GatherDir]
@@ -42,8 +42,14 @@ web = http://github.com/oalders/www-mechanize-cached/issues
 [AutoPrereqs]
 [RemovePrereqs]
   remove = TestCache
-[Prereqs]
+[Prereqs / RuntimeRequires]
+  Cache::FileCache = 0
   Storable = 2.21
+[Prereqs / TestRequires]
+  CHI = 0
+  Cache::FileCache = 0
+[Prereqs / RuntimeRecommends]
+  CHI = 0
 
 [Test::CPAN::Changes]
 [Test::Perl::Critic]
@@ -52,7 +58,7 @@ web = http://github.com/oalders/www-mechanize-cached/issues
 [ModuleBuild]
 [PodWeaver]
 
-[ContributorsFromGit]
+[Git::Contributors]
 [ContributorsFile]
 [@Git]
 
@@ -60,3 +66,5 @@ web = http://github.com/oalders/www-mechanize-cached/issues
 [CopyFilesFromBuild]
 copy = cpanfile
 copy = README
+
+;authordep Perl::Critic::Nits
@@ -6,7 +6,8 @@ use warnings;
 use WWW::Mechanize::Cached;
 use CHI;
 
-my $cache = CHI->new( driver => 'File',
+my $cache = CHI->new(
+    driver   => 'File',
     root_dir => '/tmp/mech-example'
 );
 
@@ -2,106 +2,72 @@ use strict;
 use warnings FATAL => 'all';
 
 package WWW::Mechanize::Cached;
-$WWW::Mechanize::Cached::VERSION = '1.44';
+$WWW::Mechanize::Cached::VERSION = '1.46';
 use 5.006;
 
-use Moose;
+use Class::Load 'try_load_class';
+use Moo 1.004005;
+use MooX::Types::MooseLike::Base qw(AnyOf Bool Enum Maybe);
+use namespace::clean;
 extends 'WWW::Mechanize';
 
 use Carp qw( carp croak );
 use Data::Dump qw( dump );
 use Storable qw( freeze thaw );
 
-has 'cache'                         => ( is => 'rw', );
-has 'is_cached'                     => ( is => 'rw', );
-has 'positive_cache'                => ( is => 'rw', );
-has 'ref_in_cache_key'              => ( is => 'rw', );
-has 'cache_undef_content_length'    => ( is => 'rw', );
-has 'cache_zero_content_length'     => ( is => 'rw', );
-has 'cache_mismatch_content_length' => ( is => 'rw', );
-has '_verbose_dwarn'                => ( is => 'rw', );
-
-sub new {
-    my $class     = shift;
-    my %mech_args = @_;
-
-    my $cache = delete $mech_args{cache};
-    if ( $cache ) {
-        my $ok
-            = ( ref( $cache ) ne "HASH" )
-            && $cache->can( "get" )
-            && $cache->can( "set" );
-        if ( !$ok ) {
-            carp "The cache param must be an initialized cache object";
-            $cache = undef;
-        }
-    }
+has is_cached => ( is => 'rw', isa => Maybe [Bool], default => undef );
+has positive_cache   => ( is => 'rw', isa => Bool, default => 1 );
+has ref_in_cache_key => ( is => 'rw', isa => Bool, default => 0 );
+has _verbose_dwarn   => ( is => 'rw', isa => Bool, default => 0 );
 
-    my %cached_args = %mech_args;
+for (qw(cache_undef_content_length cache_zero_content_length)) {
+    has $_ =>
+        ( is => 'rw', isa => AnyOf [ Bool, Enum ['warn'] ], default => 0 );
+}
+has cache_mismatch_content_length => (
+    is      => 'rw',
+    isa     => AnyOf [ Bool, Enum ['warn'] ],
+    default => 'warn',
+);
+
+has cache => ( is => 'lazy', isa => \&_isa_warn_cache );
+
+sub _isa_warn_cache {
+    return
+            if 'HASH' ne ref $_[0]
+        and $_[0]->can('get')
+        and $_[0]->can('set');
+    carp 'The cache param must be an initialized cache object';
+    $_[0] = undef;
+}
 
-    my %defaults = (
-        ref_in_cache_key              => 0,
-        positive_cache                => 1,
-        cache_undef_content_length    => 0,
-        cache_zero_content_length     => 0,
-        cache_mismatch_content_length => 'warn',
-        _verbose_dwarn                => 0,
+sub _build_cache {
+    my $self = shift;
+
+    return Cache::FileCache->new(
+        default_expires_in => '1d',
+        namespace          => 'www-mechanize-cached',
+    ) if try_load_class 'Cache::FileCache';
+    return CHI->new(
+        driver     => 'File',
+        expires_in => '1d',
+        namespace  => 'www-mechanize-cached',
+    ) if try_load_class 'CHI';
+
+    croak(    'Could not create a default cache.'
+            . 'Please make sure either CHI or Cache::FileCache are installed or configure manually as appropriate'
     );
-
-    for my $key ( keys %defaults ) {
-        delete $mech_args{$key};
-    }
-
-    my $self = $class->SUPER::new( %mech_args );
-
-    if ( !$cache ) {
-        local $@;
-        if ( eval { require Cache::FileCache; 1 } ) {
-          my $cache_params = {
-              default_expires_in => "1d",
-              namespace          => 'www-mechanize-cached',
-          };
-          $cache = Cache::FileCache->new( $cache_params );
-        } elsif ( eval { require CHI; 1 } ) {
-          my $cache_params = {
-            driver => 'File',
-            expires_in => '1d',
-            namespace => 'www-mechanize-cached',
-          };
-          $cache = CHI->new( %$cache_params );
-        } else {
-          croak("Could not create a default cache." .
-            "Please make sure either CHI or Cache::FileCache are installed or configure manually as appropriate"
-          );
-        }
-    }
-
-    $self->cache( $cache );
-
-    foreach my $arg ( keys %defaults ) {
-        if ( exists $cached_args{$arg} ) {
-            $self->$arg( $cached_args{$arg} );
-        }
-        else {
-            $self->$arg( $defaults{$arg} );
-        }
-    }
-    $self->is_cached( undef );
-
-    return $self;
 }
 
-sub _make_request {
+around _make_request => sub {
+    my ( $orig, $self, $request ) = splice @_, 0, 3;
+    my $req = $request;
 
-    my $self    = shift;
-    my $request = shift;
-    my $req     = $request;
-
-    $self->is_cached( 0 );
+    $self->is_cached(0);
 
     # An odd line to need.
     # No idea what purpose this serves?  OALDERS
-    $self->{proxy} = {} unless defined $self->{proxy};
+    $self->{proxy} = {} unless defined $self->{proxy};    ## no critic
 
     # RT #56757
     if ( !$self->ref_in_cache_key ) {
@@ -110,17 +76,17 @@ sub _make_request {
         $req = $clone->as_string;
     }
 
-    my $response = $self->cache->get( $req );
+    my $response = $self->cache->get($req);
 
-    if ( $response ) {
-        $response = thaw( $response );
+    if ($response) {
+        $response = thaw($response);
     }
-    if ( $self->_cache_ok( $response ) ) {
-        $self->is_cached( 1 );
+    if ( $self->_cache_ok($response) ) {
+        $self->is_cached(1);
         return $response;
     }
 
-    $response = $self->SUPER::_make_request( $request, @_ );
+    $response = $self->$orig( $request, @_ );
 
     # decode strips some important headers.
     my $headers = $response->headers->clone;
@@ -129,12 +95,12 @@ sub _make_request {
 
     # http://rt.cpan.org/Public/Bug/Display.html?id=42693
     $response->decode();
-    delete $response->{handlers};
+    delete $response->{handlers};    ## no critic
 
-    $self->cache->set( $req, freeze( $response ) ) if $should_cache;
+    $self->cache->set( $req, freeze($response) ) if $should_cache;
 
     return $response;
-}
+};
 
 sub _dwarn_filter {
     my ( $ctx, $ref ) = @_;
@@ -150,7 +116,7 @@ sub _dwarn {
     my $self    = shift;
     my $message = shift;
 
-    return unless my $handler = $self->{onwarn};
+    return unless my $handler = $self->{onwarn};    ## no critic
 
     return if $self->quiet;
 
@@ -164,7 +130,7 @@ sub _dwarn {
         return $handler->( Data::Dump::dumpf( $payload, \&_dwarn_filter ) );
     }
     else {
-        return $handler->( $message );
+        return $handler->($message);
     }
 }
 
@@ -179,20 +145,24 @@ sub _response_cache_ok {
     return 0 if $response->code < 200;
     return 0 if $response->code > 301;
 
-    if ( exists $headers->{'client-transfer-encoding'} ) {
-        for my $cte ( @{ $headers->{'client-transfer-encoding'} } ) {
-
-            # Transfer-Encoding = chunked means document consistency
-            # is independent of Content-Length value,
-            # and that Content-Length can be safely ignored.
-            # Its not obvious how the lower levels represent a
-            # failed chuncked-transfer yet.
-            # But its safe to say relying on content-length proves pointless.
-            return 1 if $cte eq 'chunked';
+    my $size;
+    {
+        ## no critic (ValuesAndExpressions::ProhibitAccessOfPrivateData)
+        if ( exists $headers->{'client-transfer-encoding'} ) {
+            for my $cte ( @{ $headers->{'client-transfer-encoding'} } ) {
+
+                # Transfer-Encoding = chunked means document consistency
+                # is independent of Content-Length value,
+                # and that Content-Length can be safely ignored.
+                # Its not obvious how the lower levels represent a
+                # failed chuncked-transfer yet.
+                # But its safe to say relying on content-length proves pointless.
+                return 1 if $cte eq 'chunked';
+            }
         }
-    }
 
-    my $size = $headers->{'content-length'};
+        $size = $headers->{'content-length'};
+    }
 
     if ( not defined $size ) {
         if ( $self->cache_undef_content_length . q{} eq q{warn} ) {
@@ -224,8 +194,7 @@ sub _response_cache_ok {
 
     if (    defined $size
         and $size != 0
-        and $size != length( $response->content ) )
-    {
+        and $size != length( $response->content ) ) {
         if ( $self->cache_mismatch_content_length . "" eq "warn" ) {
             $self->_dwarn(
                 q{Content-Length header did not match contents actual length, not caching}
@@ -254,8 +223,6 @@ sub _cache_ok {
     return 1;
 }
 
-__PACKAGE__->meta->make_immutable( inline_constructor => 0 );
-
 "We miss you, Spoon";    ## no critic
 
 # ABSTRACT: Cache response to be polite
@@ -272,7 +239,7 @@ WWW::Mechanize::Cached - Cache response to be polite
 
 =head1 VERSION
 
-version 1.44
+version 1.46
 
 =head1 SYNOPSIS
 
@@ -482,7 +449,7 @@ Olaf Alders <olaf@wundercounter.com> (current maintainer)
 
 =head1 COPYRIGHT AND LICENSE
 
-This software is copyright (c) 2013 by Iain Truskett and Andy Lester.
+This software is copyright (c) 2015 by Iain Truskett and Andy Lester.
 
 This is free software; you can redistribute it and/or modify it under
 the same terms as the Perl 5 programming language system itself.
@@ -1,5 +1,5 @@
 use Test::More tests => 1;
 
-use_ok( 'WWW::Mechanize::Cached' );
+use_ok('WWW::Mechanize::Cached');
 
-diag( "Testing WWW::Mechanize::Cached $WWW::Mechanize::Cached::VERSION" );
+diag("Testing WWW::Mechanize::Cached $WWW::Mechanize::Cached::VERSION");
@@ -6,18 +6,26 @@ use Test::More;
 
 BEGIN {
     eval "use Test::Warn";
-    plan skip_all => "Test::Warn required for testing invalid cache parms" if $@;
+    plan skip_all => "Test::Warn required for testing invalid cache parms"
+        if $@;
     plan tests => 3;
 }
 
 BEGIN {
-    use_ok( 'WWW::Mechanize::Cached' );
+    use_ok('WWW::Mechanize::Cached');
 }
 
 my $mech;
 
 warning_like {
-    $mech = WWW::Mechanize::Cached->new( cache => { parm => 73 }, autocheck => 1 );
-} qr/cache param/, "Threw the right warning";
+    $mech = WWW::Mechanize::Cached->new(
+        cache     => { parm => 73 },
+        autocheck => 1
+    );
+}
+qr/cache param/, "Threw the right warning";
 
-isa_ok( $mech, "WWW::Mechanize::Cached", "Even with a bad cache, still return a valid object" );
+isa_ok(
+    $mech, "WWW::Mechanize::Cached",
+    "Even with a bad cache, still return a valid object"
+);
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 use strict;
-use warnings FATAL => 'all';
+use warnings FATAL   => 'all';
 use Test::More tests => 2;
 use vars qw( $class );
 
@@ -1,7 +1,7 @@
 #!perl
 
 use strict;
-use warnings FATAL => 'all';
+use warnings FATAL   => 'all';
 use Test::More tests => 14;
 use Test::Requires 'Cache::FileCache';
 
@@ -24,62 +24,66 @@ use Test::Requires 'Cache::FileCache';
 #< Cache-Control: private, max-age=0
 #
 
-use constant URL => 'http://www.wikipedia.org';
+use constant URL  => 'http://www.wikipedia.org';
 use constant SITE => 'Wikipedia';
 
 BEGIN {
-    use_ok( 'WWW::Mechanize::Cached' );
+    use_ok('WWW::Mechanize::Cached');
 }
 
-my $SITE=SITE();
+my $SITE = SITE();
 my $stashpage;
-my $secs = time; # Handy string that will be different between runs
+my $secs        = time;    # Handy string that will be different between runs
 my $cache_parms = {
-    namespace => "www-mechanize-cached-$secs",
+    namespace          => "www-mechanize-cached-$secs",
     default_expires_in => "1d",
 };
 
 FIRST_CACHE: {
-    my $cache = Cache::FileCache->new( $cache_parms );
+    my $cache = Cache::FileCache->new($cache_parms);
     isa_ok( $cache, 'Cache::FileCache' );
 
-    my $mech = WWW::Mechanize::Cached->new( autocheck => 0, cache => $cache, );
+    my $mech
+        = WWW::Mechanize::Cached->new( autocheck => 0, cache => $cache, );
     isa_ok( $mech, 'WWW::Mechanize::Cached' );
 
     ok( !defined( $mech->is_cached ), "No request status" );
 
-    my $first_req = $mech->get( URL );
-    my $first  = $first_req->content;
-    SKIP: {
+    my $first_req = $mech->get(URL);
+    my $first     = $first_req->content;
+SKIP: {
         skip "cannot connect to $SITE", 6 unless $mech->success;
         ok( defined $mech->is_cached, "First request" );
-        ok( !$mech->is_cached, "should be NOT cached" );
+        ok( !$mech->is_cached,        "should be NOT cached" );
         $stashpage = $first;
 
-        my $second = $mech->get( URL )->content;
+        my $second = $mech->get(URL)->content;
         ok( defined $mech->is_cached, "Second request" );
-        ok( $mech->is_cached, "should be cached" );
+        ok( $mech->is_cached,         "should be cached" );
 
-        sleep 3; # 3 due to Referer header
-        my $third  = $mech->get( URL )->content;
+        sleep 3;    # 3 due to Referer header
+        my $third = $mech->get(URL)->content;
         ok( $mech->is_cached, "Third request should be cached" );
 
         is( $second => $third, "Second and third match" );
     }
 }
 
-
 SECOND_CACHE: {
-    my $cache = Cache::FileCache->new( $cache_parms );
+    my $cache = Cache::FileCache->new($cache_parms);
     isa_ok( $cache, 'Cache::FileCache' );
 
     my $mech = WWW::Mechanize::Cached->new( autocheck => 0, cache => $cache );
     isa_ok( $mech, 'WWW::Mechanize::Cached' );
 
-    my $fourth = $mech->get( URL )->content;
-    SKIP: {
+    my $fourth = $mech->get(URL)->content;
+SKIP: {
         skip "cannot connect to $SITE", 2 unless $mech->success;
-        is_deeply( [split /\n/, $fourth], [split /\n/, $stashpage], "Fourth request matches..." );
+        is_deeply(
+            [ split /\n/, $fourth ],
+            [ split /\n/, $stashpage ],
+            "Fourth request matches..."
+        );
         ok( $mech->is_cached, "... because it's from the same cache" );
     }
 }
@@ -21,24 +21,29 @@ use Test::More tests => 4;
 #< Date: Wed, 23 May 2012 10:09:55 GMT
 #< Expires: -1
 #< Cache-Control: private, max-age=0
-use constant URL => 'http://www.wikipedia.org';
+use constant URL  => 'http://www.wikipedia.org';
 use constant SITE => 'Wikipedia';
 use TestCache;
 
-my $SITE=SITE();
+my $SITE = SITE();
+
 BEGIN {
-    use_ok( 'WWW::Mechanize::Cached' );
+    use_ok('WWW::Mechanize::Cached');
 }
 
 my $cache = TestCache->new();
 isa_ok( $cache, 'TestCache' );
 
-my $mech = WWW::Mechanize::Cached->new( cache => $cache, autocheck => 0, _verbose_dwarn => 1);
+my $mech = WWW::Mechanize::Cached->new(
+    cache          => $cache,
+    autocheck      => 0,
+    _verbose_dwarn => 1
+);
 isa_ok( $mech, 'WWW::Mechanize::Cached' );
 
-my $first  = $mech->get( URL );
-my $second = $mech->get( URL );
-my $third  = $mech->get( URL );
+my $first  = $mech->get(URL);
+my $second = $mech->get(URL);
+my $third  = $mech->get(URL);
 
 SKIP: {
     skip "cannot connect to $SITE", 1 unless $mech->success;
@@ -1,7 +1,7 @@
 #!perl
 
 use strict;
-use warnings FATAL => 'all';
+use warnings FATAL   => 'all';
 use Test::More tests => 14;
 use Test::Requires 'CHI';
 
@@ -24,19 +24,19 @@ use Test::Requires 'CHI';
 #< Cache-Control: private, max-age=0
 #
 
-use constant URL => 'http://www.wikipedia.org';
+use constant URL  => 'http://www.wikipedia.org';
 use constant SITE => 'Wikipedia';
 
 BEGIN {
-    use_ok( 'WWW::Mechanize::Cached' );
+    use_ok('WWW::Mechanize::Cached');
 }
 
-my $SITE=SITE();
+my $SITE = SITE();
 my $stashpage;
-my $secs = time; # Handy string that will be different between runs
+my $secs        = time;    # Handy string that will be different between runs
 my $cache_parms = {
-    driver => "File",
-    namespace => "www-mechanize-cached-$secs",
+    driver             => "File",
+    namespace          => "www-mechanize-cached-$secs",
     default_expires_in => "1d",
 };
 
@@ -44,32 +44,32 @@ FIRST_CACHE: {
     my $cache = CHI->new( %{$cache_parms} );
     isa_ok( $cache, 'CHI::Driver' );
 
-    my $mech = WWW::Mechanize::Cached->new( autocheck => 0, cache => $cache, );
+    my $mech
+        = WWW::Mechanize::Cached->new( autocheck => 0, cache => $cache, );
     isa_ok( $mech, 'WWW::Mechanize::Cached' );
 
     ok( !defined( $mech->is_cached ), "No request status" );
 
-    my $first_req = $mech->get( URL );
-    my $first  = $first_req->content;
-    SKIP: {
+    my $first_req = $mech->get(URL);
+    my $first     = $first_req->content;
+SKIP: {
         skip "cannot connect to $SITE", 6 unless $mech->success;
         ok( defined $mech->is_cached, "First request" );
-        ok( !$mech->is_cached, "should be NOT cached" );
+        ok( !$mech->is_cached,        "should be NOT cached" );
         $stashpage = $first;
 
-        my $second = $mech->get( URL )->content;
+        my $second = $mech->get(URL)->content;
         ok( defined $mech->is_cached, "Second request" );
-        ok( $mech->is_cached, "should be cached" );
+        ok( $mech->is_cached,         "should be cached" );
 
-        sleep 3; # 3 due to Referer header
-        my $third  = $mech->get( URL )->content;
+        sleep 3;    # 3 due to Referer header
+        my $third = $mech->get(URL)->content;
         ok( $mech->is_cached, "Third request should be cached" );
 
         is( $second => $third, "Second and third match" );
     }
 }
 
-
 SECOND_CACHE: {
     my $cache = CHI->new( %{$cache_parms} );
     isa_ok( $cache, 'CHI::Driver' );
@@ -77,10 +77,14 @@ SECOND_CACHE: {
     my $mech = WWW::Mechanize::Cached->new( autocheck => 0, cache => $cache );
     isa_ok( $mech, 'WWW::Mechanize::Cached' );
 
-    my $fourth = $mech->get( URL )->content;
-    SKIP: {
+    my $fourth = $mech->get(URL)->content;
+SKIP: {
         skip "cannot connect to $SITE", 2 unless $mech->success;
-        is_deeply( [split /\n/, $fourth], [split /\n/, $stashpage], "Fourth request matches..." );
+        is_deeply(
+            [ split /\n/, $fourth ],
+            [ split /\n/, $stashpage ],
+            "Fourth request matches..."
+        );
         ok( $mech->is_cached, "... because it's from the same cache" );
     }
 }
@@ -13,18 +13,18 @@ sub new {
 }
 
 sub set {
-    my $self = shift;
-    my $key = shift;
-    my $value = shift; # an HTTP::Response
+    my $self  = shift;
+    my $key   = shift;
+    my $value = shift;    # an HTTP::Response
 
-    my $res = thaw( $value );
-    $res->content( "DUMMY" );
+    my $res = thaw($value);
+    $res->content("DUMMY");
     $self->{$key} = freeze($res);
 }
 
 sub get {
     my $self = shift;
-    my $key = shift;
+    my $key  = shift;
 
     return $self->{$key};
 }
@@ -13,7 +13,7 @@ use Test::More tests => 64;
 use TestCache;
 
 BEGIN {
-    use_ok( 'WWW::Mechanize::Cached' );
+    use_ok('WWW::Mechanize::Cached');
 }
 
 my $cache = TestCache->new();
@@ -22,39 +22,44 @@ isa_ok( $cache, 'TestCache' );
 my $mech = WWW::Mechanize::Cached->new( cache => $cache, autocheck => 1, );
 isa_ok( $mech, 'WWW::Mechanize::Cached' );
 
-ok( !$mech->ref_in_cache_key, "Referring URLs in cache key disabled by default" );
+ok(
+    !$mech->ref_in_cache_key,
+    "Referring URLs in cache key disabled by default"
+);
 
-my @iter = ( 1..10 );
-foreach my $i ( @iter ) {
-    $mech->get( page_url( $i ) );
+my @iter = ( 1 .. 10 );
+foreach my $i (@iter) {
+    $mech->get( page_url($i) );
     cmp_ok( $mech->content, '==', $i, "page $i has correct content" );
-    ok( !$mech->is_cached, "page $i NOT in cache");
+    ok( !$mech->is_cached, "page $i NOT in cache" );
 }
 
-
-check_cache( @iter );
+check_cache(@iter);
 
 diag("reversing page order");
 
 check_cache( reverse @iter );
 
 sub check_cache {
-    
+
     my @pages = @_;
-    foreach my $i ( @pages ) {
-        $mech->get( page_url( $i ) );
-        cmp_ok( $mech->content, 'eq', 'DUMMY', "page $i has correct content" );
-        ok( $mech->is_cached, "page $i IS in cache");
-    }    
+    foreach my $i (@pages) {
+        $mech->get( page_url($i) );
+        cmp_ok(
+            $mech->content, 'eq', 'DUMMY',
+            "page $i has correct content"
+        );
+        ok( $mech->is_cached, "page $i IS in cache" );
+    }
 }
 
 sub page_url {
-    
-    my $i = shift;
+
+    my $i      = shift;
     my $prefix = 'file://';
     $prefix .= '/' if $^O =~ m{Win};
-    return $prefix . File::Spec->catfile(Find::Lib::base(), 'pages', "$i.html");
-    
-}
+    return $prefix
+        . File::Spec->catfile( Find::Lib::base(), 'pages', "$i.html" );
 
+}
 
@@ -7,17 +7,23 @@ use HTTP::Request;
 use Test::More tests => 6;
 
 BEGIN {
-    use_ok( 'WWW::Mechanize::Cached' );
+    use_ok('WWW::Mechanize::Cached');
 }
 
 my $mech = WWW::Mechanize::Cached->new;
 
-my $response = HTTP::Response->new( '200' );
+my $response = HTTP::Response->new('200');
 
 cmp_ok( $mech->positive_cache, '==', 1, "positive cache is ON" );
-ok( $mech->_cache_ok( $response ), "200 is always cachable" );
-ok( !$mech->_cache_ok( HTTP::Response->new( 404 ) ), "won't cache 404 when positive");
+ok( $mech->_cache_ok($response), "200 is always cachable" );
+ok(
+    !$mech->_cache_ok( HTTP::Response->new(404) ),
+    "won't cache 404 when positive"
+);
 
-$mech->positive_cache( 0 );
-ok( $mech->_cache_ok( $response ), "200 is cachable in negative cache" );
-ok( $mech->_cache_ok( HTTP::Response->new( 404 ) ), "will cache 404 when negative");
+$mech->positive_cache(0);
+ok( $mech->_cache_ok($response), "200 is cachable in negative cache" );
+ok(
+    $mech->_cache_ok( HTTP::Response->new(404) ),
+    "will cache 404 when negative"
+);
@@ -6,7 +6,7 @@ use warnings;
 use Test::More tests => 2;
 
 BEGIN {
-    use_ok( 'WWW::Mechanize::Cached' );
+    use_ok('WWW::Mechanize::Cached');
 }
 
 my $mech = WWW::Mechanize::Cached->new;