How to use the arguments to use() in the package being used

Howdy,=20
The subject says it all believe it or not :)

What I'm trying to figure out is how to pass an argument=20
(pragma I believe is the proper term) to use() and do=20
sonethign in the package based on it.

I've looked at CGI.pm source but can't seem to track it down.=20
(Similar idea as to CGIs -oldstyle_urls -newstyel_urls)
http://search.cpan.org/~lds/CGI.pm-3.04/CGI.pm#PRAGMAS

What I'd like to do is something like this:

# for old time's sake we'll just use our favorite module
use Foo::Monkey qw(:Foo :Bar -doamazingthings);

#then in Foo::Monkey:
package Foo::Monkey;

[mandatory module goodies snipped]

if(?????) { # IE if -doamazingthings was specified in the use statement
	# do some amazing things here
}

[mandatory module goodies snipped]

How do I do that?? Are those arguments stored in a special array =
somewhere??

TIA
DMuey
0
dmuey
2/4/2004 3:52:56 PM
perl.beginners 29344 articles. 3 followers. Follow

9 Replies
1873 Views

Similar Articles

[PageSpeed] 48

On Feb 4, Dan Muey said:

># for old time's sake we'll just use our favorite module
>use Foo::Monkey qw(:Foo :Bar -doamazingthings);

Well, depending on what you want to do with the arguments, you might want
to use the Exporter module to handle exporting functions, variables, etc.

  perldoc perlmod (look for "Perl Modules")
  perldoc Exporter

When you say

  use Module qw( args go here );

this is translated into

  BEGIN {
    require Module;
    Module->import(qw( args go here ));
  }

Thus, you need an 'import' method in Module::.

  package Module;

  sub import {
    my $class = shift;
    print "You gave me (@_)\n";
  }

It's up to you to do something with @_.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]

0
japhy
2/4/2004 4:06:45 PM
>>>>> "Dan" == Dan Muey <dmuey@infiniplex.com> writes:

Dan> What I'm trying to figure out is how to pass an argument 
Dan> (pragma I believe is the proper term) to use() and do 
Dan> sonethign in the package based on it.

$ perldoc -f use

[...]
            Imports some semantics into the current package from the named
            module, generally by aliasing certain subroutine or variable
            names into your package. It is exactly equivalent to

                BEGIN { require Module; import Module LIST; }

            except that Module *must* be a bareword.

Therefore, it's calling a class method in your module called "import".
Create your own import method, instead of inheriting Exporter's import,
and you're all set.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
0
merlyn
2/4/2004 4:30:32 PM
> On Feb 4, Dan Muey said:
>=20
> ># for old time's sake we'll just use our favorite module
> >use Foo::Monkey qw(:Foo :Bar -doamazingthings);
>=20
> Well, depending on what you want to do with the arguments,=20
> you might want to use the Exporter module to handle exporting=20
> functions, variables, etc.
>=20
>   perldoc perlmod (look for "Perl Modules")
>   perldoc Exporter

I do use Exporter actually should've mentioned that sorry, I'll check =
out your perldocs to.
Thanks

>=20
> When you say
>=20
>   use Module qw( args go here );
>=20
> this is translated into
>=20
>   BEGIN {
>     require Module;
>     Module->import(qw( args go here ));
>   }
>=20
> Thus, you need an 'import' method in Module::.
>=20
>   package Module;
>=20
>   sub import {
>     my $class =3D shift;
>     print "You gave me (@_)\n";
>   }
>=20

Perfect! Exactly what I needed.

> It's up to you to do something with @_.
>=20

Thanks Jeff

> --=20
> Jeff "japhy" Pinyan
0
dmuey
2/4/2004 5:31:54 PM
Jeff 'Japhy' Pinyan wrote:
>
> When you say
>
>   use Module qw( args go here );
>
> this is translated into
>
>   BEGIN {
>     require Module;
>     Module->import(qw( args go here ));
>   }

That's an interesting point Jeff. You're right that it's

 Module->import()

instead of

 Module::import()

as 'import' will be inherited in the (common) case that
Module ISA Exporter.

Rob




0
rob
2/4/2004 6:34:13 PM
On Feb 4, Rob Dixon said:

>That's an interesting point Jeff. You're right that it's
>
> Module->import()
>
>instead of
>
> Module::import()
>
>as 'import' will be inherited in the (common) case that
>Module ISA Exporter.

And also, 'Module' is sent as the first arg to import().

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]

0
japhy
2/4/2004 8:53:02 PM
Dan Muey wrote:

> Howdy,
> The subject says it all believe it or not :)
>
> What I'm trying to figure out is how to pass an argument
> (pragma I believe is the proper term) to use() and do
> sonethign in the package based on it.
>
> I've looked at CGI.pm source but can't seem to track it down.

But did you perldoc?  Munging source may sometimes be useful, but more often
than not it throws you headlong into implementation details of someone ele's
code without shedding much light on how to use it.  By entering:
perldoc -f use
at the cmmand-line, you should get direct instruction on proper usage.  I just
checked, and the returned text proceeds immediately into a detailed explanation
of the parameters and their use.

