Cache-Memcached-Managed

 view release on metacpan or  search on metacpan

lib/Cache/Memcached/Managed.pm  view on Meta::CPAN

sub start {

# Obtain the object
# Obtain the servers to start

    my $self = shift;
    @_ = $self->servers unless @_;

# Initialize started counter
# For all of the servers to start
#  Obtain IP and port
#  Increment counter if start was successful
    
    my $started = 0;
    foreach (@_) {
        my ($ip,$port) = split ':';
        $started++ unless system 'memcached',
         '-d','-u',(scalar getpwuid $>),'-l',$ip,'-p',$port;
    }

# Return whether all servers started

    $started == @_;
} #start

#---------------------------------------------------------------------------
# stats
#
# Return a hash ref with simple statistics for each server
#
#  IN: 1 instantiated object
#      2..N config specifications of servers (default: all)
# OUT: 1 hash reference
#
# $stats
#   |-- server
#        |-- key
#             |-- value

sub stats {

# Obtain the object
# Return now if no active servers anymore

    my $self = shift;
    return {} unless $self->_check_socket;

# Create hash with configs to be done
# Initialize the result ref
# For all of the objects that we have
#  For all of the servers we want to do this
#   Reloop if not to be done
#   Obtain STATS info

    my %todo = @_ ? map {$_ => undef} @_ : %{$self->servers};
    my %result;
    foreach my $cache ($self->data,$self->directory) {
        foreach my $host ( $self->servers ) {
            next unless exists $todo{$host} and not exists $result{$host};
            $result{$host} = {
             map {s#^STAT ##; split m#\s+#}
             $self->_morelines( $cache,$host,"stats" )
            };
        }
    }

# Return the result hash as a ref

    \%result;
} #stats

#---------------------------------------------------------------------------
# stop
#
# Stop the indicated memcached backend servers
#
#  IN: 1 instantiated object
#      2..N config of memcached servers to stop (default: all)
# OUT: 1 whether all indicated memcached servers stopped

sub stop {

# Obtain the object
# Obtain the pid's to kill
# Return whether all were killed

    my $self = shift;
    my @pid = map {$_->{'pid'}} grep {$_->{'pid'}} values %{$self->stats( @_ )};
    @pid == kill 15,@pid;
} #stop

#---------------------------------------------------------------------------
# version
#
# Return version information of running memcached backend servers
#
#  IN: 1 instantiated object
#      2..N config of memcached servers to obtain version of (default: all)
# OUT: 1 hash ref with version info, keyed to config

sub version {

# Obtain the object
# Obtain the basic info to work with
# Normalize to version information

    my $self = shift;
    my $stats = $self->stats( @_ );
    $_ = $_->{'version'} foreach values %{$stats};

# Return the resulting hash reference

    $stats;
} #version

#---------------------------------------------------------------------------
#
# Internal methods
#
#---------------------------------------------------------------------------
# _data_key



( run in 0.906 second using v1.01-cache-2.11-cpan-483215c6ad5 )