develooper Front page | perl.perl5.porters | Postings from March 2023

Re: Questions about the my Foo $var syntax

Thread Previous
March 13, 2023 11:50
Re: Questions about the my Foo $var syntax
Message ID:
On Mon, 13 Mar 2023 at 12:29, Robert Rothenberg <> wrote:

> There's some legacy syntax still used in some very old code bases, e.g.
> TheSchwartz
>    my TheSchwartz::Job $job = shift;
> As far as I can tell, this doesn't do anything except require that
> TheSchwartz::Job namespace exists. It doesn't require $job to be a
> TheSchwartz::Job.
> I have some questions:
> 1. Is this documented anywhere still?
> 2. Is the syntax deprecated?
> 3. if not, are there plans to do something useful with it, e.g. enforce
> type constraints?

It is covered in perldoc -f 'my' (aka perlfunc.pod) under "my TYPE VARLIST"
and in "Private Variables via my()" in perlsub.  From the former:

            The exact semantics and interface of TYPE and ATTRS are still
            evolving. TYPE may be a bareword, a constant declared with "use
            constant", or "__PACKAGE__". It is currently bound to the use of
            the fields pragma, and attributes are handled using the
            attributes pragma, or starting from Perl 5.8.0 also via the
            Attribute::Handlers module. See "Private Variables via my()" in
            perlsub for details.

perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About