CPAN-Mini-Inject
view release on metacpan or search on metacpan
lib/CPAN/Mini/Inject/Config.pm view on Meta::CPAN
my $file = shift;
my %required = map { $_, 1 } qw(local remote);
$self->load_config( $file ) unless $self->config_file;
if ( -r $self->config_file ) {
open my ( $fh ), "<", $self->config_file
or croak sprintf "$0: cannot open config file <%s>: $!", $self->config_file;
while ( <$fh> ) {
next if /^\s*#/;
chomp;
if( /^\s*([^:\s]+)\s*:\s*(.*?)\s*$/ ) {
$self->{$1} = $2;
delete $required{$1} if defined $required{$1};
} else {
carp sprintf "$0: %s:%d ignoring invalid configuration line: %s\n",
$self->config_file, $., $_;
}
}
close $fh;
if( keys %required ) {
croak sprintf "$0: missing required parameter(s): %s", join ' ', keys %required;
}
}
return $self;
}
=item C<< get( DIRECTIVE ) >>
Return the value for the named configuration directive.
=cut
sub get { $_[0]->{ $_[1] } }
=item C<< set( DIRECTIVE, VALUE ) >>
Sets the value for the named configuration directive.
=cut
sub set { $_[0]->{ $_[1] } = $_[2] }
=back
=head1 AUTHOR
Shawn Sorichetti C<< <ssoriche@coloredblocks.net> >>
=head1 SOURCE AVAILABILITY
The main repository is on GitHub:
https://github.com/briandfoy/cpan-mini-inject
There are also backup repositories on several other services:
https://bitbucket.org/briandfoy/cpan-mini-inject
https://codeberg.org/briandfoy/cpan-mini-inject
https://gitlab.com/briandfoy/cpan-mini-inject
=head1 COPYRIGHT & LICENSE
Copyright 2004 Shawn Sorichetti, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
__PACKAGE__;
( run in 0.852 second using v1.01-cache-2.11-cpan-39bf76dae61 )