@@ -13,17 +13,20 @@ Defined as:
13
13
14
14
= begin code :method
15
15
proto sub EVAL($code where Blob|Cool|Callable, Str() :$lang = 'Raku',
16
- PseudoStash :$context, *%n )
16
+ PseudoStash :$context, Str() :$filename, Bool() :$check, *%_ )
17
17
= end code
18
18
= begin code :method
19
19
multi sub EVAL($code, Str :$lang where { ($lang // '') eq 'Perl5' },
20
- PseudoStash :$context)
20
+ PseudoStash :$context, Str() :$filename, :$check )
21
21
= end code
22
22
23
- This routine coerces L < Cool|/type/Cool > C < $code > to L < Str|/type/Str > . If
23
+ This routine executes at runtime a fragment of code, C < $code > , of a given language,
24
+ C < $lang > , which defaults to C < Raku > .
25
+
26
+ It coerces L < Cool|/type/Cool > C < $code > to L < Str|/type/Str > . If
24
27
C < $code > is a L < Blob|/type/Blob > , it'll be processed using the same encoding as
25
28
the C < $lang > compiler would: for C < Raku > C < $lang > , uses C < utf-8 > ; for C < Perl5 > ,
26
- processes using the same rules as C < perl > .
29
+ processes using the same rules as Perl .
27
30
28
31
This works as-is with a literal string parameter. More complex input,
29
32
such as a variable or string with embedded code, is illegal by default.
@@ -93,19 +96,39 @@ EVAL "use v5.20; say 'Hello from perl!'", :lang<Perl5>;
93
96
You need to have L < C < Inline::Perl5 > |https://github.com/niner/Inline-Perl5> for
94
97
this to work correctly.
95
98
99
+ More languages may be supported with additional
100
+ modules which may be found from the
101
+ L < Raku Modules Directory|https://modules.raku.org/search/?q=inline > .
102
+
103
+ If the optional C < $filename > parameter is given, the
104
+ L « C < $?FILE > |/language/variables#index-entry-$%3FFILE» variable is set to
105
+ its value. Otherwise C < $?FILE > is set to a unique and generated file name.
106
+
107
+ = for code
108
+ use MONKEY-SEE-NO-EVAL;
109
+ EVAL 'say $?FILE'; # OUTPUT: «/tmp/EVAL_0»
110
+ EVAL 'say $?FILE', filename => '/my-eval-code'; # OUTPUT: «/my-eval-code»
111
+
112
+ If the optional C < $check > parameter is C < True > , C < $code >
113
+ is processed by the C < $lang > compiler but is not actually
114
+ run. For C < Raku > , L « C < BEGIN > |/language/phasers#BEGIN» , and
115
+ L « C < CHECK > |/language/phasers#CHECK» blocks are run. The C < EVAL > routine
116
+ then returns C < Nil > if compilation was successful, otherwise an exception
117
+ is thrown.
118
+
96
119
= head2 sub EVALFILE
97
120
98
121
Defined as:
99
122
100
- sub EVALFILE($filename where Blob|Cool, :$lang = 'Raku')
123
+ sub EVALFILE($filename where Blob|Cool, :$lang = 'Raku', :$check )
101
124
102
125
Slurps the specified file and evaluates it. Behaves the same way as
103
- C < EVAL > with regard to L < Blob|/type/Blob > decoding, scoping, and the C < $lang >
104
- parameter. Evaluates to the value produced by the final statement in the
105
- file.
126
+ C < EVAL > with regard to L < Blob|/type/Blob > decoding, scoping, the C < $lang >
127
+ parameter and the C < $check > parameter . Evaluates to the value produced
128
+ by the final statement in the file when C < $check > is not C < True > .
106
129
107
130
= for code
108
- EVALFILE "foo.p6 ";
131
+ EVALFILE "foo.raku ";
109
132
110
133
= head2 sub mkdir
111
134
0 commit comments