diff options
author | franck cuny <franck@lumberjaph.net> | 2011-03-24 14:30:10 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2011-07-26 13:19:59 +0200 |
commit | 64b9434622830edc51553b87348174e3b423cdde (patch) | |
tree | be9928956997202ac5cff559b62202e9fd30d43b | |
parent | set a default value to 0 for trace attribute in debug role (diff) | |
download | net-http-spore-64b9434622830edc51553b87348174e3b423cdde.tar.gz |
basic role for SPORE
Signed-off-by: franck cuny <franck@lumberjaph.net>
-rw-r--r-- | lib/Net/HTTP/Spore/Role.pm | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/Net/HTTP/Spore/Role.pm b/lib/Net/HTTP/Spore/Role.pm new file mode 100644 index 0000000..ed33995 --- /dev/null +++ b/lib/Net/HTTP/Spore/Role.pm @@ -0,0 +1,56 @@ +package Net::HTTP::Spore::Role; + +use MooseX::Role::Parameterized; +use Net::HTTP::Spore; + +parameter name => (isa => 'Str', required => 1); +parameter config => (isa => 'Str', required => 1); + +role { + my $p = shift; + my $name = $p->name; + my $config = $p->config; + + has $name => ( + is => 'rw', + isa => 'Object', + lazy => 1, + default => sub { + my $self = shift; + my $client_config = $self->$config; + my $client = Net::HTTP::Spore->new_from_spec( + $client_config->{spec}, + %{ $client_config->{options} }, + ); + foreach my $mw ( @{ $client_config->{middlewares} } ) { + $client->enable($mw); + } + $client; + }, + ); + + has $config => ( + is => 'rw', + isa => 'HashRef', + lazy => 1, + default => sub { {} }, + ); +}; + +1; + +=head1 NAME + +Net::HTTP::Spore::Role + +=head1 DESCRIPTION + +=head1 SYNOPSIS + + package my::app; + use Moose; + with Net::HTTP::Spore::Role => {name => 'twitter', config => 'twitter_config'}; + + ... + + my $app = my::app->new(twitter_config => $config->{spore}->{twitter_config}); |