From 0ce9554937e19d7c0045a68bc0c4184c84c236c4 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Wed, 2 Jun 2010 11:37:02 +0200 Subject: role to handle useragent --- lib/MooseX/Net/API/Role/UserAgent.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/MooseX/Net/API/Role/UserAgent.pm (limited to 'lib/MooseX/Net/API/Role/UserAgent.pm') diff --git a/lib/MooseX/Net/API/Role/UserAgent.pm b/lib/MooseX/Net/API/Role/UserAgent.pm new file mode 100644 index 0000000..0c11732 --- /dev/null +++ b/lib/MooseX/Net/API/Role/UserAgent.pm @@ -0,0 +1,24 @@ +package MooseX::Net::API::Role::UserAgent; + +use Moose::Role; +use LWP::UserAgent; + +has api_useragent => ( + is => 'rw', + isa => 'LWP::UserAgent', + lazy => 1, + default => sub { + my $self = shift; + my $ua = $self->meta->get_option('useragent'); + return $ua->() if $ua; + $ua = LWP::UserAgent->new(); + $ua->agent( + "MooseX::Net::API " . $MooseX::Net::API::VERSION . " (Perl)"); + $ua->env_proxy; + return $ua; + } +); + +1; + +__END__ -- cgit 1.4.1