This should be rather trivial, but I cannot figure it out on my own.
Having the code below, are there any ways to get rid of many invocations of dirname(rel2abs($0))
?
package Foo;
use File::Basename;
use File::Spec::Functions qw/rel2abs/;
use Carp qw/croak/;
use 5.010;
use constant BAR_NAMES => {
WATER => dirname(rel2abs($0)) . '/../data/water.png',
FIRE => dirname(rel2abs($0)) .'/../data/fire.png',
GRASS => dirname(rel2abs($0)) .'/../data/grass.png'#,
#and so on
};
sub get {
my ($self, $name) = (shift, shift);
if (exists BAR_NAMES->{$name}) {
#return some calculated data based on $name value
} else {
croak("Constant `$name` is not declared.");
}
};
1;
Thank you.