Type::Const released

  • I've created an experimental Type::Tiny library called Type::Const that coerces ArrayRefs and HashRefs into constants using Const::Fast.


    When you have read-only attributes in Moo(se) classes:

    has things => ( 
      is => 'ro',
      isa => HashRef,

    While you can't change what hash reference things refers to, you can change the contents. This is fine:

    $obj->things->{$key} = $val;

    and there are good reasons for that.

    But in other situations, you have built a table of data that you do not want changed. You can use this instead:

    has things => ( 
      is         => 'ro',
      isa       => ConstHashRef,
      coerce => 1,

    The coercion means that any hash reference will be made read-only.



© Lightnetics 2019