Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: How to pass an argument to a Module?

by Anonymous Monk
on Sep 09, 2012 at 17:00 UTC ( #992609=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How to pass an argument to a Module?
in thread How to pass an argument to a Module?

Does anyone know how to use this IMPORT block properly?

Presumably the author. Seeing how the module never tests this IMPORT block business (Perl6-Export-Attrs-0.0.3/t/00.load.t), I would complain to the author.

You can probably get away with writing  sub IMPORT {} , cause that works for BEGIN/END/... also


Comment on Re^3: How to pass an argument to a Module?
Download Code
Re^4: How to pass an argument to a Module?
by mascip (Pilgrim) on Sep 09, 2012 at 17:05 UTC

    IMPORT{ print "inside the IMPORT block, with arguments @_\n"; }
    works but does the same thing as when i override import() : my subroutines are not exported to the symbol table.
    I'll write to the author.

Re^4: How to pass an argument to a Module?
by mascip (Pilgrim) on Sep 09, 2012 at 18:25 UTC

    The author's response (i tried it and it works, with sub IMPORT) :

    This is not a bug in the module.
    The problem is that you specified:

    sub subr :Export(:DEFAULT) { return "subr() was called\n"; }
    :DEFAULT exports are only exported when the module is use'd with no arguments at all.
    But then you call:
    use Mod3 'argument';
    with an argument, so the :DEFAULT exports don't happen.

    You could fix this by specifying:

    sub subr :Export(:MANDATORY) { return "subr() was called\n"; }
    (assuming you always want subr() exported).
    If not, then you need to specifically request subr(), like this:
    use Mod3 '&subr', 'argument';
    or request all the defaults, like this:
    use Mod3 ':DEFAULT', 'argument';

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992609]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-07-30 02:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls