tags:

views:

79

answers:

1

What is the significance and what is the effect of something like this (I think it is object oriented):

use My::Confusing::Code
{
   CITY  => { MODIFY      => 1,           
              DEFAULT     => My::Even::more::complicated->func(), 
            },
   STATE => { MODIFY      => 1,           
              DEFAULT     => 'Concatenate()', 
            },
   COUNTRY => { MODIFY       => 1,
                REQUIRED     => 0,
                DEFAULT      => 'Gabon',
               }, 
}

What would the My::Confusing::Code package/module/class do with the stuff in the curly braces. Do the curly braces enclose a code block or a hash reference?

+12  A: 

It's a hash reference.

When you do use Module::Foo @stuff;, what's happening behind-the-scenes is:

BEGIN { 
    require "Module/Foo.pm";
    Module::Foo->import( @stuff );
};

Normally, the parameters passed to import are used to ask for symbols to be exported into your namespace. (The typical way to do this is to use the import subroutine from the standard Exporter module.) But in this case, the module author has written a custom import method that takes a hashref and does stuff with it.

friedo
There are many other reasons for a module to implement an `import` method.
mobrule
Thanks. Yes, the "import" function in this case uses the hash reference passed to it to initialize an entry in it's own set of symbol tables for the modules that use it. This code implements a perl framework of sorts.