Skip to content

Commit d389710

Browse files
author
Simon Wistow
committed
Better test for whether something is loaded or not
1 parent 0ec1af3 commit d389710

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

t/22trigger.t

+19-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,25 @@ ok(@plugins = $foo->plugins, "Ran plugins");
1313
ok(@errors = $foo->errors, "Got errors");
1414
is_deeply([sort @plugins], ['TriggerTest::Plugin::After', 'TriggerTest::Plugin::CallbackAllow'], "Got the correct plugins");
1515
is_deeply([@errors], ['TriggerTest::Plugin::Error'], "Got the correct errors");
16-
ok(keys %{TriggerTest::Plugin::CallbackDeny::}, "CallbackDeny has been required");
17-
ok(!keys %{TriggerTest::Plugin::Deny::}, "Deny has not been required");
16+
ok(_is_loaded('TriggerTest::Plugin::CallbackDeny'), "CallbackDeny has been required");
17+
ok(!_is_loaded('TriggerTest::Plugin::Deny'), "Deny has not been required");
18+
19+
20+
# Stolen from Module::Loaded by Chris Williams (bingOs)
21+
sub _is_loaded {
22+
my $pm = shift;
23+
my $file = __PACKAGE__->_pm_to_file( $pm ) or return;
24+
return $INC{$file} if exists $INC{$file};
25+
return;
26+
}
27+
28+
sub _pm_to_file {
29+
my $pkg = shift;
30+
my $pm = shift or return;
31+
my $file = join '/', split '::', $pm;
32+
$file .= '.pm';
33+
return $file;
34+
}
1835

1936
package TriggerTest;
2037

0 commit comments

Comments
 (0)