From 96431a38af44bb41e6ef2b71c178e01f94569b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 4 Apr 2014 12:06:31 +0200 Subject: [PATCH 1/3] Do not create %FIELDS if it doesn't exists Checking the existence of %FIELDS was creating it. This could trigger 'once' warnings on (at least) perl 5.10.1. --- lib/Test/MockObject/Extends.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Test/MockObject/Extends.pm b/lib/Test/MockObject/Extends.pm index 682624a..f976313 100644 --- a/lib/Test/MockObject/Extends.pm +++ b/lib/Test/MockObject/Extends.pm @@ -30,7 +30,7 @@ sub new # Fields now locks the hash as of 5.9.0 - #84535 if ($^V gt v5.9.0 && blessed( $fake_class ) && do { no strict 'refs'; - (%{$parent_class . '::FIELDS'}) # uses fields + exists ${$parent_class . '::'}{FIELDS} # uses fields }) { # bypass prototypes &Hash::Util::unlock_hash(\%$fake_class); From d8b352823a656dc84db99a14c45a80ae77b07631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 4 Apr 2014 14:08:23 +0200 Subject: [PATCH 2/3] Constify $^V check to allow inlining Allows perl to optimize the generated code. --- lib/Test/MockObject/Extends.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Test/MockObject/Extends.pm b/lib/Test/MockObject/Extends.pm index f976313..a0b6148 100644 --- a/lib/Test/MockObject/Extends.pm +++ b/lib/Test/MockObject/Extends.pm @@ -17,6 +17,8 @@ sub import use Devel::Peek 'CvGV'; use Scalar::Util 'blessed'; +use constant PERL_5_9 => $^V gt v5.9.0; + sub new { my ($class, $fake_class) = @_; @@ -28,7 +30,7 @@ sub new my $self = blessed( $fake_class ) ? $fake_class : {}; # Fields now locks the hash as of 5.9.0 - #84535 - if ($^V gt v5.9.0 && blessed( $fake_class ) && do { + if (PERL_5_9 && blessed( $fake_class ) && do { no strict 'refs'; exists ${$parent_class . '::'}{FIELDS} # uses fields }) { From 7885276b51cc41571b4f78dd4f34f48675f639e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 4 Apr 2014 14:14:03 +0200 Subject: [PATCH 3/3] Do not load fields.pm and Hash::Util When we use them (in T::MO::Extends), this is to extends a fields-based class. In that case, the original class has already loaded those modules. --- lib/Test/MockObject/Extends.pm | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Test/MockObject/Extends.pm b/lib/Test/MockObject/Extends.pm index a0b6148..d030c10 100644 --- a/lib/Test/MockObject/Extends.pm +++ b/lib/Test/MockObject/Extends.pm @@ -4,8 +4,6 @@ use strict; use warnings; use Test::MockObject; -use Hash::Util (); -use fields (); sub import {