summaryrefslogblamecommitdiff
path: root/lib/Net/Riak/Role/Hosts.pm
blob: 639d4722a50deb22ed64a35e857f72dfc310180f (plain) (tree)
1
2
3
4
5
6
7
8
9


                               
                                  


                    
                        
                 
                                       















                                              
package Net::Riak::Role::Hosts;

use Moose::Role;
use Net::Riak::Types qw(RiakHost);

has host => (
    is      => 'rw',
    isa     => RiakHost,
    coerce  => 1,
    default => 'http://127.0.0.1:8098',
);

sub get_host {
    my $self = shift;

    my $choice;
    my $rand = rand;

    for (@{$self->host}) {
        $choice = $_->{node};
        ($rand -= $_->{weight}) <= 0 and last;
    }
    $choice;
}

1;