K
kj
I have the following short script:
use strict;
my $services;
my @packages = qw(Foo Bar Baz);
for my $package (@packages) {
my @services;
eval <<EOEVAL;
use $package;
\@services = $package\::get_available_services;
EOEVAL
$services->{ "http://acmeServices.com/#${_}" } = $package
for @services;
}
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
->dispatch_with( $services )
->handle();
The for-loop cycles over a list of packages, all of which implement
the sub get_available_services(), and uses eval to "use" each
package, and call the package's get_available_services.
As far as I can tell this code does the right thing, but I find
the construct with the eval rather klugey. Is there a better way
to achieve the same effect?
Thanks!
kj
use strict;
my $services;
my @packages = qw(Foo Bar Baz);
for my $package (@packages) {
my @services;
eval <<EOEVAL;
use $package;
\@services = $package\::get_available_services;
EOEVAL
$services->{ "http://acmeServices.com/#${_}" } = $package
for @services;
}
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
->dispatch_with( $services )
->handle();
The for-loop cycles over a list of packages, all of which implement
the sub get_available_services(), and uses eval to "use" each
package, and call the package's get_available_services.
As far as I can tell this code does the right thing, but I find
the construct with the eval rather klugey. Is there a better way
to achieve the same effect?
Thanks!
kj