3

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.

Liberat0r
  • 1,852
  • 2
  • 16
  • 21

1 Answers1

1

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.

kobame
  • 5,766
  • 3
  • 31
  • 62
  • Thanks, that works for me also :). Perl variables/names/types/references system is still a bit confusing for me, so I have tried many "variants"(thinking, this was the case) and just pasted what made most sense to me ;). – Liberat0r Feb 25 '14 at 09:25
  • 1
    @Liberat0r - I'm checked this problem more deeply and it is a very strange. I forwarded it to mason mailing-list - maybe someone answer it - and will modify my answer... – kobame Feb 26 '14 at 15:40
  • @Liberat0r - see the edit - update your Poet to fresh v0.15. ;) – kobame Feb 26 '14 at 23:41