sv_setpv(sv, name);
if (PL_in_my_stash) {
if (*name != '$')
- yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"my\"",
- name));
+ yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"%s\"",
+ name, PL_in_my == KEY_our ? "our" : "my"));
SvOBJECT_on(sv);
(void)SvUPGRADE(sv, SVt_PVMG);
SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash);
type != OP_PADHV &&
type != OP_PUSHMARK)
{
- yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type]));
+ yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
+ PL_op_desc[o->op_type],
+ PL_in_my == KEY_our ? "our" : "my"));
return o;
}
else if (attrs && type != OP_PUSHMARK) {
SV *padsv;
SV **namesvp;
+ PL_in_my = FALSE;
+ PL_in_my_stash = Nullhv;
+
/* check for C<my Dog $spot> when deciding package */
namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE);
if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp)))
{
if (o->op_flags & OPf_PARENS)
list(o);
- PL_in_my = FALSE;
- PL_in_my_stash = Nullhv;
if (attrs)
SAVEFREEOP(attrs);
- return my_kid(o, attrs);
+ o = my_kid(o, attrs);
+ PL_in_my = FALSE;
+ PL_in_my_stash = Nullhv;
+ return o;
}
OP *
char *s;
for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ;
if (*s == ';' || *s == '=')
- Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list",
- lex ? "my" : "local");
+ Perl_warner(aTHX_ WARN_PARENTHESIS,
+ "Parentheses missing around \"%s\" list",
+ lex ? (PL_in_my == KEY_our ? "our" : "my") : "local");
}
}
- PL_in_my = FALSE;
- PL_in_my_stash = Nullhv;
if (lex)
- return my(o);
+ o = my(o);
else
- return mod(o, OP_NULL); /* a bit kludgey */
+ o = mod(o, OP_NULL); /* a bit kludgey */
+ PL_in_my = FALSE;
+ PL_in_my_stash = Nullhv;
+ return o;
}
OP *
to try to declare one with a package qualifier on the front. Use local()
if you want to localize a package variable.
-=item "my" variable %s masks earlier declaration in same %s
+=item "%s" variable %s masks earlier declaration in same %s
-(W) A lexical variable has been redeclared in the current scope or statement,
+(W) A "my" or "our" variable has been redeclared in the current scope or statement,
effectively eliminating all access to the previous instance. This is almost
always a typographical error. Note that the earlier variable will still exist
until the end of the scope or until all closure referents to it are
(P) An error peculiar to VMS. The process is suffering from exhausted quotas
or other plumbing problems.
-=item Can't declare %s in my
+=item Can't declare class for non-scalar %s in "%s"
-(F) Only scalar, array, and hash variables may be declared as lexical variables.
-They must have ordinary identifiers as names.
+(S) Currently, only scalar variables can declared with a specific class
+qualifier in a "my" or "our" declaration. The semantics may be extended
+for other types of variables in future.
+
+=item Can't declare %s in "%s"
+
+(F) Only scalar, array, and hash variables may be declared as "my" or
+"our" variables. They must have ordinary identifiers as names.
=item Can't do inplace edit on %s: %s
=item Global symbol "%s" requires explicit package name
(F) You've said "use strict vars", which indicates that all variables
-must either be lexically scoped (using "my"), or explicitly qualified to
-say which package the global variable is in (using "::").
+must either be lexically scoped (using "my"), declared beforehand using
+"our", or explicitly qualified to say which package the global variable
+is in (using "::").
=item goto must have label
my ($foo, $bar) = @_;
-Remember that "my" and "local" bind closer than comma.
+Remember that "my", "our" and "local" bind closer than comma.
=item Perl %3.3f required--this is only version %s, stopped