Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

use base qw(Module); (was Re: Re: Re: Calling a subroutine located in a module)

by brother ab (Scribe)
on Nov 02, 2001 at 12:35 UTC ( [id://122767]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Calling a subroutine located in a module
in thread Calling a subroutine located in a module

May be it is out of the thread but I must say a word.

Be carefull with base pragma, it will only require your base modules, not use them! So import subroutines of the base modules will be ignored.

A spot from documentation:

----------- package Baz; use base qw(Foo Bar);
Roughly similar in effect to
BEGIN { require Foo; require Bar; push @ISA, qw(Foo Bar); } ----------

An example:

---------- ### File A.pm package A; sub import { warn "A imported"; } ---------- ### File X.pm package X; use base qw(A); sub import { warn "X imported"; } ---------- ### File Y.pm package Y; use A; use base qw(A); sub import { warn "Y imported"; } ----------- ### File Z.pm package Z; use A; @ISA = qw(A); sub import { warn "Z imported"; } ----------

And now:

bash$ perl -e 'use X' import X at X.pm line 7. bash$ perl -e 'use Y' import A at A.pm line 5. import Y at Y.pm line 8. bash$ perl -e 'use Z' import A at A.pm line 5. import Z at Z.pm line 9.

You can see base module A is not imported in the first case.

-- brother ab

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-19 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found