trait is dynamic
| 1 | class Variable |
| 1.1 | (Variable) trait is dynamic |
Documentation for trait is dynamic assembled from the following types:
class Variable
From Variable
(Variable) trait is dynamic
multi sub trait_mod:<is>(Variable, :)
Marks a variable as dynamic, that is, accessible from inner dynamic scopes without being in an inner lexical scope.
sub introspect() {
say $CALLER::x;
}
my $x is dynamic = 23;
introspect; # OUTPUT: «23»
{
# not dynamic
my $x;
introspect() # dies with an exception of type X::Caller::NotDynamic
}
The is dynamic trait is a rather cumbersome way of creating and accessing dynamic variables. A much easier way is to use the * twigil:
sub introspect() {
say $*x;
}
my $*x = 23;
introspect; # OUTPUT: «23»
{
# not dynamic
my $x;
introspect() # dies with an exception of type X::Dynamic::NotFound
}