use strict;

my $VERSION = '1.16';


=head1 NAME

cpanstats-storage - script to return the internal JSON storage object.


  perl cpanstats-storage


Using the CPAN Testers Statistics local JSON storage, extracts all the JSON 
data for a specific type, and returns it.


# -------------------------------------
# Library Modules

use lib qw(./lib ../lib);

use CPAN::Testers::WWW::Statistics;
use Data::Dumper;
use Getopt::ArgvFile default=>1;
use Getopt::Long;

# -------------------------------------
# Variables

my (%options);

# -------------------------------------
# Program


my $stats = CPAN::Testers::WWW::Statistics->new(
        config    => $options{config},
        directory => $options{directory},
        templates => $options{templates},
        address   => $options{address},
        logfile   => $options{logfile},
        logclean  => $options{logclean}

if($options{type}) { 
    my $store = $stats->storage($options{type});
    if($options{path}) { 
        my @keys = split('/',$options{path});
        for(@keys) {
            exit(0) unless($store->{$_});
            $store = $store->{$_};

    if($options{keys}) {
        print join("\n",keys %$store) . "\n";
    } else {
        print Dumper($store);

# -------------------------------------
# Subroutines


=over 4

=item init_options

Prepare command line options.

=item help

Display the help screen.



sub init_options {
    GetOptions( \%options,

    ) or help(1);

    help(1) if($options{help});
    help(0) if($options{version});

    $options{type} = shift @ARGV    unless($options{type});
    $options{path} = shift @ARGV    unless($options{path});
    help(1)                         unless($options{type});

sub help {
    my $full = shift;

    if($full) {
        print "\n";
        print "Usage:$0 --config=<file> \\\n";
        print "         [--templates=<dir>]   \\\n";
        print "         [--directory=<dir>]   \\\n";
        print "         [--address|a=<file>]  \\\n";
        print "         [--logfile=<file> [--logclean=<1|0>]] \\\n";
        print "         [--type=<type> | <type>] [--keys] \\\n";
        print "         [--path=<path> | <path>] \\\n";
        print "         [--help|h] [--version|v] \n\n";

#              12345678901234567890123456789012345678901234567890123456789012345678901234567890
        print "This program builds the CPAN Testers Statistics website.\n";

        print "\nFunctional Options:\n";
        print "  [--config=<file>]          # path to config file [required]\n";
        print "  [--templates=<dir>]        # path to templates\n";
        print "  [--directory=<dir>]        # path to website directory\n";
        print "  [--address=<file>]         # path to address file\n";
        print "  [--logfile=<file>]         # path to logfile\n";
        print "  [--logclean]		    # overwrite log if specified\n";

        print "\nRun Mode Options:\n";
        print "  [--type=<type>]            # data type to return [e.g. osname, platform, etc]\n";
        print "  [--path=<path>]            # data path to return [e.g. 'monthly/200904', default is top level]\n";
        print "  [--keys]                   # only list keys for the current level\n";

        print "\nOther Options:\n";
        print "  [--version]                # program version\n";
        print "  [--help]                   # this screen\n";

        print "\nFor further information type 'perldoc $0'\n";

    print "$0 v$VERSION\n";



CPAN Testers wouldn't exist without the help and support of the Perl 
community. However, since 2008 CPAN Testers has grown far beyond the 
expectations of it's original creators. As a consequence it now requires
considerable funding to help support the infrastructure.

In early 2012 the Enlightened Perl Organisation very kindly set-up a
CPAN Testers Fund within their donatation structure, to help the project
cover the costs of servers and services.

If you would like to donate to the CPAN Testers Fund, please follow the link
below to the Enlightened Perl Organisation's donation site.


If your company would like to support us, you can donate financially via the
fund link above, or if you have servers or services that we might use, please
send an email to admin@cpantesters.org with details.

Our full list of current sponsors can be found at our I <3 CPAN Testers site.



There are no known bugs at the time of this release. However, if you spot a
bug or are experiencing difficulties, that is not explained within the POD
documentation, please send bug reports and patches to the RT Queue (see below).

Fixes are dependent upon their severity and my availability. Should a fix not
be forthcoming, please feel free to (politely) remind me.

RT Queue -

=head1 SEE ALSO



=head1 AUTHOR

  Barbie, <barbie@cpan.org>
  for Miss Barbell Productions <http://www.missbarbell.co.uk>.


  Copyright (C) 2005-2014 Barbie for Miss Barbell Productions.

  This module is free software; you can redistribute it and/or
  modify it under the same terms as Perl itself.