Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Encapsulate function and variables

by gaal (Parson)
on Jun 19, 2007 at 11:46 UTC ( #621996=note: print w/replies, xml ) Need Help??


in reply to Encapsulate function and variables

For most practical purposes, you can treat a namespace exactly as if it were a hash.

sub capsule { my($capsule_name, $file) = @_; my $src = slurp $file; eval "package $capsule_name; \n#line 1\n$src" or die $@; } [...] capusle("Foo", "foo.pl"); print $Foo::{text};

An alternative is to load everything into a dummy package with a throwaway name, then to export everything out of it. Of course, both these proposals break if foo.pl switches namespaces itself, and that's hard to catch.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://621996]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-02-27 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (376 votes). Check out past polls.