#!/usr/bin/perl -w

use warnings;
use strict;

use CipUX::CAT::Web::Plugin;

# USAGE: $0
# USAGE: $0 hash
# USAGE: $0 single index.cgi
# USAGE: $0 all
my $arg = shift;
$arg = q{} if not defined $arg;
chomp $arg;
my $module = shift;
$module = q{} if not defined $module;
chomp $module;

my $plugin = CipUX::CAT::Web::Plugin->new();
$plugin->init();

# simple interface
if ( $arg eq q{} ) {
    print "All available CipUX CAT Web modules:\n";
    my @module = $plugin->get_module_name_register();
    foreach my $m (@module) {
        print "Found CAT module [$m]\n";
    }
}

# hash interface
if ( $arg eq 'hash' ) {
    my $p_hr = $plugin->get_module_name_register();
    foreach my $o ( sort keys %{$p_hr} ) {
        print "MODULE [$o] povided by [$p_hr->{$o}]\n";
    }
}

# single interface
if ( $arg and $module ) {
    print "Single module $module:\n";
    my $m_hr = $plugin->get_module_cfg_register( { name => $module } );

    foreach my $attr ( sort keys %{$m_hr} ) {
        if ( ref $m_hr->{$attr} eq 'ARRAY' ) {
            print "$module [$attr]:\n";
            foreach my $v ( @{ $m_hr->{$attr} } ) {
                print "    [$v]\n";
            }
        }
        else {
            print "$module [$attr]=[$m_hr->{$attr}]\n";
        }
    }
}

# all interface
if ( $arg eq 'all' ) {

    my $c_hr = $plugin->get_module_cfg_register();
    foreach my $o ( sort keys %{$c_hr} ) {
        my $cfg_hr = $c_hr->{$o};
        print "CFG of [$o] is: [$cfg_hr]\n";
        foreach my $attr ( sort keys %{$cfg_hr} ) {
            print "  ATTR [$attr] VALUE [$cfg_hr->{$attr}]\n";
        }

    }
}
exit 0;
