Pergunta

I have some fields in a component (included in base component by <& file.mi &>, nothing fancy here) and I can't figure out how to set default value for an array.
My deffinition look 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 that I found on internet seems to work. I'm sure that it is something minor, bo I just can't see it.

Thanks.

Foi útil?

Solução

For some reason, the Mason doesn't like the Types. This 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 do you uses:

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

instead of

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

EDIT

I forwarded this problem to mason-users mailing list and the author of Poet/Mason (Jonathan Swartz) really quickly responded and updated the Poet to version 0.15 what fixes the bug.

So, if you update your Poet to 0.15 the

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

should work.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top