Thanks to David and Stephen for their prompt and informative replies, much appreciated.<br><br><div class="gmail_quote">On Mon, Sep 17, 2012 at 2:05 PM, Stephen Thirlwall <span dir="ltr"><<a href="mailto:stephen.thirlwall@strategicdata.com.au" target="_blank">stephen.thirlwall@strategicdata.com.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The easiest way to do what you want is:<br>
<br>
        isa => 'Maybe[AG::Dataset]'<br>
or<br>
        isa => 'Undef|AG::Dataset'<br>
<br>
Then undef is also an accepted value for dataset.<br>
(no idea which is the preferred syntax)<br>
<br>
<br>
David's suggestion has the benefit/drawback of preventing dataset<br>
from being inadvertently set to undef.<br>
<br>
        $foo->dataset($value_is_undef)<br>
<br>
<br>
There is also:<br>
<br>
        predicate => 'has_dataset'<br>
<br>
which does what is says.<br>
<br>
<br>
It also makes sense to use both the clearer/predicate and nullable type,<br>
in the (rare?) case where you need to distinguish unset from set-to-undef.<br>
<br>
eg.<br>
<br>
my $foo = Foo->new;     # $foo->has_dataset is false<br>
$foo->dataset($x);      # $foo->has_dataset is true<br>
$foo->dataset(undef);   # $foo->has_dataset is still true<br>
$foo->clear_dataset;    # $foo->has_dataset is false again<br>
<br>
<br>
Steve<div class="im"><br>
<br>
<br>
On 17/09/12 1:19 PM, David Warring wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Hi Ian,<br>
You most likely want to delete the attribute entirely, rather than setting it to undef.<br>
<br>
One way is to define a clearer property for it:<br>
<br>
package Foo;<br>
<br>
use Moose;<br>
<br>
# ...<br>
<br>
has 'dataset' => (<br>
     is => 'rw',<br>
     isa => 'AG::Dataset',<br>
     required => 0,<br>
     clearer => 'clear_dataset',<br>
);<br>
<br>
then ...<br>
<br>
my $foo = Foo->new();<br>
$foo->dataset(bless {}, 'AG::Dataset');<br>
<br>
use YAML::Syck; print YAML::Syck::Dump({foo => $foo});<br>
<br>
$foo->clear_dataset;<br>
<br>
use YAML::Syck; print YAML::Syck::Dump({foo => $foo});<br>
<br>
- David<br>
<br></div><div class="im">
On Mon, Sep 17, 2012 at 12:52 PM, Ian Macdonald <<a href="mailto:ickphum@gmail.com" target="_blank">ickphum@gmail.com</a> <mailto:<a href="mailto:ickphum@gmail.com" target="_blank">ickphum@gmail.com</a>>> wrote:<br>

<br>
    Hi,<br>
<br>
    We've got a Moose class with this attribute:<br>
<br>
<br>
    has 'dataset' => (<br>
         is => 'rw',<br>
         isa => 'AG::Dataset',<br>
         required => 0,<br>
    );<br>
<br>
    It's not required so you can happily create objects without supplying a value for it, but once you've done so, you can't then remove/clear it via "$object->dataset(undef)" :<br>
<br>
         Attribute (dataset) does not pass the type constraint because: Validation failed for 'AG::Dataset' failed with value undef (not isa AG::Dataset)<br>
<br>
    Given that it's legal to have undefs in there initially it seems funny not to be allowed to revert to that state. Am I missing another property which will allow this? I'd rather not have to remove the validation or do it manually, seems like a backward step.<br>

<br>
    Thanks,<br>
    --<br>
    Ian Macdonald<br>
<br>
<br>
    ______________________________<u></u>_________________<br>
    Melbourne-pm mailing list<br></div>
    <a href="mailto:Melbourne-pm@pm.org" target="_blank">Melbourne-pm@pm.org</a> <mailto:<a href="mailto:Melbourne-pm@pm.org" target="_blank">Melbourne-pm@pm.org</a>><br>
    <a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/melbourne-pm</a><div class="im"><br>
<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
Melbourne-pm mailing list<br>
<a href="mailto:Melbourne-pm@pm.org" target="_blank">Melbourne-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/melbourne-pm</a><br>
<br>
</div></blockquote><div class="HOEnZb"><div class="h5">
<br>
______________________________<u></u>_________________<br>
Melbourne-pm mailing list<br>
<a href="mailto:Melbourne-pm@pm.org" target="_blank">Melbourne-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/melbourne-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/melbourne-pm</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Ian Macdonald<br><br>