Moose in Mason - the array value is not set by default

I have some fields in the component (included in the base component by <& file.mi &>, there is nothing interesting here) and I cannot figure out how to set the default value for the array. My definition looks like this:

<%class>
    has 'field' => (is => 'ro', isa => 'ArrayRef[Int]', default => sub{\[1,3]});
</%class>

then in

<%init>
    dp_live($.field);
</%init>

I got an empty array. Nothing I found on the Internet seems to work. I am sure that this is something insignificant, more, I just do not see it.

Thank.

+3
source share
1 answer

For some reason, Mason does not like types. It works:

<%class>
        has 'field' => (is => 'ro', default => sub{[1,3]});
</%class>

<pre>
<% dh $.field %>
</pre>

and prints:

[dh at .../testpoet/comps/ar.mc line 6.] [99751] [
  1,
  3
]

Btw, why are you using:

default => sub{\[1,3]});

instead

default => sub{[1,3]});

EDIT

, / ( ) 0.15, .

, Poet 0,15,

has 'field' => (is => 'ro', isa => 'ArrayRef[Int]', default => sub{[1,3]});

.

+1

All Articles