Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Is it possible to create a sub exclusive to a sub?

by bsdz (Friar)
on Sep 19, 2004 at 10:19 UTC ( [id://392153]=note: print w/replies, xml ) Need Help??


in reply to Is it possible to create a sub exclusive to a sub?

One could implement something using the caller builtin, i.e. :-
use strict; &foo; &badfoo; sub foo { &bar; } sub badfoo { &bar; } sub bar { if ((caller(1))[3] ne 'main::foo') { die((caller(0))[3], ": can not be called from ", (caller(1))[3], " due to restrictions"); } print "called sub ",(caller(0))[3], "\n"; }
Update: changed "print STDERR" to "die"

Replies are listed 'Best First'.
Re^2: Is it possible to create a sub exclusive to a sub?
by ihb (Deacon) on Sep 19, 2004 at 10:42 UTC

    I think you indeed missed the point a bit. The idea isn't to prohibit people from calling it (althought you do by using the other solutions too). The idea is mainly to not pollute the global namespace.

    ihb

    Read argumentation in its context!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found