can_ok('Class', qw(method_a method_b));


can_ok($object, qw(method_a method_b));

In order to nicely test if a module has certain methods you can use the can_ok() function of Test::More. It can be used both on modules and on objects.


examples/test-perl/t/can_ok.t
use strict;
use warnings;

use Test::More tests => 2;

use FindBin;
use lib "$FindBin::Bin/../lib";
use MyTools;

can_ok('MyTools', 'fibonacci');
can_ok('MyTools', 'make_tea');

Output:


1..2
ok 1 - MyTools->can('fibonacci')
not ok 2 - MyTools->can('make_tea')
#   Failed test 'MyTools->can('make_tea')'
#   at examples/test-perl/t/can_ok.t line 11.
#     MyTools->can('make_tea') failed
# Looks like you failed 1 test of 2.