title: How to use Types::Path::Tiny with Moo
body: <p>My first question on this site, I come quickly. I'm a developer, I mainly use Python and Perl. I am passionate and I really like the development.</p>
  
  <p>My first question is about Perl, Moo, and Type::Tiny. Type::Tiny is a great module for use with Moo of course, but I will return to this subject in another question.</p>
  
  <p>I discovered Types::Path::Tiny a module coercions for Moose and Moo, so I tried to make a attribute directory in my class like as described in the <a href="https://metacpan.org/module/Types%3a%3aPath%3a%3aTiny">documentation</a>, as my project was in Moose it work, but since I moved in Moo, it no longer works:</p>
  
  <pre><code>package MahewinBlogEngine::Common;
  
  use strict;
  use warnings;
  
  use feature "state";
  
  use Moo;
  use Types::Path::Tiny qw/Path AbsPath/;
  
  use CHI;
  use MahewinBlogEngine::Renderer;
  
  use Type::Params qw( compile );
  use Types::Standard qw( slurpy Object Str HashRef ArrayRef );
  
  
  =attr directory
  
  rw, required, Str. The directory contain articles.
  
  =cut
  
  has 'directory' =&gt; (
      is       =&gt; 'rw',
      isa      =&gt; AbsPath,
      required =&gt; 1,
      coerce   =&gt; 1,
  );
  </code></pre>
  
  <p>In my tests directory:</p>
  
  <pre><code>my $articles = MahewinBlogEngine-&gt;articles( directory =&gt; getcwd() . '/t/articles' );
  </code></pre>
  
  <p>Error is:</p>
  
  <pre><code>Invalid coerce '1' for MahewinBlogEngine::Common-&gt;directory not a coderef or code-convertible object at /home/hobbestigrou/perl5/perlbrew/perls/perl-5.19.1/lib/site_perl/5.19.1/Method/Generate/Accessor.pm line 618.
  Compilation failed in require at /home/hobbestigrou/perl5/perlbrew/perls/perl-5.19.1/lib/site_perl/5.19.1/Module/Runtime.pm line 317.
  Compilation failed in require at /home/hobbestigrou/MahewinBlogEngine/lib/MahewinBlogEngine.pm line 8.
  BEGIN failed--compilation aborted at /home/hobbestigrou/MahewinBlogEngine/lib/MahewinBlogEngine.pm line 8.
  Compilation failed in require at ./benchmark.pl line 10.
  BEGIN failed--compilation aborted at ./benchmark.pl line 10.
  </code></pre>
  
  <p>This is normal, because with Moo the coercion is a coderef so I tried:</p>
  
  <pre><code>has 'directory' =&gt; (
      is       =&gt; 'rw',
      isa      =&gt; AbsPath,
      required =&gt; 1,
      coerce   =&gt; sub { return "Path" }
   );
  </code></pre>
  
  <p>Error is:</p>
  
  <pre><code>value "Path" did not pass type constraint "Path" (not isa Path::Tiny) (in $self-&gt;{"directory"}) at (eval 355) line 99.
  </code></pre>
  
  <p>If I have no coerce:</p>
  
  <pre><code>value "/home/hobbestigrou/MahewinBlogEngine/t/articles" did not pass type constraint "Path" (not isa Path::Tiny) (in $self-&gt;{"directory"}) at (eval 355) line 89.
  </code></pre>
  
  <p>I'm sorry for this simple question, I must be stupid and miss something, but I do not see what maybe I was missing something in the doc.</p>
  
  <p>Thanks</p>