Alt-Lexical-Var-ButSupportModernPerl
view release on metacpan or search on metacpan
t/code_3.pm
t/code_4.pm
t/code_bare.t
t/code_bare_no.t
t/code_const.t
t/code_ident.t
t/code_ops.t
t/code_scope.t
t/code_type.t
t/error.t
t/glob_ident.t
t/glob_scope.t
t/glob_type.t
t/glob_write.t
t/hash_ident.t
t/hash_ops.t
t/hash_scope.t
t/hash_type.t
t/hash_write.t
t/once.t
t/pod_cvg.t
t/pod_syn.t
t/scalar_0.pm
t/scalar_0n.pm
void context, we would have to change it to *av_store. */
# define padnamelist_store av_store
#endif
/*
* scalar classification
*
* Logic borrowed from Params::Classify.
*/
#define sv_is_glob(sv) (SvTYPE(sv) == SVt_PVGV)
#if PERL_VERSION_GE(5,11,0)
# define sv_is_regexp(sv) (SvTYPE(sv) == SVt_REGEXP)
#else /* <5.11.0 */
# define sv_is_regexp(sv) 0
#endif /* <5.11.0 */
#define sv_is_string(sv) \
(!sv_is_glob(sv) && !sv_is_regexp(sv) && \
(SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK)))
/*
* gen_const_identity_op()
*
* This function generate op that evaluates to a fixed object identity
* and can also participate in constant folding.
*
* Lexical::Var generally needs to make ops that evaluate to fixed
* identities, that being what a name that it handles represents.
croak("%s name is not a string", vari_word);
key = name_key(base_sigil, name);
if(!key) croak("malformed %s name", vari_word);
sigil = SvPVX(key)[KEYPREFIXLEN];
rt = SvROK(ref) ? SvTYPE(SvRV(ref)) : SVt_LAST;
switch(sigil) {
case '$': rok = svt_scalar(rt); vt="scalar"; break;
case '@': rok = rt == SVt_PVAV; vt="array"; break;
case '%': rok = rt == SVt_PVHV; vt="hash"; break;
case '&': rok = rt == SVt_PVCV; vt="code"; break;
case '*': rok = rt == SVt_PVGV; vt="glob"; break;
default: rok = 0; vt = "wibble"; break;
}
if(!rok) croak("%s is not %s reference", vari_word, vt);
val = newRV_inc(SvRV(ref));
he = hv_store_ent(GvHV(PL_hintgv), key, val, 0);
if(he) {
val = HeVAL(he);
SvSETMAGIC(val);
} else {
SvREFCNT_dec(val);
lib/Lexical/Var.pm view on Meta::CPAN
declaration, this would refer to the scalar variable of that name
located in the current package. A C<Lexical::Var> declaration can
change this to refer to any particular scalar, bypassing the package
system entirely. A variable name that includes an explicit package part,
such as "C<$main::foo>", always refers to the variable in the specified
package, and is unaffected by this module. A symbolic reference through
a string value, such as "C<${'foo'}>", also looks in the package system,
and so is unaffected by this module.
The types of name that can be influenced are scalar ("C<$foo>"),
array ("C<@foo>"), hash ("C<%foo>"), subroutine ("C<&foo>"), and glob
("C<*foo>"). A definition for any of these names also affects code
that logically refers to the same entity, even when the name is spelled
without its usual sigil. For example, any definition of "C<@foo>" affects
element references such as "C<$foo[0]>". Barewords in filehandle context
actually refer to the glob variable. Bareword references to subroutines,
such as "C<foo(123)>", only work on Perl 5.11.2 and later; on earlier
Perls you must use the C<&> sigil, as in "C<&foo(123)>".
Where a scalar name is defined to refer to a constant (read-only) scalar,
references to the constant through the lexical namespace can participate
in compile-time constant folding. This can avoid the need to check
configuration values (such as whether debugging is enabled) at runtime.
A name definition supplied by this module takes effect from the end of the
definition statement up to the end of the immediately enclosing block,
lib/Lexical/Var.pm view on Meta::CPAN
namespace, just as it can affect those in package namespaces or elsewhere.
C<Lexical::Var> avoids contributing to the problem itself, but certain
ways of building the parameters to C<Lexical::Var> can result in the
object in the lexical namespace not being the one that was intended,
or can damage the named object so that later referencing operations on
it misbehave. L<Scalar::Construct> can be used to avoid this problem.
Bogus redefinition warnings occur in some cases when C<our> declarations
and C<Lexical::Var> declarations shadow each other.
Package hash entries get created for subroutine and glob names that
are used, even though the subroutines and globs are not actually being
stored or looked up in the package. This can occasionally result in a
"used only once" warning failing to occur when it should.
On Perls prior to 5.15.5,
if this package's C<import> or C<unimport> method is called from inside
a string C<eval> inside a C<BEGIN> block, it does not have proper
access to the compiling environment, and will complain that it is being
invoked outside compilation. Calling from the body of a C<require>d
or C<do>ed file causes the same problem
on the same Perl versions. Other kinds of indirection
use Lexical::Var '@array' => [];
is_deeply \@array, [];
use Lexical::Var '%hash' => {};
is_deeply \%hash, {};
use Lexical::Var '&code' => sub { 1 };
is_deeply &code, 1;
use Lexical::Var '*glob' => \*x;
is_deeply *glob, *x;
use Lexical::Sub sub => sub { 1 };
is_deeply &sub, 1;
1;
( run in 0.627 second using v1.01-cache-2.11-cpan-49f99fa48dc )