#!/usr/bin/env perl -l
use strict;
use warnings;
# Compile time
use if $ENV{PM_1155832_USE}, 'List::Util' => qw{max};
BEGIN {
print 'Check for List::Util::max() at compile time';
eval { max(1, 2) };
print $@ if $@;
}
# Runtime
if (! $ENV{PM_1155832_USE}) {
require List::Util;
List::Util->import(qw{max});
}
print 'Max is ', max(1, 2);
####
$ pm_1155832_cond_use_mod.pl
Check for List::Util::max() at compile time
Undefined subroutine &main::max called at ./pm_1155832_cond_use_mod.pl line 11.
Max is 2
####
$ PM_1155832_USE=1 pm_1155832_cond_use_mod.pl
Check for List::Util::max() at compile time
Max is 2