CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/root/usr/local/rvglobalsoft/rvsitebuilder7/lib/RVL/
Upload File :
Current File : //proc/2/root/usr/local/rvglobalsoft/rvsitebuilder7/lib/RVL/Config.pm

#!/usr/bin/perl
package RVL::Config;
# WebSite:  http://www.rvglobalsoft.com
# Unauthorized copying is strictly forbidden and may result in severe legal action.
# Copyright (c) 2013 RV Global Soft Co.,Ltd. All rights reserved.
#
# =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
# Copyright (c) 2013 RV Global Soft Co.,Ltd. All rights reserved.
# This Agreement is a legal contract, which specifies the terms of the license
# and warranty limitation between you and RV Global Soft Co.,Ltd. and RV2Factor Product for RV Global Soft.
# You should carefully read the following terms and conditions before
# installing or using this software.  Unless you have a different license
# agreement obtained from RV Global Soft Co.,Ltd., installation or use of this software
# indicates your acceptance of the license and warranty limitation terms
# contained in this Agreement. If you do not agree to the terms of this
# Agreement, promptly delete and destroy all copies of the Software.
#
# =====  Grant of License =======
# The Software may only be installed and used on a single host machine.
#
# =====  Disclaimer of Warranty =======
# THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND
# WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER
# WARRANTIES WHETHER EXPRESSED OR IMPLIED.   BECAUSE OF THE VARIOUS HARDWARE
# AND SOFTWARE ENVIRONMENTS INTO WHICH RV SITE BUILDER MAY BE USED, NO WARRANTY OF
# FITNESS FOR A PARTICULAR PURPOSE IS OFFERED.  THE USER MUST ASSUME THE
# ENTIRE RISK OF USING THIS PROGRAM.  ANY LIABILITY OF RV GLOBAL SOFT CO.,LTD. WILL BE
# LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE.
# IN NO CASE SHALL RV GLOBAL SOFT CO.,LTD. BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR
# CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS
# OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE
# BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT,
# NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF
# RV GLOBAL SOFT CO.,LTD. IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL
# RV GLOBAL SOFT CO.,LTD.'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID
# BY LICENSEE TO RV GLOBAL SOFT CO.,LTD.
# ===============================

=head1 NAME

RVL::Config - Config file parsing and handling, acts as a registry for config data.

=head1 SYNOPSIS


=head1 DESCRIPTION


=head1 METHODS

=cut

use strict;
use warnings;
use CGI;
use IO::Interactive qw(is_interactive interactive busy);
use RVL::ParamHandler;
use Class::Std::Utils;
{
    # class attribute

    sub new {
        my ($class, $opt) = @_;
        my %hash;
        my ($this) = bless( \%hash, $class);
        if ($this->isEmpty()) {
            my ($configFile) = (defined $opt->{file}) ? $opt->{file} : $this->getDefauftConfig();
            
            if ($configFile) {
                RVL::debug("Load config $configFile", __CONSTANT__::RVL_LOG_DEBUG);
                $this->{aProps} = $this->load($configFile);
            } else {
                RVL::raiseError('could not config file ' . $configFile,
                __CONSTANT__::RVL_ERROR_NOFILE);
            }
        }
        return $this;
    }

=head2 singleton()

 Returns a singleton Request instance.
 
=cut
    sub singleton {
        my ($class, $file) = __PACKAGE__;
        if (!defined $RVL::INSTANCE{$class}) {
            $RVL::INSTANCE{$class} = $class->new();
        }
        return $RVL::INSTANCE{$class}
    }
    
    sub load {
        my ($this, $file) = @_;
        if (-f $file) {
            RVL::logMessage('Load config file: ' . $file, __CONSTANT__::RVL_LOG_DEBUG);
            my ($fp) = RVL::ParamHandler::singleton($file);
            my ($data) = $fp->read();
            return $data;
        } else {
            return RVL::raiseError('Problem reading config file ' . $file, 0, __CONSTANT__::RVL_ERROR_INVALIDFILEPERMS);
        }
    }
    
    sub get {
        my ($this, $key);
        $this = shift;
        if (ref $this ne __PACKAGE__) {
            $key = $this;
            $this = RVL::Config::singleton();
        } else {
            $key = shift;
        }
        
        if (RVL::String::is_hash($key)) {
            my ($group) = keys %{$key};
            return defined($this->{aProps}->{$group}->{$key->{$group}}) ?
                $this->{aProps}->{$group}->{$key->{$group}} : '';
        } elsif(RVL::String::is_string($key)) {
            my (@keys) = split(/\./, $key, 2);
            if (!$keys[0] || !$keys[1]) {
                return '';
            } elsif (!defined($this->{aProps}) || !$this->{aProps}) {
                return '';
            } elsif(!defined($this->{aProps}->{$keys[0]})) {
                return '';
            } elsif (!defined($this->{aProps}->{$keys[0]}->{$keys[1]}) ) {
                return '';
            } else {
                return $this->{aProps}->{$keys[0]}->{$keys[1]};
            }
        }
    }

    sub getAll {
        my ($this) = @_;
        return $this->{aProps};
    }
    
    sub getDefauftConfig {
        my ($this) = @_;
        return __CONSTANT__::RVL_VAR_DIR . '/' . $this->getRealHostname() . '.yaml';
    }
    
    sub getRealHostname {
        my ($this) = @_;
        $this = RVL::Config::singleton() if (ref $this ne __PACKAGE__);
        my ($hostname);
        if (!-f __CONSTANT__::RVL_VAR_DIR . '/customhostname.txt') {
            $hostname = `hostname`;
        } else {
            open(FD, '<', __CONSTANT__::RVL_VAR_DIR . '/customhostname.txt');
            $hostname = <FD>;
            close(FD);
        }
        chomp($hostname);
        return $hostname;
    }
    
    sub isEmpty {
        my ($this, $force) = @_;
        return (defined $this->{aProps}) ? 0 : 1;
    }
    
    sub ensureModuleConfigLoaded{
        my ($this, $moduleName) = @_;
        if ( !defined $this->{aProps}->{localConfig}->{moduleName} 
             || $this->{aProps}->{localConfig}->{moduleName} ne $moduleName) {
            my ($modConfigPath) = __CONSTANT__::RVL_MOD_DIR . '/' . $moduleName . '/conf.yaml';
            if (-f $modConfigPath) {
                my ($aModuleConfig) = $this->load($modConfigPath);
                $this->merge($aModuleConfig);
            } else {
                my $ret = RVL::raiseError("Config file could not be found at '$modConfigPath'", 0, 1, __CONSTANT__::RVL_ERROR_NOFILE);
            }
        }
    }
    
    sub merge{
        my ($this, $value) = @_;
        $this->{aProps} = RVL::String::merge($this->{aProps}, $value);
    }
    
}
1;

Copyright 2K16 - 2K18 Indonesian Hacker Rulez