GSM-SMS

 view release on metacpan or  search on metacpan

lib/GSM/SMS/Config.pm  view on Meta::CPAN

package GSM::SMS::Config;
use strict;
use vars qw( $REVISION $VERSION @EXPORT );

use base qw( Exporter );
@EXPORT = qw( &setup &generate_config );

use Carp;
use Log::Agent;
use ExtUtils::MakeMaker qw( prompt );
use Config;
use File::Path;
use File::Spec;

$VERSION = "0.161";
$REVISION = '$Revision: 1.6 $';

=head1 NAME

GSM::SMS::Config - Implements a simple .ini style config.

=head1 DESCRIPTION

Implements a simple configuration format. Used mainly for the transports 
config file.

The configuration format is defined as follows

  ^#         := comment
  ^[.+]$     := start block
  ^.+=.+$    := var, value pair
  
The structure allows attribute (configuration) access as follows

  $_preferences->{$blockname}->{$var}=$value
  $blockname = ( 'default', <blocknames> }

=head1 METHODS

=over 4

=item B<new> - The constructor

  my $cfg = GSM::SMS::Config->new(
               -file => $config_file, # Optional otherwise take default config
			   -check => 1            # Optional, does a sanity check
			);

=cut

my $Config_defaults = {};
if ( $^O =~ /^MSWin/ ) {
	$Config_defaults->{'logdir'} = "C:\\gsmsms\\log";
	$Config_defaults->{'spool'} = "C:\\gsmsms\\spool";
	$Config_defaults->{'port'} = 'COM1';
	$Config_defaults->{'filetransport'} = "C:\\gsmsms\\filetransport";
} else {
	$Config_defaults->{'logdir'} = "/var/log/gsmsms";
	$Config_defaults->{'spool'} = "/var/spool/gsmsms";
	$Config_defaults->{'port'} = '/dev/ttyS0';
	$Config_defaults->{'filetransport'} = "/tmp/filetransport";
}

sub new {
	my ($proto, %arg) = @_;

	my $class = ref($proto) || $proto;

	my $self = {
			_config_file => $arg{-file},
			_check => $arg{-check}
	};

	bless $self, $class;

	$self->read_config( $self->{_config_file}, $self->{_check} );

	return $self;
}

=item B<setup> - run the setup script

=cut

sub setup {
	my $config = _config_wizard();

	if ($config) {
		require File::Spec;
		my $config_file = File::Spec->catfile(
			$Config{'installsitelib'}, "GSM", "SMS", "Config", "Default.pm"
		);		
		open OUT, ">$config_file" or die "$!: $config_file";
		print OUT $config;
		close OUT;
		print "Config saved.\n";
	}
}

=item B<save_default> - save this configuration as the default

=cut

sub save_default {
	my ($self) = @_;

}

=item B<read_config> - read a configuration file

=cut

sub read_config {
	my ($self, $filename, $check) = @_;
	my $config = {};
	



( run in 2.667 seconds using v1.01-cache-2.11-cpan-d8267643d1d )