@@ -6,17 +6,7 @@ function Use-Module
6
6
. SYNOPSIS
7
7
Uses a module.
8
8
. DESCRIPTION
9
- Uses a module.
10
-
11
- This can either:
12
-
13
- * If present, run a module's `Use` function, method, or script property.
14
- * Otherwise, run a script block in the module's context.
15
-
16
- * Run a module's `Use` function, if present
17
- * Call a module's `Use` method, if present
18
-
19
- In all cases, the script block should be run in the module's context, using dot-sourcing.
9
+ Uses a module's context to run a `[ScriptBlock]` (with dot-sourcing).
20
10
. EXAMPLE
21
11
Get-Module PipeScript | Use-Module -ScriptBlock { $myInvocation.MyCommand.ScriptBlock.Module }
22
12
#>
@@ -61,43 +51,12 @@ function Use-Module
61
51
Get-Module $Name | Select-Object - First 1
62
52
}
63
53
64
- # Return if there is no module context.
65
- return if -not $moduleContext
66
54
67
- # Get the use commands.
68
- $useCommands = $moduleContent.ExportedCommands [@ (
69
- " Use-$ ( $moduleContext.Name ) " ,
70
- " Use.$ ( $moduleContext.Name ) "
71
- " $ ( $moduleContext.Name ) .Use"
72
- )]
73
-
74
- # Get the use method.
75
- $useMethod = $moduleContext.psobject.methods [" Use" ]
76
-
77
- $ToRun =
78
- # If we have a method
79
- if ($useMethod )
80
- {
81
- $useMethod.Script # use it
82
- # (and pass the script block as an argument)
83
- $ArgumentList = @ ($ScriptBlock ) + @ ($ArgumentList )
84
- }
85
- # If we have any use commands, use the first one
86
- elseif ($useCommands -ne $null )
87
- {
88
- @ ($useCommands -ne $null )[0 ]
89
- # (and pass the script block as an argument)
90
- $ArgumentList = @ ($ScriptBlock ) + @ ($ArgumentList )
91
- }
92
- else
93
- {
94
- # Otherwise, use the script block
95
- $ScriptBlock
96
- }
97
-
98
- # We're running in the module context, and now we know what we want `$toRun`.
55
+ # We're running in the module context,
99
56
$runningIn = $moduleContext
100
-
57
+ # and we want `$toRun` the ScriptBlock.
58
+ $ToRun = $ScriptBlock
59
+
101
60
# The rest of the code is tedium.
102
61
# If there were arguments and parameters, pass them both with splatting.
103
62
if ($ArgumentList ) {
0 commit comments