title: Perl Moose - How do I filter a type that does not match a parameter and replace it with a default or null value?
body: <p>This is the User.pm</p>
  
  <pre><code>package User;
  use Moose;
  
  has 'name' =&gt; (
    is =&gt; 'rw',
    isa =&gt; 'Str',
    required =&gt; 1
  );
  
  has 'age' =&gt; (
    is =&gt; 'rw',
    isa =&gt; 'Int',
    required =&gt; 1
  );
  
  has 'water' =&gt; (
    is =&gt; 'rw',
    isa =&gt; 'Int',
    required =&gt; 1,
    default =&gt; '2000'
  );
  
  no Moose;
  1;
  </code></pre>
  
  <p>This is the program that uses the User.pm</p>
  
  <pre><code>#!/bin/perl
  BEGIN {
    unshift(@INC, '/tmp'); # User.pm ===&gt; /tmp/User.pm
  }
  use User;
  
  my $rh_params = {
    name =&gt; 'Rebecca',
    age =&gt; 25,
    water =&gt; '2500cc'
  };
  my $user = User-&gt;new($rh_params);
  </code></pre>
  
  <p>After the program execution</p>
  
  <pre><code>Attribute (water) does not pass the type constraint because: Validation failed for 'Int' with value 2500cc at /usr/local/lib64/perl5/Moose/Object.pm line 24
      Moose::Object::new('User', 'HASH(0x157fcb8)') called at go.pl line 12
  </code></pre>
  
  <p>I would like to verify that the type does not meet the time, you can use the default value or null value instead, rather than terminate the program.</p>
  
  <p>Is there a solution?</p>