if $obj.^can($method_name) {...
Am 20.03.2015 um 19:38 schrieb Tom Browder:
> 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- Object Introspection for Existence of Methods: How? Tom Browder
- Re: Object Introspection for Existence of Methods: How? Will Coleda
- Re: Object Introspection for Existence of Methods: ... Tom Browder
- Re: Object Introspection for Existence of Metho... Will Coleda
- Re: Object Introspection for Existence of M... Tom Browder
- Re: Object Introspection for Existence of Methods: How? Tobias Leich
- Re: Object Introspection for Existence of Methods: ... Tom Browder
- Re: Object Introspection for Existence of Metho... Tom Browder
- Re: Object Introspection for Existence of M... Henk van Oers
- Re: Object Introspection for Existence... Tom Browder
- Re: Object Introspection for Exist... Henk van Oers
- Re: Object Introspection for E... Tom Browder
- Re: Object Introspection for E... Henk van Oers
- Re: Object Introspection for E... Tom Browder
- Re: Object Introspection for E... Moritz Lenz
- Re: Object Introspection for E... Tom Browder
