What do module type codes describe
Usually, this is on the PowerShell module path; but if necessary you can explicitly describe where your module is installed. A binary module is a. NET Framework assembly. Cmdlet developers can use this type of module to share cmdlets, providers, and more.
Existing snap-ins can also be used as binary modules. Compared to a script module, a binary module allows you to create cmdlets that are faster or use features such as multithreading that are not as easy to code in Windows PowerShell scripts. As with script modules, you can include a manifest file to describe additional resources that your module uses, and to track metadata about your module.
Similarly, you probably should install your binary module in a folder somewhere along the PowerShell module path. A manifest module is a module that uses a manifest file to describe all of its components, but doesn't have any sort of core assembly or script. However, you can still use the other features of a module, such as the ability to load up dependent assemblies or automatically run certain pre-processing scripts.
You can also use a manifest module as a convenient way to package up resources that other modules will use, such as nested modules, assemblies, types, or formats. A dynamic module is a module that is not loaded from, or saved to, a file.
Instead, they are created dynamically by a script, using the New-Module cmdlet. This type of module enables a script to create a module on demand that does not need to be loaded or saved to persistent storage. By its nature, a dynamic module is intended to be short-lived, and therefore cannot be accessed by the Get-Module cmdlet. Similarly, they usually do not need module manifests, nor do they likely need permanent folders to store their related assemblies.
A module manifest is a. The keys and values in the hash table do the following things:. Manifests are not required for a module. This takes all of the dependencies from a module and makes it an exported field, you could import it like this:.
They also support replacing the exports object with a custom single object. Default exports are meant to act as a replacement for this behavior; however, the two are incompatible. This can be a class, interface, namespace, function, or enum. Depending on the module target specified during compilation, the compiler will generate appropriate code for Node. For more information on what the define , require and register calls in the generated code do, consult the documentation for each module loader.
This simple example shows how the names used during importing and exporting get translated into the module loading code. To compile, we must specify a module target on the command line. For Node. For example:. A module has the same lifetime as your program. Because its members are all Shared , they also have lifetimes equal to that of the program. Modules default to Friend access. You can adjust their access levels with the access modifiers.
For more information, see Access levels in Visual Basic. Previous versions of Visual Basic recognize two types of modules: class modules. The current version calls these classes and modules , respectively. Shared Members. You can control whether a member of a class is a shared or instance member.
Object Orientation. Classes are object-oriented, but modules are not. So only classes can be instantiated as objects. For more information, see Objects and Classes. All module members are implicitly Shared. You can view a module as a collection of its exports, which are also referred to as members of the module.
These are simply names that can but need not be assigned values. You can establish initial values for the exports by assigning values to them in the body of the module definition. The word export is a short form for exported local variable. In most cases, a module export is a local variable such as those declared with the local declaration.
The difference is that you can access the exported local variables of a module after it has been created. To access an export of a module, use the member selection operator Its general syntax is. Anything else signals an exception. You cannot access the local variables of an instantiated module by using this syntax.
The Hello example above has one export named say. In the following example, say is assigned a procedure. To call it, enter. The following expression raises an exception because the name noSuchModule is not assigned a module expression. In the following example, a module expression is assigned to the name m and the member selection expression m:-e evaluates to the value of the exported variable e of m.
Since m does not export a variable named noSuchExport , the following expression raises an exception. In addition to the :- syntax, square brackets can also be used to reference a module export.
The square bracket notation has different evaluation rules than member selection. When using the member selection operator :- , the export name must be known in advance.
When using [], the name of the export can be computed. In this example, an exported variables value can be selected from an arbitrary module. Important: Exports do not need to have assigned values. The following module exports an unassigned name. This illustrates the importance of distinguishing module exports from global variables. References to the exported name e in m evaluate to the name e. Note, however, that this is a local name e and not the global instance of the name.
The first e in the previous expression refers to the global e , while the expression m:-e evaluates to the e that is local to the module m. This distinction between a global and export of the same name is useful. For example, you can create a module with an export sin. Assigning a value to the export sin does not affect the protected global name sin. Determining the Export Names. You can determine the names of the exports of a module by using the exports procedure.
This procedure returns the global instances of the export names. You can also obtain the local instances of those names by using the option instance. You cannot have the same name declared as both a local variable and an exported local variable. The declared exports and locals actually form a partition of the names that are local to a module.
Testing for Membership in a Module. As described in previous chapters, the member command can be used to test whether a value is a member of a set or list. This command can also be used for membership tests in modules. The first argument is a global name whose membership is to be tested, and the second argument is the name of a module. The member command returns the value true if the module has an export whose name is the same as the first argument. The member command also has a three-argument form that can be used with lists to determine the first position at which an item occurs.
The name pos is now assigned the value 2 because b occurs at the second position of the list. When used with modules, the third argument is assigned the local instance of the name whose membership is being tested, provided that the return value is true.
If the return value from the member command is false , the name remains unassigned or maintains its previously assigned value. Module Options. Similar to procedures, a module definition can contain options. The options available for modules are different from those for procedures. Only the options trace and copyright are common to both procedures and modules. The following four options have a predefined meaning for modules: load , unload , package , and record.
The load and unload options cover functionality defined by the ModuleLoad and ModuleUnload special exports described in the next section. For more information, refer to the module,option help page. The package Option. A package is a collection of procedures and other data that can be treated as a whole. Packages typically gather several procedures that allow you to perform computations in a well-defined problem domain.
Packages can contain data other than procedures and can even contain other packages subpackages. The package option is used to designate a module as a Maple package.
The exports of a module created with the package option are automatically protected. For more information, see Writing Packages. The record Option. The record option is used to identify records, which are fixed-size collections of items. Records are created by using the Record constructor and are represented using modules. For more information, see Records. Special Exports. Certain specially named exports, when defined in a module, affect how modules behave in Maple. These special exports are described below.
In most cases, they can be declared as either exported local variables or local variables. The ModuleApply Procedure. When a procedure named ModuleApply is declared as an export or local of a module, the module name can be used as if it were a procedure name. Consider the Counter example described at the beginning of this chapter. Since it only has one method, the calling sequence can be shortened by using the ModuleApply function.
In this example, calls to Counter:-ModuleApply are not needed and the results are the same as those generated by the original Counter example.
The ModuleApply function can specify and accept any number of parameters. You can also use the ModuleApply function to create module factories , a standard object-oriented design pattern described later in this chapter. The ModuleIterator Procedure. The ModuleIterator procedure defines how a module functions when it is used as the in clause of a for loop. In the example below, the ModuleIterator procedure returns two procedures: hasNext and getNext. These procedures can have any names, and in fact, do not require names.
When the ModuleIterator procedure is called, an iterator is initialized for the instance, the details of which are kept hidden from the caller. The two returned procedures can then be used to iterate over the instance to perform a specific task.
For example, consider a class that implements a form of a set of which mySet is an instance.
0コメント