diff options
author | franck cuny <franck@lumberjaph.net> | 2011-03-24 15:35:26 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2011-07-26 13:19:59 +0200 |
commit | 36f54fda1d85f5ebe974b37eb76ddbe00b132c64 (patch) | |
tree | a3e01039ebd86d05b2c1f951a7cc5e30ad6ce7d1 | |
parent | basic role for SPORE (diff) | |
download | net-http-spore-36f54fda1d85f5ebe974b37eb76ddbe00b132c64.tar.gz |
multiple clients
Signed-off-by: franck cuny <franck@lumberjaph.net>
-rw-r--r-- | lib/Net/HTTP/Spore/Role.pm | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/lib/Net/HTTP/Spore/Role.pm b/lib/Net/HTTP/Spore/Role.pm index ed33995..fae079d 100644 --- a/lib/Net/HTTP/Spore/Role.pm +++ b/lib/Net/HTTP/Spore/Role.pm @@ -3,38 +3,42 @@ 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); +parameter spore_clients => (isa => 'ArrayRef[HashRef]', 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 { {} }, - ); + my $p = shift; + my $clients = $p->spore_clients; + + foreach my $client (@$clients) { + my $name = $client->{name}; + my $config = $client->{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} } ) { + my %options = %{$mw->{options} || {}}; + $client->enable( $mw->{name}, %options); + } + $client; + }, + ); + + has $config => ( + is => 'rw', + isa => 'HashRef', + lazy => 1, + default => sub { {} }, + ); + } }; 1; |