Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by mascip (Pilgrim)
on Sep 09, 2012 at 17:01 UTC ( #992610=note: print w/replies, xml ) Need Help??


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

I just tried it on a simple package and it works :o)
You're right, as it's not a class i'm doing:

use Mod; Mod::initialize('argument');

It is more simple than the previous solutions, and does what i need. Thank you !

It is less 'elegant' though : there is an additional line of code to put in the client code, each time.
If someone knows how to use IMPORT i'm still interested in learning.

Replies are listed 'Best First'.
Re^5: How to pass an argument to a Module?
by tobyink (Abbot) on Sep 09, 2012 at 21:29 UTC

    Despite the Perl6::Export::Attrs pod, IMPORT should just be a plain old sub.

    sub IMPORT { ... }

    Here's a full example:

    use 5.010; use strict; { package Local::MyTest; no thanks; use Perl6::Export::Attrs; sub foobar :Export(:DEFAULT) { return 1; } sub IMPORT { say "in the IMPORT block! Got: @_"; } } use Local::MyTest qw(1 2 3 :DEFAULT); say "YEAH!" if foobar();
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992610]
help
Chatterbox?
[stevieb]: my RPi::WiringPi now fully supports: GPIO, LCDs, digital potentiometers, analog to digital converters, shift registers, barometric pressure sensor, direct access to SPI bus, and ability for more :)
[stevieb]: ...just need to perform many tests and POD review this week, then I'm going to put together some real projects and post about them

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-01-22 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (190 votes). Check out past polls.