BEGIN {
my $code= '...some work-around for not having GD...';
if( eval { require GD } ) {
$code= '...code that uses GD...';
}
eval "sub mySub { $code }; 1 "
or die "$@";
}
####
package Pretend;
use base qw(Exporter);
our @EXPORT_OK= qw( sorter hasher );
sub sorter(&@);
sub hahser(\%);
#[...]
##
##
my $got_Pretend;
BEGIN {
if( $got_Pretend= eval { require Pretend } ) {
Pretend->import( qw( sorter hasher ) );
} else {
require WorsePretendWorkAround;
WorsePretendWorkAround->import(
qw( comparer worse_hasher ) );
}
}
#[...]
if( $got_Pretend ) {
@list= sorter { $_[0] <=> $_[1] } hasher %hash;
} else {
@list= sort \&comparer worse_hasher(\%hash);
}
##
##
if( $got_Pretend ) {
@list= sorter( sub { $_[0] <=> $_[1] }, &hasher(\%hash) );
} else {
@list= sort \&comparer worse_hasher(\%hash);
}