Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: How to declare globally visible subroutine like built-in ones ? Is it possible?

by bdimych (Monk)
on Nov 06, 2007 at 12:14 UTC ( #649195=note: print w/replies, xml ) Need Help??


in reply to Re: How to declare globally visible subroutine like built-in ones ? Is it possible?
in thread How to declare globally visible subroutine like built-in ones ? Is it possible?

>Are you sure you don't wan't use y; or require y; in z.pm??

Yes, I've given simplified example. Actually y.pm is a runtime library with many submodules:

script.pl - "use y";
y.pm - load many submodules with "subnamespaces", and export many subs to the script.pl
z.pm - one of submodules

Perl is Perl, it allows almost all, I suppose it is possible to make my problem in some way...

  • Comment on Re^2: How to declare globally visible subroutine like built-in ones ? Is it possible?

Replies are listed 'Best First'.
Re^3: How to declare globally visible subroutine like built-in ones ? Is it possible?
by Anonymous Monk on Nov 06, 2007 at 13:00 UTC

    If you're looking to avoid the overhead of loading all the submodules in y.pm but still having access to the code of y.pm proper, you could consider refactoring so that the big load/export is visible as y, but the actual code of y.pm occurs in y/actual.pm

    Then in y.pm

    require y::actual; push @ISA, 'y::actual';

    This would leave y.pm with the same public interface, but give you the option of a leaner y::actual or y::tiny or y::whatever available. This will only work of course, if the code in y.pm doesn't itself depend on those submodules.

    You could also look at autoloading and/or custom import subroutines

    If you're just woried about namespace polution, s/use/require/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2023-09-26 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?