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?




Reply via email to