summaryrefslogtreecommitdiff
path: root/embed.h
diff options
context:
space:
mode:
authorDavid Golden <dagolden@cpan.org>2009-10-06 06:48:48 -0400
committerDavid Golden <dagolden@cpan.org>2009-10-06 12:41:09 -0400
commit6fa4d285bff5644bebb95aff09143322042282cc (patch)
tree3e353ca1e3a17967f6dd473bcb49a7269c880355 /embed.h
parentcc4c9faad0767bbb62e32c96638b5ce02dde234e (diff)
downloadperl-6fa4d285bff5644bebb95aff09143322042282cc.tar.gz
Add 'package NAME VERSION' syntax
This patch adds support for setting the $VERSION of a namespace when the namespace is declared with 'package'. It eliminates the need for 'our $VERSION = ...' and similar constructs. E.g. package Foo::Bar 1.23; # $Foo::Bar::VERSION == 1.23 There are several advantages to this: * VERSION is parsed in *exactly* the same way as 'use NAME VERSION' * $VERSION is set at compile time * Eliminates '$VERSION = ...' and 'eval $VERSION' clutter * As it requires VERSION to be a numeric literal or v-string literal, it can be statically parsed by toolchain modules without 'eval' the way MM->parse_version does for '$VERSION = ...' * Alpha versions with underscores do not need to be quoted; static parsing will preserve the underscore, but during compilation, Perl will remove underscores as it does for all numeric literals During development of this, there was discussion on #corehackers and elsewhere that this should also allow other metadata to be set such as "status" (stable/alpha) or "author/authority". On reflection, those metadata are not very well defined yet and likely should never be encoded into Perl core parsing so they can be freely changed in the future. (They could perhaps be achieved via a comment on the same line as 'package NAME VERSION'.) Version numbers, however, already have a very specific definition and use defined in the core through 'use NAME VERSION'. This patch merely provides appropriate symmetry for setting $VERSION with the exact same parsing and semantics as 'use'. It does not break old code with only 'package NAME', but code that uses 'package NAME VERSION' will need to be restricted to perl 5.11.X. This is analogous to the change to open() from two-args to three-args. Users requiring the latest Perl will benefit, and perhaps N years from now it will become standard practice when Perl 5.12 is targeted the way that 5.6 is today. The patch does not prevent 'package NAME VERSION' from being used multiple times for the same package with different version numbers, but nothing prevents $VERSION from being modified arbitrarily at runtime, either, so I see no urgen reason to add limitations or warnings so long as Perl uses a global $VERSION variable for package version numbers. I am posting this patch to the p5p list for discussion and review. If there seems to be general assent (or lack of dissent), I will go ahead and commit the patch to blead.
Diffstat (limited to 'embed.h')
-rw-r--r--embed.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/embed.h b/embed.h
index 5ac4f998da..c0e6953035 100644
--- a/embed.h
+++ b/embed.h
@@ -629,6 +629,7 @@
#endif
#endif
#ifdef PERL_CORE
+#define package_version Perl_package_version
#define pad_alloc Perl_pad_alloc
#define allocmy Perl_allocmy
#define pad_findmy Perl_pad_findmy
@@ -2974,6 +2975,7 @@
#endif
#endif
#ifdef PERL_CORE
+#define package_version(a) Perl_package_version(aTHX_ a)
#define pad_alloc(a,b) Perl_pad_alloc(aTHX_ a,b)
#define allocmy(a) Perl_allocmy(aTHX_ a)
#define pad_findmy(a) Perl_pad_findmy(aTHX_ a)