class bar { method foo () {}}
my bar $a = bar.new();
say so $a.can("foo");

True

my Int $b;
say so $b.can("foo");

False

I'm not sure this warrants a new _ok method.

On Fri, Mar 20, 2015 at 2:38 PM, Tom Browder <tom.brow...@gmail.com> wrote:
> I am trying to create a testing subroutine to detect if a class object
> has a certain method.
>
> I want it to look something like this:
>
>   my $obj = Foo.new();
>   can_ok($obj, 'method1');
>
>   sub can_ok($obj, Str $method_name) {
>     if $obj.{$method_name}:exists {
>       say "ok";
>       return True;
>     }
>     else {
>       say "not ok";
>      return False;
>     }
>   }
>
> A similar function can detect valid attributes, but this or variants
> I've tried don't.
>
> How can I test for the existence of a method?
>
> Thanks.
>
> Cheers!
>
> -Tom



-- 
Will "Coke" Coleda

Reply via email to