Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of a code block after a "use module"?

Tags:

module

perl

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?

like image 235
paz9 Avatar asked Jul 21 '10 15:07

paz9


1 Answers

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.

like image 175
friedo Avatar answered Nov 01 '22 11:11

friedo