189 if ($self->{ExtendedAccess}) {
190 # we are blessing here again, to get into the ::Extended namespace
191 # for inheriting the methods available overthere, which we doesn't have.
192 bless $self, 'Config::General::Extended';
193 eval {
194 require Config::General::Extended;
195 };
####
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::Extended)) {
17 printf "\tIs \$self a %s? (\$self->isa(%s) returns): %s\n",
18 $classTest, $classTest, $self->isa ($classTest) ? 'true' : '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::Extended)) {
26 printf "\tIs \$self a %s? (\$self->isa(%s) returns): %s\n",
27 $classTest, $classTest, $self->isa ($classTest) ? 'true' : 'false';
28 }
29 $self;
30 }
31
32 1;
33
34 use Config::General; # This is the way this works (see ExtendedAccess)
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
####
First, here's the contents of our config file:
FooThing = 1
FooThang = 7
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) returns): true
Is $self a Config::General::Extended? ($self->isa(Config::General::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) returns): true
Is $self a Config::General::Extended? ($self->isa(Config::General::Extended) returns): false