I have a moose class with a boolean attribute. When I create a new instance of that class I try to pass either a 0 or 1 (perl boolean vals I thought) I get an error stating this is not a valid value. Either that or I'm misunderstanding the error message.

Here's the package.

package AXField; # Our libraries use lib 'C:\Users\Jay\Desktop\SBS DEV\CODE\perl\Utilities'; use Moose; # Attributes has 'Name' => (is => 'rw', isa => 'Str', required => 1); has 'Value' => (is => 'rw', isa => 'Str', reader => 'Value', writer => + 'SetValue'); has 'isKey' => (is => 'rw', isa => 'Boolean'); has 'Len' => (is=>'rw', isa => 'Num'); has 'DecimalPos' => (is => 'rw', isa => 'Num'); has 'Type' => (is => 'rw', isa => 'Str'); has 'OriginalValue' => (is => 'rw', isa => 'Str'); has 'ParentRec' => (is => 'rw', isa => 'Str', required => 1); has 'Populated' => (is => 'rw', isa => 'Str'); # Contains a single field sub BUILD # Constructor { my $self; $self = shift; $self->Populated(0); $self->OriginalValue(' '); $self->SetValue(' '); } sub Value { my $self; $self = shift; return $self->Value; } sub SetValue { my $self; $self = shift; $self->Value = shift; if ($self=>Populated() eq 'N') { $self=>Populated() eq 'Y'; } } 1;
Here's the line that creates a new "Field"
&Fld = AXField->new(Name => $Prop[0], Value => ' ', isKey => 1, Len => + $Length, DecimalPos => $prec, Type => $Prop[4], ParentRec => $self-> +Name);
We're interested in the isKey attribute.

Here's the error message

Attribute (isKey) does not pass the type constraint because: Validatio +n failed f or 'Boolean' with value 1 (not isa Boolean) at C:\Perl64\lib\Moose\Obj +ect.pm lin e 24
What am I missing

In reply to Moose boolean type values: Noob by jorba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.