Allow new config store to be univerally available within the app

This commit is contained in:
Duncan Ferguson 2010-06-25 16:20:48 +01:00
parent 1410a8f807
commit 4b03d3f6ea
2 changed files with 125 additions and 11 deletions

View file

@ -7,17 +7,18 @@ use App::ClusterSSH::L10N;
# Dont use SVN revision as it can cause problems
use version;
our $VERSION = version->new('0.01');
our $VERSION = version->new('0.02');
my $debug_level = 0;
our $language = 'en';
our $language_handle;
our $app_configuration;
sub new {
my ( $class, %args) = @_;
my ( $class, %args ) = @_;
my $config = {
lang => 'en',
lang => 'en',
debug => 0,
%args,
};
@ -27,8 +28,9 @@ sub new {
$self->set_debug_level( $config->{debug} );
$self->set_lang( $config->{lang} );
$self->debug( 7,
$self->loc('Arguments to [_1]->new(): ', $class),
$self->debug(
7,
$self->loc( 'Arguments to [_1]->new(): ', $class ),
$self->_dump_args_hash(%args),
);
@ -69,11 +71,9 @@ sub loc {
sub set_lang {
my ( $self, $lang ) = @_;
$language=$lang;
$language = $lang;
if ($self) {
$self->debug( 6,
$self->loc('Setting language to "[_1]"', $lang ),
);
$self->debug( 6, $self->loc( 'Setting language to "[_1]"', $lang ), );
}
return $self;
}
@ -109,6 +109,34 @@ sub debug {
return $self;
}
sub config {
my ($self) = @_;
if ( !$app_configuration ) {
croak( _translate('config has not yet been set') );
}
return $app_configuration;
}
sub set_config {
my ( $self, $config ) = @_;
if ($app_configuration) {
croak( _translate('config has already been set') );
}
if(!$config) {
croak( _translate('passed config is empty'));
}
$self->debug( 3, _translate('Setting app configuration') );
$app_configuration = $config;
return $self;
}
1;
=pod
@ -177,6 +205,15 @@ a wrapper to maketext in Locale::Maketext
Output text on STDOUT.
=item $config = $obj->config;
Returns whatever configuration object has been set up. Croaks if set_config
hasnt been called
=item $obj->set_config($config);
Set the config to the given value - croaks if has already been called
=back
=head1 AUTHOR