http://www.perlmonks.org?node_id=1012009

anaconda_wly has asked for the wisdom of the Perl Monks concerning the following question:

I'm reading Win32::TieRegistry.pm and can't understand the relation between $RegObj and $Registry by code. Is anyone willing to help me? Thanks in advance! As code snippet below

$RegObj->Tie( \%RegHash ); $Registry= \%RegHash; bless $Registry;

I can understand $RegObj is a blessed object holding something like the access options. $Registry is blessed into the same package and a ref to %RegHash, the virtual root of the registry tree stored as a hash.

My first question is: As I didn't understand Tie clearly, How $RegObj and $Registry affect to each other after Tied?

My second quetion is I didn't know how the %RegHash got its contents regarding the default setting in $RegObj?

As when using, we only need to "use Win32::TieRegistry", then use $Registry->{$myKey} will return the registry hash I want, too simple to understand. No "new" call to load from registry.

I read the author override the import function in EXPORT to support a user-defined options. If I want to add another default $RegObj2 and $Registry2, how can I make it through just after "use" and can then get $Registry2 filled? I don't know if I state my problem clear....Sorry seems too long.

OK, I understand some now. The TieHash in TieRegistry is auto called by Perl when tying and called sub new. $Registry(\%RegHash) is used by user like a real hash and will call the underlaid TieRegistry method with blessed $RegObj(since tied).