Hello,
I have small problem. I define a class 'Node' with 2 enums Action and State
and when creating an instance it enforces constraints correctly. However
once I’ve created an instance it doesn’t seem to enforce constraints.


At the end of the following code if I dump $btn I see:

  DB<5> x $btn

0  HtmlElement=HASH(0x11036ae8)

   'Name' => 'myButton'

*   'Type' => 'An Illegal Value'*

Any idea how I can make it enforce the enum constraints when I dynamically
change a value so I can't change Type to be 'An Illegal Value' ?


Thanks in advance,

Steve

 
---------------------------------------------------------------------------------------------





package Node;

use Moose;

use Moose::Util::TypeConstraints;



has Name => (

    is => 'rw',

    isa => 'Str',

    required => 1,

    );

has Action => (

    is => 'ro',

    isa => enum( [qw [ Clicked Selected HoverClicked ]]),

    );

has State => (

    is => 'ro',

    isa => enum( [qw [ HasItems Selected Highlighted Showing HoveredOver
]]),

    );





package HtmlElement;

use Moose;

use Moose::Util::TypeConstraints;

extends 'Node';

has Type => (

    is => 'ro',

    isa => enum( [qw [Tab Page Control Dropdown Button Link]]),

    required => 1,

    );



package main;

my $btn = HtmlElement->new( Name => 'myButton', Type => 'Button');

$btn->{Type}='An Illegal Value';




-- 
StephenPrytherch
_____________________________

MyWebGrocer
354 Mountain View Dr. Colchester, VT 05446
Phone: 802.857.0272
+ www.MyWebGrocer.com
+ www.Twitter.com/MyWebGrocer
+ www.YouTube.com/MyWebGrocer

Reply via email to