The usual way I handle this sort of thing is to require an environment variable in order to run the test suite. The environment variable will contain the useful bit of information (e.g. an API key, a hostname to connect to, etc.)
Here's an example of how you might handle this sort of thing from within a test file. We use this for the MongoDB distribution to check if there's an available server to run against:
BEGIN {
eval {
my $host = exists $ENV{MONGOD} ? $ENV{MONGOD} : 'localhost';
$conn = MongoDB::MongoClient->new( host => $host, ssl => $ENV{MONGO_SSL} );
};
if ( $@ ) {
plan skip_all => $@;
exit 0;
}
};
All this does is try to connect to a host specified in the MONGOD
environment variable (or else localhost.) If it can't, it skips all the tests and tells the reason why. The skips still count as a non-failure, so it won't prevent installation of the module if no test server is available.
I have this code in a .pm file which I use
in every .t file in the distribution.