Joseph



0
rjnewton
2/5/2004 7:43:33 PM
> Dan Muey wrote:
>=20
> > Howdy,
> > The subject says it all believe it or not :)
> >
> > What I'm trying to figure out is how to pass an argument (pragma I=20
> > believe is the proper term) to use() and do sonethign in=20
> the package=20
> > based on it.
> >
> > I've looked at CGI.pm source but can't seem to track it down.
>=20
> But did you perldoc?  Munging source may sometimes be useful,=20

Shamefully, no :(=20
I usually do but this time I was just backwards!

> but more often than not it throws you headlong into=20
> implementation details of someone ele's code without shedding=20
> much light on how to use it.  By entering: perldoc -f use at=20
> the cmmand-line, you should get direct instruction on proper=20
> usage.  I just checked, and the returned text proceeds=20
> immediately into a detailed explanation of the parameters and=20
> their use.
>=20
> Joseph
>=20
>=20
>=20
>=20
0
dmuey
2/5/2004 8:32:08 PM
Dan Muey wrote:

> >
> > But did you perldoc?  Munging source may sometimes be useful,
>
> Shamefully, no :(
> I usually do but this time I was just backwards!

Cool.  I'm afraid I sent the response before I noticed the signature.  I
know that you know better (;-o)

Joseph

0
rjnewton
2/5/2004 11:10:20 PM
> Dan Muey wrote:
>=20
> > >
> > > But did you perldoc?  Munging source may sometimes be useful,
> >
> > Shamefully, no :(
> > I usually do but this time I was just backwards!
>=20
> Cool.  I'm afraid I sent the response before I noticed the=20
> signature.  I know that you know better (;-o)

Thanks for the vote of confidence,=20
sometimes I just can't help but do things SSA!
:)

>=20
> Joseph
>=20
>=20
0
dmuey
2/5/2004 11:43:48 PM
Reply:

Similar Artilces:

When to use ( and when to use ((?
I'm just not getting it. When do you use ( in a statement, when do you need to use ((, and is the space after either or both mandatory? For example, I coded this statement: if (( $_ eq $bad_guys_ip )) { more_stuff_here }; Why the two (( in an if? And why does it seem to not work when I miss the space after the ((? Thanx! Mark me as... /Corn-fused|Dense/ > I'm just not getting it. >=20 > When do you use ( in a statement, when do you need to use ((, and is > the space after either or both mandatory? >=20 > For example, I coded this sta...

Using Using
I have just completed reading a chapter in my book on performance. The books says to speed up performance on your web site you should use the using statement when opening connections. My question is how do you catch errors if you are using this as apposed to a try catch block.thanksBryan  Why would you use it as an alternative to a try/catch statement. Couldn't you just do something like  public void UsingSomeMethod() { try { SomeMethod(); } catch(SomeException e) { /// do something useful }}public void SomeMethod() { using (Something) { ...

cannot use other packages when using CGI
Hi all, I am using CGI package in my script. When i try to use other packages like LWP::UserAgent inside the same script, it is not working in the web environment. But when i run the script from the command prompt it is working fine. Anyone please do solve my problem. Thanks +ACY- Regards, wilson. ...

why to use 1)use CGI,2)use Strict ,3)use Carp in script
hi why we r using 1)use CGI, 2)use Strict, 3)use Carp in the begining of script sometimes. What is the use of it.Is the files CGI.pm,Strict.pm,Carp.pm default with PERL. Thnx __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com On Thu, 2004-11-04 at 09:31, supriya devburman wrote: > hi Hi > why we r using > 1)use CGI, We only use CGI when we want to use methods from that module (usually on web pages); see `perldoc CGI` for more information on what you...

DSRepair
Any good information on when to use Dsrepair which settings to use ? Is this something that should be run on a monthly /weekly basis and which of the million settings should be turned on:o) Use DSREPAIR to fix a broken database - that is what it is intended to be used for. It is not intended to be used as a "regular maintenance" tool. Using it in this way can in fact hide more serious issues by removing symptoms that indicate a more serious problem. Use it as a last resort for trying to identify problems with the database. Run health checks weekly or monthly (...

FreeAndNil to use or not to use
After reading these debates about FreeAndNil I separated the people into two categories: The first one says: "You should have a perfect design which prohibits errors from happening. So, if you have a perfect design then FreeAndNil is not necessary so you should not use it. If we see FreeAndNil in your code then it means that your design is not perfect." The second one says: "Yes, we agree that we should have a perfect design which prohibits errors from happening and we do our best in order to create a perfect design. However our practice says that it is better ...

When to use/not use ViewState
I'm creating a client app and I'm wondering is it neccessary to enable viewstate for "All" the fields. When should you use viewstate and when should you "NOT" use viewstate. Thanks.Daniel It depends on your requirements. if you dont need to preserve the contents of inputboxes past the initial post then dont turn on viewstate for them. you could take the approach of turning off viewstate for everything, and then turn it back on item by item as you find you need it. It shouldnt just be enabled for everything as it does make the page heavier - especially with ...

To use or not to use Delphi
Sadly, it seems to me that there is a sort of race between the two threads, for and against using Delphi in new projects, with more or less the same users posting in both threads. Arguments are fiercely debated in both camps. Borland had their own vision. As a community, now that Delphi has changed ownership I believe we should try to be more consistent, more clear, and more articulate in what we expect from Embercadero in terms of Delphi. We can contribute to keeping Delphi alive and moving in the right direction. "Laurent Cocea" schrieb: > Sadly, it seems to me that there ...

To use signatures or not to use?
--001a11c3871a8a8fe2051b7b8b18 Content-Type: text/plain; charset=UTF-8 Dear all, Perl now has subroutine signatures. However, they are marked as experimental feature. As I really like it, I'm always tempted to use it. On the other hand, I don't want to wast efforts to something I have to roll back. So, does anyone know the tendency if signatures are going to stay? I'm not looking for the standard "do if you want to do it because TIMTOWTDI" answer, it will not help me. I'm looking for rumors, or eventually an assessment from the people who did the fe...

To use DNN or not to use?
Hello,I am developing a community web based appication for non-profits and social service agencies in our county, that will be used to provide and track client services in a single datastore.Some built in features that dnn has is what I need, but I need custom tree navigation, list views, edit on the fly, several customized layers for data access, etc.I am familiar with asp.net, but not very familiar with dnn.  I installed  dnn on a friends website but never had time to configure and learn more about it.What are the general rules when deciding when to use dnn and when not...

this keyword- to use or not to use???
While reading some articles I came across this sample code which uses the "this" keyword. Is this best practice?         this.sqldsCustomerDetails.SelectParameters.Clear();        this.sqldsCustomerDetails.SelectParameters.Add("customerid", Convert.ToString(this.gvCustomers.DataKeys[row.RowIndex].Value));        this.dvCustomerDetail.DataSource = this.sqldsCustomerDetails;        this.dvCustomerDetail.DataBind(); In my code I usual...

I used to use Firefox until...
Name: Dan Product: Firefox Summary: I used to use Firefox until... Comments: Firefox takes forever to load now, even the absolute newest version. It has become clunky and everyone I know has moved on to another browser. I prefer Chrome. I suggest adding some sort of configuration optimization tool as well as toolbar/add-on install/hijack prevention. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a re...

Why using use strict;
Hi all, I know why I should use "use strict;" but what happen if I use "use strict;" then if the code is OK, I delete this line? Shouldn't it work the same without this line if the code has no problems? Thanks. Teddy, orasnita@home.ro why would you want to do that Octavian? "use strict" is a sanity safety net. What your saying is like "I know why I should use safety belt whilst driving my car but what if I took it off?" - of course you can do it but beware of the consequences. joel -----Original Message----- From: ...

How to use net use?
Please can any one tell me how to use the dos command net use properly? I have read the help but can't seem to get it to work. Keep getting sytax error message. Thanks in advance. "Beowulf" <who-knows@no-one.com> wrote in message news:9krutk$puu$1@news.grc.com... > Please can any one tell me how to use the dos command net use properly? > > I have read the help but can't seem to get it to work. Keep getting sytax > error message. what are you trying to do? There are about 50 options to "net use" that do a ton of different thin...

Web resources about - How to use the arguments to use() in the package being used - perl.beginners

Argument (linguistics) - Wikipedia, the free encyclopedia
In linguistics , an argument is an expression that helps complete the meaning of a predicate . Most predicates take one, two, or three arguments. ...

Brexit? David Cameron outlines arguments for UK EU referendum
WHEN UK Prime Minister David Cameron stepped up to the microphone last week, he was in no mood to beat around the bush.

The White House's top spokesman had an intense argument with a Fox News host over the Paris attack
... said. "He called this a 'setback.' Why? Just a 'setback' seems cavalier. But go ahead and answer the question." Earnest repeated his argument ...

Arguments that Water Might Run Uphill Are Endless
... Center George Mason University Fairfax, VA 22030 Several other problems, in addition to the one highlighted above, infect Smith’s argument. ...

Pro-Hillary Mayor Makes The Most Shocking Argument Yet For Denying Syrian Refugees
Pro-Hillary Mayor Makes The Most Shocking Argument Yet For Denying Syrian Refugees

Let's have an argument about encryption
Government officials have been vexed for quite some time now that they can't surveil communications that use end-to-end encryption. Never mind ...

Saturday Night Live Knows How To Quell Thanksgiving Arguments
This holiday season, let Adele help you soothe those inevitable family arguments around the dinner table.

US, China officials get into heated argument over Tibet
US, China officials get into heated argument over Tibet

Flaws in "Economics 101" Arguments Pose Grave Risk to Internet Commenters
As you all know, there is no internet comment more devastating and definitive than saying something is “Economics 101”—thereby proving that you ...

The Latest: Closing Arguments Presented in Ex-Coal CEO Trial
The Latest: Jurors hear closing arguments in ex-coal CEO's trial; defense called no witnesses

Resources last updated: 11/28/2015 8:46:12 AM