1package Net::Riak::Role::UserAgent; 2{ 3 $Net::Riak::Role::UserAgent::VERSION = '0.1702'; 4} 5{ 6 $Net::Riak::Role::UserAgent::VERSION = '0.1600'; 7} 8 9# ABSTRACT: useragent for Net::Riak 10 11use Moose::Role; 12use LWP::UserAgent; 13use LWP::ConnCache; 14use IO::Socket::SSL; 15use Data::Dumper; 16 17our $CONN_CACHE; 18 19sub connection_cache { $CONN_CACHE ||= LWP::ConnCache->new } 20 21has ua_timeout => ( 22 is => 'rw', 23 isa => 'Int', 24 default => 120 25); 26 27has ssl_opts => ( 28 is => 'rw', 29 isa => 'HashRef' 30); 31 32has useragent => ( 33 is => 'rw', 34 isa => 'LWP::UserAgent', 35 lazy => 1, 36 default => sub { 37 my $self = shift; 38 39 # The Links header Riak returns (esp. for buckets) can get really long, 40 # so here increase the MaxLineLength LWP will accept (default = 8192) 41 my %opts = @LWP::Protocol::http::EXTRA_SOCK_OPTS; 42 $opts{MaxLineLength} = 65_536; 43 @LWP::Protocol::http::EXTRA_SOCK_OPTS = %opts; 44 my $ua = undef; 45 46 if ( !$self->ssl ) { 47 $ua = LWP::UserAgent->new( 48 timeout => $self->ua_timeout, 49 keep_alive => 1, 50 ); 51 } else { 52 $ua = LWP::UserAgent->new( 53 timeout => $self->ua_timeout, 54 keep_alive => 1, 55 ssl_opts => $self->ssl_opts 56 ); 57 } 58 59 $ua->conn_cache(__PACKAGE__->connection_cache); 60 61 $ua; 62 } 63); 64 651; 66 67__END__ 68 69=pod 70 71=head1 NAME 72 73Net::Riak::Role::UserAgent - useragent for Net::Riak 74 75=head1 VERSION 76 77version 0.1702 78 79=head1 AUTHOR 80 81franck cuny <franck@lumberjaph.net>, robin edwards <robin.ge@gmail.com> 82 83=head1 COPYRIGHT AND LICENSE 84 85This software is copyright (c) 2013 by linkfluence. 86 87This is free software; you can redistribute it and/or modify it under 88the same terms as the Perl 5 programming language system itself. 89 90=cut 91