New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fields::inherit doesn't bless derived package's \%FIELDS, results in phash deprecation errors. #7044
Comments
From @nothingmuchCreated by @nothingmuchThough reported under 5.8.1, this bug was tested for in 5.8.3. I When using the fields pragma, in something like <<EOF; package Foo; use fields qw/foo/; sub new { package Bar; use base qw/Foo/; package main; new Foo; # will not generate an error EOF In 5.8.1 the blessing of \%FIELDS into the 'pseudohash' class was &fields::inherit doesn't bless that referant though, so errors for a A solution could be to do my $derived_fields = \%{"$derived\::FIELDS"}; which resolves the issue. if (ref $derived_fields !~ /^pseudohash/){ can also be done, to supress reblessing (why?). This should be wrapped in if ($] < 5.0009){ } as 5.9 changes %FIELDS to be a has locked with &Hash::Utils::lock_keys. Here is a patch to base.pm, which now handles fields::inherit, and the EOF Inline Patchdiff -ru perl-5.8.3/lib/base/t/fields-base.t perl-5.8.3-inherit-has-no-fields-phash-warning/lib/base/t/fields-base.t
--- perl-5.8.3/lib/base/t/fields-base.t Tue Sep 16 08:28:46 2003
+++ perl-5.8.3-inherit-has-no-fields-phash-warning/lib/base/t/fields-base.t Sun Jan 18 16:47:02 2004
@@ -20,7 +20,7 @@
}
use strict;
-use Test::More tests => 25;
+use Test::More tests => 26;
BEGIN { use_ok('base'); }
@@ -194,3 +194,23 @@
::like( $@, qr/Can't multiply inherit %FIELDS/i, 'Again, no multi inherit' );
+# Test that a package with no fields can inherit from a package with fields, and that pseudohash messages don't show up
+package B9;
+use fields qw(b1);
+
+sub _mk_obj { fields::new($_[0])->{'b1'} };
+
+package D9;
+use base qw(B9);
+
+package main;
+
+{
+ my $w = 0;
+ local $SIG{__WARN__} = sub { $w++ };
+
+ B9->_mk_obj();
+ D9->_mk_obj(); # used tp emit a warning that pseudohashes are deprecated, because %FIELDS wasn't blessed.
+
+ is ($w, 0, "pseudohash warnings in derived class with no fields of it's own");
+}
diff -ru perl-5.8.3/lib/base.pm perl-5.8.3-inherit-has-no-fields-phash-warning/lib/base.pm
--- perl-5.8.3/lib/base.pm Fri Dec 19 10:13:27 2003
+++ perl-5.8.3-inherit-has-no-fields-phash-warning/lib/base.pm Sun Jan 18 16:10:31 2004
@@ -42,7 +42,11 @@
# Shut up a possible typo warning.
() = \%{$_[0].'::FIELDS'};
- return \%{$_[0].'::FIELDS'};
+ my $f = \%{$_[0].'::FIELDS'};
+
+ bless $f, 'pseudohash' if ($] < 5.009 and ref($f) ne 'pseudohash'); # should be centrallized in fields? perhaps fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' } is used here anyway, it doesn't matter.
+
+ return $f;
}
sub import {
The test classes could also be B8 and D8, with only package B8 sub _mk_obj { $_[0]->fields::new()->{'_b1'} }; package main; B8->_mk_obj(); but the naming scheme was not so coherent to me. Plus, being hermetic Perl Info
|
From @iabynOn Sun, Jan 18, 2004 at 03:15:46PM -0000, nothingmuch@woobling.org (via RT) wrote:
Thanks, applied to bleedperl as change #22208. I took the liberty in your Dave. -- Change 22208 by davem@davem-percy on 2004/01/24 16:13:17 Subject: [perl #24942] fields::inherit doesn't bless derived Affected files ... ... //depot/perl/lib/base.pm#26 edit Differences ... ==== //depot/perl/lib/base.pm#26 (text) ==== @@ -38,11 +38,26 @@ -sub get_fields { - return \%{$_[0].'::FIELDS'}; sub import { ==== //depot/perl/lib/base/t/fields-base.t#2 (text) ==== @@ -20,7 +20,7 @@ use strict; BEGIN { use_ok('base'); } @@ -194,3 +194,27 @@ +# Test that a package with no fields can inherit from a package with |
The RT System itself - Status changed from 'new' to 'open' |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#24942 (status was 'resolved')
Searchable as RT24942$
The text was updated successfully, but these errors were encountered: