package Config::File;
use 5.000;
use strict;
use warnings;
use Carp;
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);
@ISA = qw(Exporter);
$VERSION = '0.01';
sub new {
my $class = shift;
my %arg = @_;
my $self = {};
bless( $self, $class );
croak($class.'->new() requires file name') unless $arg{file};
$self->{'conf'} = do($arg{file});
return $self;
}
sub AUTOLOAD {
my $self = shift;
my $method = $AUTOLOAD;
$method =~ s/.*://;
unless (defined $self->{'conf'}->{$method}) {
croak($method.' not defined in '.$self);
}
if (ref $self->{'conf'}->{$method} eq 'HASH') {
return %{ $self->{'conf'}->{$method} };
}
elsif (ref $self->{'conf'}->{$method} eq 'ARRAY') {
return @{ $self->{'conf'}->{$method} };
}
else {
return $self->{'conf'}->{$method};
}
}
1;
####
{
en => 'one',
de => [qw/ein zwei/],
ch => { 1 => 'yi',
2 => 'er'},
}
####
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Config::File;
my $c = Config::File->new(file => 'conf.pl');
my $en = $c->en;
my @de = $c->de;
my %ch = $c->ch;
print Dumper(\$en, \@de, \%ch);
####
$VAR1 = \'one';
$VAR2 = [
'ein',
'zwei'
];
$VAR3 = {
'1' => 'yi',
'2' => 'er'
};
(in cleanup) DESTROY not defined in Config::File=HASH(0x224f74) at test.pl line 0