goto magicalize;
case '!':
- GvMULTI_on(gv);
+ GvMULTI_on(gv);
/* If %! has been used, automatically load Errno.pm. */
sv_magic(GvSVn(gv), (SV*)gv, PERL_MAGIC_sv, name, len);
/* magicalization must be done before require_tie_mod is called */
- if (sv_type == SVt_PVHV)
+ if (sv_type == SVt_PVHV || sv_type == SVt_PVGV)
require_tie_mod(gv, "!", newSVpvs("Errno"), "TIEHASH", 1);
- /* NOTE: Errno.pm does the tieing of %! itself when it is executed.
- This is different to the way %+ and %- are handled. */
break;
case '-':
case '+':
GvMULTI_on(gv); /* no used once warnings here */
{
- bool plus = (*name == '+');
- SV *stashname = newSVpvs("Tie::Hash::NamedCapture");
AV* const av = GvAVn(gv);
- HV *const hv = GvHVn(gv);
- HV *const hv_tie = newHV();
- SV *tie = newRV_noinc((SV*)hv_tie);
+ SV* const avc = (*name == '+') ? (SV*)av : NULL;
- sv_bless(tie, gv_stashsv(stashname, GV_ADD));
- hv_magic(hv, (GV*)tie, PERL_MAGIC_tied);
- sv_magic((SV*)av, (plus ? (SV*)av : NULL), PERL_MAGIC_regdata, NULL, 0);
+ sv_magic((SV*)av, avc, PERL_MAGIC_regdata, NULL, 0);
sv_magic(GvSVn(gv), (SV*)gv, PERL_MAGIC_sv, name, len);
-
- /* NOTE: Tie::Hash::NamedCapture does NOT do the tie of %- or %+ itself.
- This is different to the way %! is handled. */
- if (plus)
+ if (avc)
SvREADONLY_on(GvSVn(gv));
- else
- Perl_hv_store(aTHX_ hv_tie, STR_WITH_LEN("all"), newSViv(1), 0);
-
- SvREADONLY_on(hv);
- SvREADONLY_on(tie);
SvREADONLY_on(av);
-
- require_tie_mod(gv, name, stashname, "FETCH", 0);
-
+
+ if (sv_type == SVt_PVHV || sv_type == SVt_PVGV)
+ require_tie_mod(gv, name, newSVpvs("Tie::Hash::NamedCapture"), "FETCH", 0);
+
break;
}
case '*':
use strict;
use warnings;
-our $VERSION = "0.03";
+our $VERSION = "0.04";
sub TIEHASH {
my $classname = shift;
- my $hash = {@_};
+ my %opts = @_;
- if ($hash->{re} && !re::is_regexp($hash->{re})) {
- die "'re' parameter to ",__PACKAGE__,"->TIEHASH must be a qr//"
+ if ($opts{re} && !re::is_regexp($opts{re})) {
+ require Carp;
+ Carp::croak("'re' parameter to " . __PACKAGE__
+ . "->TIEHASH must be a qr//.");
}
- return bless $hash, $classname;
+ my $self = bless {
+ all => $opts{all},
+ re => $opts{re},
+ }, $classname;
+ return $self;
}
sub FETCH {
return scalar re::regnames($_[0]->{re},$_[0]->{all});
}
+tie %+, __PACKAGE__;
+tie %-, __PACKAGE__, all => 1;
+
1;
__END__
#!./perl
-#
-# Tests to make sure the regexp engine doesn't run into limits too soon.
-#
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
}
-print "1..1\n";
+# WARNING: Do not use anymodules as part of this test code.
+# We could get action at a distance that would invalidate the tests.
+
+print "1..2\n";
+
+# This tests whether glob assignment fails to load the tie.
*X = *-;
-print eval '*X{HASH}{X} || 1' ? "ok\n" :"not ok\n";
+'X'=~/(?<X>X)/;
+print eval '*X{HASH}{X} || 1' ? "" :"not ","ok ",++$test,"\n";
+
+# And since its a similar case we check %! as well
+*Y = *!;
+print 0<keys(%Y) ? "" :"not ","ok ",++$test,"\n";