Skip to content

Instantly share code, notes, and snippets.

@atoomic
Created January 8, 2020 16:14
Show Gist options
  • Save atoomic/98ee3a7af8e26989fb6bae6085c8e3ed to your computer and use it in GitHub Desktop.
Save atoomic/98ee3a7af8e26989fb6bae6085c8e3ed to your computer and use it in GitHub Desktop.

Revisions

  1. atoomic created this gist Jan 8, 2020.
    16 changes: 16 additions & 0 deletions constant-eval.t
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!perl

    use Test::More;

    my %storage;
    use constant SAMPLE_CONSTANT => defined eval { $storage{cache} = get_string('abcd') };

    sub get_string {
    my ( $str ) = @_;
    return ":$str:";
    }

    is SAMPLE_CONSTANT, 1, "constant is set to true";
    is $storage{cache}, ':abcd:', "cache is set at compile time";

    done_testing;