# -------------------------------------------------------------------------------------
# flo::Object
# -------------------------------------------------------------------------------------
#
#       Author : Jean-Michel Hiver (jhiver@cisedi.com).
#    Copyright : (c) MKDoc Holdings Ltd, 2001
# 
#      Unauthorized modification, use, reuse, distribution or redistribution
#      of this module is stricly forbidden.
#
#    Description:
#
#      Base class for all flo::* objects mainly providing a config class method
#
# -------------------------------------------------------------------------------------
package flo::Object;
use lib::Config;
use strict;
use vars qw /$CONFIG/;
$CONFIG = {};


##
# $class->config;
# ---------------
#   Returns the configuration parameters of that class as a
#   hash reference
##
sub config
{
    my $class = shift;
    $class = ref $class || $class;
    
    # compute the config file name from the class name
    my $file = $class;
    $file =~ s/\.pm$//;
    $file =~ s/::/./g;
    
    # if there is a configuration file already, then we want to
    # reuse it to avoid computation
    return $CONFIG->{$file} if (defined $CONFIG->{$file});
    
    # otherwise, it's the first time we're called, in which case
    # we want to create the config hash
    if (-e $lib::Config::DIR . '/' . $file)
    {
	my $cfg = new lib::Config ($file);
	my $hash = {};
	foreach ($cfg->keys) { $hash->{$_} = $cfg->get ($_) }
	$CONFIG->{$file} = $hash;
    }
    else
    {
	$CONFIG->{$file} = {};
    }
    
    # return the config file info
    return $CONFIG->{$file};
}


1;


