| 1 | # | ||||||||||
| 2 | # Mail/Salsa/Config.pm | ||||||||||
| 3 | # Last Modification: Thu May 27 18:32:49 WEST 2004 | ||||||||||
| 4 | # | ||||||||||
| 5 | # Copyright (c) 2004 Henrique Dias <hdias@aesbuc.pt>. All rights reserved. | ||||||||||
| 6 | # This module is free software; you can redistribute it and/or modify | ||||||||||
| 7 | # it under the same terms as Perl itself. | ||||||||||
| 8 | # | ||||||||||
| 9 | package Mail::Salsa::Config; | ||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use 5.008000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | require Exporter; | |||||||||
| 16 | 1 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 1 | our @ISA = qw(Exporter); | |||||||||
| 19 | |||||||||||
| 20 | # Items to export into callers namespace by default. Note: do not export | ||||||||||
| 21 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||
| 22 | # Do not simply export all your public functions/methods/constants. | ||||||||||
| 23 | |||||||||||
| 24 | # This allows declaration use Mail::Salsa::Config ':all'; | ||||||||||
| 25 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||
| 26 | # will save memory. | ||||||||||
| 27 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||
| 28 | |||||||||||
| 29 | ) ] ); | ||||||||||
| 30 | |||||||||||
| 31 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 32 | |||||||||||
| 33 | 1 | our @EXPORT = qw( | |||||||||
| 34 | |||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 1 | our $VERSION = '0.01'; | |||||||||
| 38 | |||||||||||
| 39 | # Preloaded methods go here. | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub get_config { | ||||||||
|
Subroutine
get_config: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 42 | 0 | my $config = &load_config( | |||||||||
| 43 | file => undef, | ||||||||||
| 44 | defaults => {}, | ||||||||||
| 45 | @_, | ||||||||||
| 46 | ); | ||||||||||
| 47 | 0 | return($config); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | sub load_config { | ||||||||
|
Subroutine
load_config: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 51 | 0 | my $args = {@_}; | |||||||||
| 52 | |||||||||||
| 53 | 0 | my $wloop = <<ENDCODE; | |||||||||
| 54 | while(<CONFIG>) { | ||||||||||
| 55 | study; | ||||||||||
| 56 | /^\\w/ or next; | ||||||||||
| 57 | my (\$k, \$v) = split(/ *= */); | ||||||||||
| 58 | \$v =~ s/\\s+\$//g; | ||||||||||
| 59 | \$v =~ /^(.+)\$/; | ||||||||||
| 60 | \$config{\$k} = (ref(\$args->{defaults}->{\$k}) eq "ARRAY") ? [map {/^(.+)\$/} split(/ *, */, \$1)] : \$1; | ||||||||||
| 61 | } | ||||||||||
| 62 | ENDCODE | ||||||||||
| 63 | 0 | my %config = %{$args->{defaults}}; | |||||||||
| 64 | 0 | ▶ | open(CONFIG, join("", "<", $args->{file})) or die("No such configuration file\n"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | eval($wloop); | |||||||||
| 66 | 0 | close(CONFIG); | |||||||||
| 67 | 0 | return(\%config); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||
| 72 | |||||||||||
| 73 | 1 | 1; | |||||||||
| 74 | __END__ | ||||||||||