[Bps-public-commit] r19843 - Net-Google-Code/trunk/lib/Net/Google/Code/Role

jesse at bestpractical.com jesse at bestpractical.com
Tue Jun 2 20:29:43 EDT 2009


Author: jesse
Date: Tue Jun  2 20:29:43 2009
New Revision: 19843

Modified:
   Net-Google-Code/trunk/lib/Net/Google/Code/Role/Fetchable.pm

Log:
Switch mech to be a single shared global and turn on the connection cache

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Role/Fetchable.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Role/Fetchable.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/Fetchable.pm	Tue Jun  2 20:29:43 2009
@@ -2,23 +2,24 @@
 use Moose::Role;
 use Params::Validate ':all';
 use WWW::Mechanize;
+use LWP::ConnCache;
 use Encode;
 
-has 'mech' => (
-    isa     => 'WWW::Mechanize',
-    is      => 'ro',
-    lazy    => 1,
-    default => sub {
-        my $self = shift;
-        my $m    = WWW::Mechanize->new(
+our $MECH;
+
+sub mech { 
+    
+    if (!$MECH) { 
+        $MECH = WWW::Mechanize->new(
             agent       => 'Net-Google-Code',
+            conn_cache  => LWP::ConnCache->new(),
             cookie_jar  => {},
             stack_depth => 1,
             timeout     => 60,
         );
-        return $m;
     }
-);
+    return $MECH ;
+}
 
 sub fetch {
     my $self = shift;



More information about the Bps-public-commit mailing list