#!/usr/bin/perl -w -T
# +=========================================================================+
# || cipux_configuration                                                   ||
# ||                                                                       ||
# || Prints CipUX configuration to STDOUT.                                 ||
# ||                                                                       ||
# || Copyright (C) 2009 by Christian Kuelker                               ||
# ||                                                                       ||
# || License: GNU GPL version 2 or any later version.                      ||
# ||                                                                       ||
# +=========================================================================+
# ID:       $Id$
# Revision: $Revision$
# Head URL: $HeadURL$
# Date:     $Date$
# Source:   $Source$

package cipux_configuration;    ## no critic (Capitalization)

use strict;
use warnings;
use Carp;
use CipUX;
use Data::Dumper;
use English qw( -no_match_vars );
use Log::Log4perl qw(get_logger :levels);
use YAML::Any;

use version; our $VERSION = qv('3.4.0.5');
delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)};    # Make %ENV safer

my $debug = 0;

if ( $debug == 1 ) {
    Log::Log4perl->init_once('/etc/cipux/log4perl.conf');
}
my $logger = get_logger(__PACKAGE__);
$logger->debug('BEGIN');

my $cipux = CipUX->new();

# +=========================================================================+
# || extensions                                                            ||
# +=========================================================================+
my @ext = sort $cipux->cfg_ext();

my $ext_hr = {};
$ext_hr->{extension} = \@ext;

$cipux->out("# === CipUX (supported configuration extensions) ===\n");
print YAML::Any::Dump($ext_hr) or croak "Can not print to STDOUT!\n";

# +=========================================================================+
# || cipux                                                                 ||
# +=========================================================================+

my $cfg_hr = $cipux->cfg();    # pkg

$cipux->out("# === CipUX (scope cipux) ===\n");
print YAML::Any::Dump($cfg_hr) or croak "Can not print to STDOUT!\n";
$logger->debug( 'cfg_hr: ', { filter => \&Dumper, value => $cfg_hr } );

# +=========================================================================+
# || storage                                                               ||
# +=========================================================================+
eval { require CipUX::Storage };

if ( not $EVAL_ERROR ) {

    my $storage = CipUX::Storage->new();

    my $storage_cfg_hr = $storage->get_storage_cfg();
    my $out_cfg_hr     = {};
    $out_cfg_hr->{structure} = $storage_cfg_hr;

    $cipux->out("# === CipUX::Storage structure (scope structure) ===\n");
    print YAML::Any::Dump($out_cfg_hr) or croak "Can not print to STDOUT!\n";

    my $access_cfg_hr = $storage->get_access_cfg();

# will not print access info as default
# $cipux->out("# === CipUX::Storage access (scope ldap) ===\n");
# print YAML::Any::Dump($access_cfg_hr) or croak "Can not print to STDOUT!\n";
}

# +=========================================================================+
# || object                                                                ||
# +=========================================================================+
eval { require CipUX::Object::Action };

if ( not $EVAL_ERROR ) {

    my $object          = CipUX::Object::Action->new();
    my $coupling_cfg_hr = $object->get_coupling_cfg();

    $cipux->out(
        "# === CipUX::Object::Action coupling (scope coupling) ===\n");
    print YAML::Any::Dump($coupling_cfg_hr)
        or croak "Can not print to STDOUT!\n";

    my $object_cfg_hr = $object->get_object_cfg();

    $cipux->out("# === CipUX::Object::Action object (scope object) ===\n");
    print YAML::Any::Dump($object_cfg_hr)
        or croak "Can not print to STDOUT!\n";

    my $basis_cfg_hr = $object->get_basis_cfg();

    $cipux->out("# === CipUX::Object::Action basis (scope basis) ===\n");
    print YAML::Any::Dump($basis_cfg_hr)
        or croak "Can not print to STDOUT!\n";

}

# +=========================================================================+
# || task                                                                  ||
# +=========================================================================+
eval { require CipUX::Task };

if ( not $EVAL_ERROR ) {

    my $task = CipUX::Task->new();

    my $task_api_cfg_hr = $task->get_task_api_cfg();
    my $out_cfg_hr      = {};
    $out_cfg_hr->{task_api} = $task_api_cfg_hr;

    $cipux->out("# === CipUX::Task task (scope task_api) ===\n");
    print YAML::Any::Dump($out_cfg_hr) or croak "Can not print to STDOUT!\n";

}

exit 0;

__END__

=pod

=for stopwords CipUX STDOUT TODO Kuelker

=head1 NAME

cipux_configuration - prints CipUX configuration values

=head1 VERSION

version 3.4.0.5

=head1 SYNOPSIS

     cipux_configuration

=head1 OPTIONS

None

=head1 REQUIRED ARGUMENTS

None

=head1 ARGUMENTS

None

=head1 USAGE

 cipux_configuration

=head1 DESCRIPTION

Prints CipUX configuration values to STDOUT.

=head1 DIAGNOSTICS

TODO

=head1 EXIT STATUS

TODO

=head1 CONFIGURATION

None

=head1 DEPENDENCIES

Carp
CipUX
YAML::Any
version

=head1 INCOMPATIBILITIES

Not known.

=head1 BUGS AND LIMITATIONS

Not known.

=head1 SEE ALSO

See the CipUX web page and the manual at L<http://www.cipux.org>

See the mailing list L<http://sympa.cipworx.org/wws/info/cipux-devel>

=head1 AUTHOR

Christian Kuelker  E<lt>christian.kuelker@cipworx.orgE<gt>

=head1 LICENSE AND COPYRIGHT

Copyright (C) 2009 by Christian Kuelker

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA

=cut

