summaryrefslogtreecommitdiff
path: root/overload.pl
diff options
context:
space:
mode:
authorYuval Kogman <nothingmuch@woobling.org>2008-08-09 16:01:15 +0300
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-01-02 09:52:55 +0100
commite46c382ee1a26c0abddc80ad1249dc544d229d4e (patch)
treed890a3e8023dbe3fbb3b35fe4f6b85efe8002a3f /overload.pl
parent50eca76146e11e9c375c0a5c02f5f2102f0911bc (diff)
downloadperl-e46c382ee1a26c0abddc80ad1249dc544d229d4e.tar.gz
'overloading' pragma
Diffstat (limited to 'overload.pl')
-rw-r--r--overload.pl44
1 files changed, 43 insertions, 1 deletions
diff --git a/overload.pl b/overload.pl
index 69808c6221..01dd550e4e 100644
--- a/overload.pl
+++ b/overload.pl
@@ -12,6 +12,8 @@ BEGIN {
use strict;
+use File::Spec::Functions qw(catdir catfile);;
+
my (@enums, @names);
while (<DATA>) {
next if /^#/;
@@ -21,9 +23,48 @@ while (<DATA>) {
push @names, $name;
}
-safer_unlink ('overload.h', 'overload.c');
+safer_unlink ('overload.h', 'overload.c', catfile(qw(lib overload numbers.pm)));
my $c = safer_open("overload.c");
my $h = safer_open("overload.h");
+mkdir("lib/overload") unless -d catdir(qw(lib overload));
+my $p = safer_open(catfile(qw(lib overload numbers.pm)));
+
+
+select $p;
+
+{
+local $" = "\n ";
+print <<"EOF";
+# -*- buffer-read-only: t -*-
+#
+# lib/overload/numbers.pm
+#
+# Copyright (C) 2008 by Larry Wall and others
+#
+# You may distribute under the terms of either the GNU General Public
+# License or the Artistic License, as specified in the README file.
+#
+# !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
+# This file is built by overload.pl
+#
+
+package overload::numbers;
+
+our \@names = qw#
+ @names
+#;
+
+our \@enums = qw#
+ @enums
+#;
+
+{ my \$i; our %names = map { \$_ => ++\$i } \@names }
+
+{ my \$i; our %enums = map { \$_ => ++\$i } \@enums }
+
+EOF
+}
+
sub print_header {
my $file = shift;
@@ -99,6 +140,7 @@ EOT
safer_close($h);
safer_close($c);
+safer_close($p);
__DATA__
# Fallback should be the first