#!/usr/bin/env perl

use strict;
use warnings;
use 5.008_001;

use Pod::Usage;

use version; our $VERSION = 'v0.9.1';

use App::Memcached::Tool::CLI;

if (__FILE__ eq $0) {
    main()
} else {
    return 1;
}

sub main {
    my $Cli_Class = 'App::Memcached::Tool::CLI';
    my $params = $Cli_Class->parse_args;
    exit 1 unless $params->{mode};
    pod2usage(-verbose => 1) if $params->{mode} eq 'help';
    pod2usage(-verbose => 2) if $params->{mode} eq 'man';
    $Cli_Class->new(%$params)->run
}

__END__

=encoding utf-8

=head1 NAME

B<memcached-tool> - A porting of L<memcached/memcached-tool|https://github.com/memcached/memcached/blob/master/scripts/memcached-tool>

=head1 SYNOPSIS

General:

    # Ported style from original memcached-tool
    memcached-tool <host[:port] | /path/to/socket> [mode] [options]

    # Without 1st arg, connects 127.0.0.1:11211 by default
    memcached-tool [mode] [options]

    # You can provide <addr> or <mode> by option style
    memcached-tool --addr|-a <host[:port] | /path/to/socket> --mode|-m <mode> [options]
    memcached-tool --mode|-m <mode> [options]

Modes Summary:

    memcached-tool [addr] [options]          # same with 'display'
    memcached-tool [addr] display  [options] # show slabs
    memcached-tool [addr] stats    [options] # show general stats
    memcached-tool [addr] settings [options] # show settings stats
    memcached-tool [addr] dump     [options] # dumps keys and values

Mode for Development:

    memcached-tool [addr] sizes [options]    # shows sizes stats

Type C<memcached-tool man> to check the risk of this command.

Help or Manual:

    memcached-tool help|-h|--help
    memcached-tool man|--man

=head1 DESCRIPTION

This script is a porting of
L<memcached/memcached-tool|https://github.com/memcached/memcached/blob/master/scripts/memcached-tool>
which is in the public domain.

Follwing description comes from man(1) of original I<memcached-tool>:

The first parameter specifies the address of the daemon either by a hostname,
optionally followed by the port number (the default is 11211), or a path to
UNIX domain socket. The second parameter specifies the mode in which the tool
should run.

=head1 MODES

Following description comes from man(1) or usage of original I<memcached-tool>.

=over 4

=item B<display>

Print slab class statistics. This is the default mode if no mode is specified.
The printed columns are:

=over 4

=item B<#>

Number of the slab class.

=item B<Item_Size>

The amount of space each chunk uses. One item uses one chunk of the
appropriate size.

=item B<Max_age>

Age of the oldest item in the LRU.

=item B<Pages>

Total number of pages allocated to the slab class.

=item B<Count>

Number of items presently stored in this class. Expired items are not
automatically excluded.

=item B<Full?>

Yes if there are no free chunks at the end of the last allocated page.

=item B<Evicted>

Number of times an item had to be evicted from the LRU before it expired.

=item B<Evict_Time>

Seconds since the last access for the most recent item evicted from this
class.

=item B<OOM>

Number of times the underlying slab class was unable to store a new item.

=back

=item B<stats>

Print general-purpose statistics of the daemon. Each line contains the name of
the statistic and its value.

=item B<dump>

Make a partial dump of the cache written in the add statements of the
memcached protocol.

=item B<settings>

Show settings stats.

=item B<sizes>

Shows sizes stats.

B<WARNING>: This is a development command.

As of 1.4 it is still the only command which will lock your memcached instance
for some time.

If you have many millions of stored items, it can become unresponsive for several
minutes.

Run this at your own risk. It is roadmapped to either make this feature optional
or at least speed it up.

=back

=head1 OPTIONS

=over 4

=item B<-t|--timeout=Int>

Sets connection timeout. Default is 5 seconds.

=item B<-d|--debug>

Shows debug logs.

=back

=head1 SEE ALSO

L<App::Memcached::Tool>,
B<memcached(1)>,
L<http://www.memcached.org/>

=head1 AUTHORS

YASUTAKE Kiyoshi E<lt>yasutake.kiyoshi@gmail.comE<gt>

=head1 LICENSE

Copyright (C) 2015 YASUTAKE Kiyoshi.

This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.  That means either (a) the GNU General Public
License or (b) the Artistic License.

=cut

