talexb has asked for the wisdom of the Perl Monks concerning the following question:
I want to cycle through a bunch of modules that have credentials and site URLs .. I have this working OK, but it seems that I'm doing it in a much complicated way than I should. Feedback would be appreciated.
This script illustrates how I plan to cycle through the credential modules:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; { my @variables = qw/User Password Url Prefix/; foreach my $module ( qw/Foo Bar/ ) { eval "use ABCXYZ::$module"; # Foreach loop for illustration only .. could be replaced # with a map .. my %values; foreach my $var ( @variables ) { $values{ $var } = eval '$' . join ( '::', 'ABCXYZ', $module, $var ); } # Call subroutine with values hash here .. } }
The goal is to be able to call a routine with individual site credentials for order processing. Is there a more Perl-ish way of accomplishing this? Credential modules look like this:
The credentials are stored like this so that the processing scripts can be checked into github without credentials leaving the customer site.package ABCXYZ::Foo; use Exporter; our @Export = ( $User $Password $Url $Prefix ); our $User = 'Joe'; our $Password = 'Secret123'; our $Url = 'www.example.com'; our $Prefix = 'EX'; 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing module variables
by Eily (Monsignor) on Apr 19, 2018 at 15:24 UTC | |
by hippo (Archbishop) on Apr 19, 2018 at 15:34 UTC | |
by talexb (Chancellor) on Apr 19, 2018 at 15:53 UTC | |
|
Re: Accessing module variables
by LanX (Saint) on Apr 19, 2018 at 15:17 UTC | |
by LanX (Saint) on Apr 19, 2018 at 17:07 UTC | |
|
Re: Accessing module variables
by Discipulus (Canon) on Apr 19, 2018 at 17:35 UTC | |
by talexb (Chancellor) on Apr 19, 2018 at 22:49 UTC | |
|
Re: Accessing module variables
by karlgoethebier (Abbot) on Apr 20, 2018 at 07:46 UTC | |
by talexb (Chancellor) on Apr 20, 2018 at 11:58 UTC | |
|
Re: Accessing module variables
by Anonymous Monk on Apr 19, 2018 at 18:15 UTC |