Revision 27324

Date:
2009/06/30 16:14:08
Author:
lwall
Revision Log:
[S11] attempt to break down use/require further for ELISHEVA++
Files:

Legend:

 
Added
 
Removed
 
Modified
  • docs/Perl6/Spec/S11-modules.pod

     
    12 12
    13 13 Created: 27 Oct 2004
    14 14
    15 Last Modified: 29 Jun 2009
    16 Version: 29
    15 Last Modified: 30 Jun 2009
    16 Version: 30
    17 17
    18 18 =head1 Overview
    19 19
     
    162 162 need Sense;
    163 163 Sense defines <common @horse>;
    164 164
    165 These further break down into:
    166
    167 BEGIN MY::($_) := load_module(find_module_defining($_)) for <Sense>;
    168 BEGIN MY.import_alias(Sense, <common @horse>);
    169
    165 170 =head2 Loading without importing
    166 171 X<need>
    167 172
     
    177 182
    178 183 use ACME::Rocket ();
    179 184
    185 Saying
    186
    187 need A,B,C;
    188
    189 is equivalent to:
    190
    191 BEGIN MY::($_) := load_module(find_module_defining($_)) for <A B C>;
    192
    180 193 =head2 Importing without loading
    181 194 X<defines>
    182 195
     
    190 203 ...
    191 204 Factorial defines 'fact'; # imports the multi
    192 205
    206 The last declaration is syntactic sugar for:
    207
    208 BEGIN MY.import_alias(Factorial, <fact>);
    209
    193 210 Despite having the form of an infix operator, this form functions as
    194 211 a compile-time declarator, so that these notations can be combined:
    195 212
     
    197 214 enum Ness is export <Dilly String Putty>;
    198 215 } defines <Ness>;
    199 216
    217 This really means:
    200 218
    219 BEGIN MY.import_alias(
    220 role Silly {
    221 enum Ness is export <Dilly String Putty>;
    222 },
    223 <Ness>
    224 );
    225
    201 226 =head1 Runtime Importation
    202 227
    203 228 Importing via C<require> also installs names into the current lexical scope by
    204 229 default, but delays the actual binding till runtime:
    205 230
    206 231 require Sense <common @horse>;
    232
    233 This means something like:
    234
    235 BEGIN MY.declare_stub_symbols('Sense', <common @horse>);
    236 # run time!
    237 MY.import_realias(:from(load_module(find_module_defining('Sense'))), 'Sense');
    238 MY.import_realias(:from(Sense), <common @horse>);
    239
    240 (The C<.import_realias> requires that the symbols to be imported already
    241 exist; this differs from C<.import_alias>, which requires that the
    242 imported symbols I<not> already exist in the target scope.)
    243
    244 Alternately, a filename may be mentioned directly, which installs
    245 a package that is effectively that is anonymous to the current lexical
    246 scope, and may only be accessed by whatever global names the module
    247 installs:
    248
    207 249 require "/home/non/Sense.pm" <common @horse>;
    208 250
    209 Only explicitly mentioned names may be so installed. In order
    251 which breaks down to:
    252
    253 BEGIN MY.declare_stub_symbols(<common @horse>);
    254 MY.import_realias(:from(load_module("/home/non/Sense.pm")), <common @horse>);
    255
    256 Only explicitly mentioned names may be so imported. In order
    210 257 to protect the run-time sanctity of the lexical pad, it may not be
    211 258 modified by C<require>. Tagsets are assumed to be unknown at compile
    212 259 time, hence tagsets are not allowed in the default import list to