links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
A simple Module example
Last updated at 8:07 pm UTC on 31 October 2006
Here is a little experiment you can do to become familiar with Module.

Let us assume you want to define two modules called : #(Project Test) and #(Project Test2), where the class Test is defined in the first, and Test2 in the latter.

You have for instance
    Test2 foo


Test2 class>>foo
    Transcript show: 'Hello, I am ', self class asString, ' !';cr

With the browser you define these two modules and two classes without regard to dependancies. In this case, there clearly is some between these both modules ( #(Project Test) depends on #(Project Test2)).

Showing dependencies

Take care this shows all dependencies, even references from classes that are in the prerequisite chain

Where content of #(Project Test2) module is used elsewhere
aModule := Module @ #(Project Test2).
aModule deepIncomingRefsFromOutside: aModule
These show you where class Test2 is used.

Also the module #(Project Test) (by having a reference of Test2 in the class Test) refers implicitly to the module #(Project Test2).
(Module @ #(Project Test)) viewDeepUnresolvedRefs

There are two dependancies missing, the first is, as we have just said, the relationship between Test & Test2 modules. The latter is the relationship with #(Squeak Language Core Objects) . Why? Because class Test is a subclass to Object, so Object module has to be declared.

Resolving missing dependancies

There are two ways for doing that: automatically or manually.

For doing it automatically, just perform :
(Module @ #(Project Test)) deepDeclareExternalRefs
In this case, the system "guesses" a dependancy between #(Project Test) and the other module needed. But this could not work properly if there are two classes Test2 defined in the system. In that case, you have to do it manually.

For doing it manually, perform :
(Module @ #(Project Test)) externalModule: (Object module) alias: nil version: nil importNames: true.
(Module @ #(Project Test)) externalModule: (Test2 module) alias: nil version: nil importNames: true

More information about this message is on : How to declare module dependencies

How to save modules ?

Now we have defined our great modules, with correct dependancies, we can savely store them on a disk or on a remote server. For that, the module installer is welcomed!

You can store a module either on the local disk, or on the local disk and on a remote server. For that, go to the preferences for managing that.

ModuleInstaller upload: (Module @ #(Project Test))

On the local disk a folder "RepositoryCache" is created and folders "Project/" and "Project/Test" will be included. The RepositoryCache is at the same place as your squeak binary, this is to be able to work with several images and still having one repository. For the unix user, the repository is stored on the lib/squeak/3.xxxx/ directory.

How to unload a module from the image ?

Perform :
ModuleInstaller unload: (Module @ #(Project Test))

How to load a module ?

Thanks to the module installer :
ModuleInstaller fullyInstallFromPath: #(Project Test)