title: MooseX::Types and coercion error
body: <p>As continue of <a href="https://stackoverflow.com/a/19624694/1515483">this answer</a> wow im fighting with the my own Moose "type library" - so trying to use "<a href="https://metacpan.org/pod/MooseX::Types" rel="nofollow noreferrer">MooseX::Types</a>".</p>
  
  <p>Based on the above <code>MooseX::Types</code> docs, and "hoobs" comment to the above answer, I defined my own "types" as next:</p>
  
  <pre><code>package MyTypes;
  use 5.016;
  use Moose;
  use MooseX::Types -declare =&gt; [qw( Dir File )];    
  use MooseX::Types::Moose qw( Str );
  
  use Path::Class::Dir;
  use Path::Class::File;
  
  class_type Dir, { class =&gt; 'Path::Class::Dir' };
  coerce Dir, from Str, via { Path::Class::Dir-&gt;new($_) };
  
  class_type File, { class =&gt; 'Path::Class::File' };
  coerce File, from Str, via { Path::Class::File-&gt;new($_) };
  
  1;
  </code></pre>
  
  <p>and used it in my package</p>
  
  <pre><code>package MyDir;
  use Moose;
  use warnings;
  use MyTypes qw(Dir);    #to get the Dir type and its coercion
  
  has 'path' =&gt; (
      is =&gt; 'ro',
      isa =&gt; Dir,      # Dir is defined in the package MyTypes
      required =&gt; 1,
  );
  1;
  </code></pre>
  
  <p>and tried with the next short script</p>
  
  <pre><code>use 5.016;
  use warnings;
  use MyDir;
  my $d = MyDir-&gt;new(path =&gt; "/tmp");
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Attribute (path) does not pass the type constraint because: Validation failed for 'MyTypes::Dir' with value /tmp (not isa Path::Class::Dir) at /Users/me/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/darwin-2level/Moose/Meta/Attribute.pm line 1279.
      Moose::Meta::Attribute::verify_against_type_constraint(Moose::Meta::Attribute=HASH(0x7f9e9b1c2618), "/tmp", "instance", MyDir=HASH(0x7f9e9b826bb8)) called at /Users/me/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/darwin-2level/Moose/Meta/Attribute.pm line 1266
      Moose::Meta::Attribute::_coerce_and_verify(Moose::Meta::Attribute=HASH(0x7f9e9b1c2618), "/tmp", MyDir=HASH(0x7f9e9b826bb8)) called at /Users/me/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/darwin-2level/Moose/Meta/Attribute.pm line 536
      Moose::Meta::Attribute::initialize_instance_slot(Moose::Meta::Attribute=HASH(0x7f9e9b1c2618), Moose::Meta::Instance=HASH(0x7f9e9b1c3588), MyDir=HASH(0x7f9e9b826bb8), HASH(0x7f9e9b826a98)) called at /Users/me/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/darwin-2level/Class/MOP/Class.pm line 525
      Class::MOP::Class::_construct_instance(Moose::Meta::Class=HASH(0x7f9e9b9e6990), HASH(0x7f9e9b826a98)) called at /Users/me/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/darwin-2level/Class/MOP/Class.pm line 498
      Class::MOP::Class::new_object(Moose::Meta::Class=HASH(0x7f9e9b9e6990), HASH(0x7f9e9b826a98)) called at /Users/me/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/darwin-2level/Moose/Meta/Class.pm line 284
      Moose::Meta::Class::new_object(Moose::Meta::Class=HASH(0x7f9e9b9e6990), HASH(0x7f9e9b826a98)) called at /Users/me/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/darwin-2level/Moose/Object.pm line 28
      Moose::Object::new("MyDir", "path", "/tmp") called at t.pl line 5
  </code></pre>
  
  <p>So, doesn't accept the 'Str' and don't do the coercion.</p>
  
  <p>What is wrong in the above few lines? I'm pretty sure than it is really very small bug, <em>because i followed the MooseX::Types docs</em> (at least i hope) - but unable to find the error. </p>
  
  <p>I'm starting be really hopeless with Moose, please HELP...</p>
  
  <p>Ps: My goal is defining all my own "types" in one place (package) and use it everywhere where i need them with one single "use...".</p>