开发者

How does passing parameters to a perl module when using it work?

开发者 https://www.devze.com 2023-03-26 12:28 出处:网络
Here\'s an example of what I mean use SOAP::Lite +trace => [ qw( debug ) ]; So what is +trace in SOAP::Lite? I\'m guessing it is part of a package scoped hash? I mean if I wanted to implement si

Here's an example of what I mean

use SOAP::Lite +trace => [ qw( debug ) ];

So what is +trace in SOAP::Lite? I'm guessing it is part of a package scoped hash? I mean if I wanted to implement similar syntax into one of my modules how would I do it?

How would this work if I also needed to import symbols, e.g.

use Foo qw( some_function );

Would this work?

use Foo qw( some_function ) +option => 'bar';

would any additional magic be needed in the module that allows you to pass things like this?

note: not sure I like the title of the开发者_如何学JAVA question, feel free to reword


When you do use Foo @args, what happens behind the scenes is equivalent to this:

BEGIN { 
    require 'Foo.pm';
    Foo->import( @args );
};

So in this case, use SOAP::Lite +trace => [ qw( debug ) ] gets turned into an import call like this:

SOAP::Lite->import( '+trace' => [ 'debug' ] );

Precisely how one implements the import routine is up to the module author. Most modules use the standard import provided by Exporter, but you can put anything you want there and it will be executed at use time.

0

精彩评论

暂无评论...
验证码 换一张
取 消