Skip to content

Commit

Permalink
Make sure we can redefine a function in 'main'
Browse files Browse the repository at this point in the history
This is broken with SUPER 1.17, we need a version >1.20

This is bumping the version requirement for SUPER to 1.20*
and also adding one exception for the package namespace 'main'
  • Loading branch information
atoomic authored and geofffranks committed Feb 19, 2020
1 parent 0538fe1 commit 7558aa9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ my $builder = Module::Build->new(
'Module::Build' => '0.38',
},
requires => {
'perl' => 5.006,
'perl' => 5.006,
'Carp' => 0,
'Scalar::Util' => 0,
'SUPER' => 0,
'SUPER' => '1.20',
},
build_requires => {
'Test::More' => 0.88,
Expand Down
2 changes: 1 addition & 1 deletion lib/Test/MockModule.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sub new {
croak "Invalid package name $package";
}

unless ($package eq "CORE::GLOBAL" || $args{no_auto} || ${"$package\::VERSION"}) {
unless ($package eq "CORE::GLOBAL" || $package eq 'main' || $args{no_auto} || ${"$package\::VERSION"}) {
(my $load_package = "$package.pm") =~ s{::}{/}g;
TRACE("$package is empty, loading $load_package");
require $load_package;
Expand Down
15 changes: 15 additions & 0 deletions t/main.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use warnings;
use strict;

use Test::More;
use Test::Warnings;

use Test::MockModule;

sub fourofour { 404 }

my $mocker = Test::MockModule->new('main')->redefine( fourofour => 200 );

is fourofour(), 200, "can mock a function in main # need SUPER > 1.17";

done_testing();

0 comments on commit 7558aa9

Please sign in to comment.