Sometimes you package some code for others to deploy, and you want to provide a polite way of letting them check whether they have the depended-upon modules installed. The following code checks dependencies at runtime so that a suitable error message can be provided. (The crucial part is it’s an eval of a string rather than a code block.)

my @dependencies = qw( Cari::Mysql Cari::Session );
foreach my $d (@dependencies) {
    eval "use $d";
    die "Can't find $d: $@" if $@;
}
Advertisements