title: How do you add a method to an existing class in Perl 6?
body: <p>The <a href="http://doc.perl6.org/type/Int" rel="nofollow noreferrer">Int class</a> has a method <code>is_prime</code>, so I figured, just for giggles, I'd like to add some other methods to <code>Int</code> for some of my hobby projects that do number theory stuff.</p>
  
  <p>I thought I could do something like this:</p>
  
  <pre><code>class Int {
      method is-even (Int:D $number ) returns Bool:D {
          return False if $number % 2;
          return True;
          }
      }
  
  say 137.is-even;
  </code></pre>
  
  <p>But that doesn't work:</p>
  
  <pre><code>===SORRY!===
  P6opaque: must compose before allocating
  </code></pre>
  
  <p>I don't know if this means that I can't do that or that I'm doing it incorrectly. </p>
  
  <p>I could easily make a new class that inherits from <code>Int</code>, but that's not what I'm interested in:</p>
  
  <pre><code>class MyInt is Int {
      method is-even () returns Bool:D {
          return False if self % 2;
          return True;
          }
      }
  
  my $n = MyInt.new(138);
  say $n.is-even;
  </code></pre>
  
  <p>I'm not looking for workarounds or alternate solutions.</p>