<div>When you have a constructor and it fails, It's not common practice to return a "null" object. Perl modules usually return undef.</div><div><br></div><div>However, in Moose, in a Moose role that I want to do this:</div>

<div><br></div><div><div>has ssh => (</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>is      => 'rw',</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>isa     => 'Net::SSH2',</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>default => \&ssh_builder,</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>lazy    => 1,</div><div>);</div></div><div><br>
</div>
<div>---</div><div><br></div><div>To use this within a class, I do this:</div><div><br></div><div>my $ssh = $self->ssh;</div><div>$log->warn("couldn't connect") unless defined $ssh;  #-- this line for illustration</div>

<div><br></div><div>---</div><div><br></div><div>So, I want to handle any errors such as when \&ssh_builder fails and returns 'undef', but what happens is that it crashes before the error handling code because 'undef' is not of type 'Net::SSH2'. So what I do to fix it is take out the 'isa     => 'Net::SSH2',' from the definition of the 'ssh' attribute.</div>

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div>Now I lose the advantage of having the type check in my development for the 99.99% of the time when there are no errors. It seems to me that 'undef' should be considered to be a member of every class, or better yet have an option to make it so.  Is there another way of getting the advantages of the type checking and also handling exceptions like this?</div>

<div><br></div><div>Thanks,</div><div>Sean</div><br><br>