develooper Front page | perl.perl5.porters | Postings from November 2014

our Type $thing

Thread Next
From:
Father Chrysostomos
Date:
November 25, 2014 17:20
Subject:
our Type $thing
Message ID:
20141125172032.17231.qmail@lists-nntp.develooper.com
Does anybody actually use type declarations with 'our' vars?  I know
the core doesn't (except B::Deparse), and they don't seem to work with
Lexical::Types.  And what the core does doesn't make too much sense.

'our' creates a lexical pad entry that causes $thing magically to
become $main::thing at compile time.  'our Type $thing' stores the
type in that pad entry, but by the time the code is compiled there
is no longer any link between the resulting $main::thing and the pad
entry it derived from.

Furthermore, while 'our Type $thing; our OtherType $thing' creates two
pad entries, each one references a different type stash.  So we have
*two* types recorded for the *same* variable.

Implementation details aside, are there any plans to do anything
with this syntax?  (I think I can already say the answer is no.)  Or,
rather, does it make any sense to have a type associated with an
'our' variable?

The reason I ask is that I want to use the same internal field in pad
names for the typestash and for the ourstash.  Most code will never
use both fields at once, so it should be possible to merge them and
save memory.

Perhaps the solution is to allow the our Type $thing syntax (as cur-
rently), but have it do nothing (as currently), or even less than
nothing (???), not even storing the type, since nothing except
B::Deparse uses it.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About