summaryrefslogtreecommitdiff
path: root/perly.y
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 /perly.y
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 'perly.y')
-rw-r--r--perly.y18
1 files changed, 12 insertions, 6 deletions
diff --git a/perly.y b/perly.y
index df5cf462f8..0616692470 100644
--- a/perly.y
+++ b/perly.y
@@ -633,16 +633,22 @@ subbody : block { $$ = $1; }
}
;
-package : PACKAGE WORD ';'
+package : PACKAGE WORD WORD ';'
{
+/* Since no one seem to understand or use the MAD stuff, but Larry implies
+ * it shouldn't be removed, it's just commented out, and someone who
+ * understands it can come along later and fix it up.
#ifdef MAD
- $$ = package($2);
- token_getmad($1,$$,'o');
- token_getmad($3,$$,';');
+ (yyval.opval) = package((ps[(2) - (3)].val.opval));
+ token_getmad((ps[(1) - (3)].val.i_tkval),(yyval.opval),'o');
+ token_getmad((ps[(3) - (3)].val.i_tkval),(yyval.opval),';');
#else
- package($2);
+*/
+ package($3);
+ if ($2) {
+ package_version($2);
+ }
$$ = (OP*)NULL;
-#endif
}
;