title: Precalculate Perl constants based on some run-time calculated value
body: <p>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 <code>dirname(rel2abs($0))</code>?</p>
  
  <pre><code>package Foo;
  
  use File::Basename;
  use File::Spec::Functions qw/rel2abs/;
  use Carp qw/croak/;
  use 5.010;
  
  use constant BAR_NAMES =&gt; {
      WATER =&gt; dirname(rel2abs($0)) . '/../data/water.png',
      FIRE =&gt; dirname(rel2abs($0)) .'/../data/fire.png',
      GRASS =&gt; dirname(rel2abs($0)) .'/../data/grass.png'#,
      #and so on
  };
  
  sub get {
      my ($self, $name) = (shift, shift);
      if (exists BAR_NAMES-&gt;{$name}) {
          #return some calculated data based on $name value
      } else {
          croak("Constant `$name` is not declared.");
      }
  };
  
  1;
  </code></pre>
  
  <p>Thank you.</p>