Protected Package

Protected package is a package which can explicitly expose (hide) variables and functions to (from) other packages.

import("pnuts.ext.*")
package(ProtectedPackage( pkg_name ))

In a ProtectedPackage only exported names are visible from other packages. The export() function is defined automatically.

e.g.
import("pnuts.ext.*")
package(ProtectedPackage("foo"))
x = 100
y = 200
export("x")

package("")
foo::x   ==> 100
foo::y   ==> not found
protectPackage(boolean)

When protectPackage(true) is called pnuts.ext.ProtectedPackage becomes the default class for package objects. This setting is effective only for newly created packages, but not for packages which have been created before protectPackage(true) was called.

protectPackage(true)

package("foo")
x = 100
y = 200
export("x")

package("")
foo::x ==> 100
foo::y ==> not found

If the property 'pnuts.package.factory' is specified at start up time, the class becomes the default package factory. For example, if the property's value is "pnuts.ext.ProtectedPackage$Factory", the default package class will be pnuts.ext.ProtectedPackage.

java -Dpnuts.package.factory=pnuts.ext.ProtectedPackage$Factory pnuts.lang.Pnuts

Back