in reply to Config::General inheritance [SOLVED]

Good points, Corion & Grandfather. I'll try to oblige: First, the way Config::General insists on doing business, you include C::G and tell it you want to use the Extended module through the ExtendedAccess parameter (see code). Looking at the code, it does indeed pull in that module like this:
189 if ($self->{ExtendedAccess}) { 190 # we are blessing here again, to get into the ::Extended name +space 191 # for inheriting the methods available overthere, which we do +esn't have. 192 bless $self, 'Config::General::Extended'; 193 eval { 194 require Config::General::Extended; 195 };
(This appears in Config::General)
This funkiness may indeed be the source of my frustration... it doesn't look like a traditional inheritance is set up here, despite it saying so in the comment. :) Am I right?
Ok, so now a sample piece of code. First the code:
1 #!perl 2 use strict; 3 use warnings; 4 use lib 'perlmods/lib'; 5 6 package MyConfig; 7 use base qw (Config::General); 8 9 sub new { 10 my $class = shift; 11 my @attr = @_; 12 my $self = new Config::General (@attr); 13 print "\n"; 14 printf "Now we haven't reconsecrated \$self, so: BAR: %s\n", $ +self->BAR; 15 print "And this looks right:\n"; 16 for my $classTest (qw (Config::General Config::General::Extend +ed)) { 17 printf "\tIs \$self a %s? (\$self->isa(%s) returns): %s\n" +, 18 $classTest, $classTest, $self->isa ($classTest) ? 'tru +e' : 'false'; 19 } 20 print "\nLo! the blessing ensues...\n"; 21 bless $self, $class; 22 my $bat = eval ('$self->BAR'); 23 printf "Uh-oh: BAR: %s\n", $@; 24 print "Moreover:\n"; 25 for my $classTest (qw (Config::General Config::General::Extend +ed)) { 26 printf "\tIs \$self a %s? (\$self->isa(%s) returns): %s\n" +, 27 $classTest, $classTest, $self->isa ($classTest) ? 'tru +e' : 'false'; 28 } 29 $self; 30 } 31 32 1; 33 34 use Config::General; # This is the way this works (see ExtendedAcc +ess) 35 36 my $cf = new Config::General ( 37 -ExtendedAccess => 1, # This tells C::G to allow object access + and AUTOLOAD conveninces (like BAR here) 38 -ConfigFile => 'fooConfig', 39 ); 40 41 print "First, here's the contents of our config file:\n"; 42 system "cat fooConfig"; 43 print "\n"; 44 printf "FooThang: %s\n", $cf->obj ('FOO')->value ('FooThang'); 45 printf "BAR: %s\n", $cf->BAR; 46 print "All well and good.\n"; 47 undef $cf; 48 49 my $mcf = new MyConfig ( 50 -ExtendedAccess => 1, 51 -ConfigFile => 'fooConfig', 52 ); 53 54
And then the output when you run this (perl 5.8.8, Config::General v2.42)
First, here's the contents of our config file: <FOO> FooThing = 1 FooThang = 7 </FOO> BAR = semisomething string FooThang: 7 BAR: semisomething string All well and good. Now we haven't reconsecrated $self, so: BAR: semisomething string And this looks right: Is $self a Config::General? ($self->isa(Config::General) retur +ns): true Is $self a Config::General::Extended? ($self->isa(Config::Gene +ral::Extended) returns): true Lo! the blessing ensues... Uh-oh: BAR: Can't locate object method "BAR" via package "MyConfig" at + (eval 14) line 1. Moreover: Is $self a Config::General? ($self->isa(Config::General) retur +ns): true Is $self a Config::General::Extended? ($self->isa(Config::Gene +ral::Extended) returns): false