### ----------------------------------------------------
### -- InterceptAllMethods
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;
use InterceptAllMethods;

plan 4;

my @seen;
class Foo {
    method ^find_method(Mu \obj, Str $name) {
        my constant &the-method = proto method handler(|) {*}
        multi method handler(Foo:U: |c) {
            @seen.push("type", $name) if $name ne 'is-generic';
            use nqp;
            $name eq 'new'
              ?? nqp::create(obj)
              !! $name eq 'is-generic'
                ?? False
                !! $name
        }
        multi method handler(Foo:D: |c) {
            @seen.push("instance",$name);
            $name
        }

        &the-method
    }
}

my $foo := Foo.new;
ok infix:<=:=>($foo.WHAT, Foo), 'did we get a Foo';
is Foo.foo,  "foo", 'did Foo return foo';
is $foo.bar, "bar", 'did $foo return bar';

is @seen, "type new type foo instance bar", 'did we see all the calls';

# vim: expandtab shiftwidth=4


