diff options
author | Ævar Arnfjörð Bjarmason <avar@cpan.org> | 2007-06-03 20:24:59 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-06-06 14:42:01 +0000 |
commit | 192b9cd13b3ba000f1d0a2d32c141b9513be7936 (patch) | |
tree | 26f0762a3e487484176e678091b6f25c2dafa33a /lib/Tie | |
parent | efd46721a0c1bd9cb5bfa6492d03a4890f3d86e8 (diff) | |
download | perl-192b9cd13b3ba000f1d0a2d32c141b9513be7936.tar.gz |
Re: [PATCH] Callbacks for named captures (%+ and %-)
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Message-ID: <51dd1af80706031324y5618d519p460da27a2e7fe712@mail.gmail.com>
p4raw-id: //depot/perl@31341
Diffstat (limited to 'lib/Tie')
-rw-r--r-- | lib/Tie/Hash/NamedCapture.pm | 56 |
1 files changed, 11 insertions, 45 deletions
diff --git a/lib/Tie/Hash/NamedCapture.pm b/lib/Tie/Hash/NamedCapture.pm index 73bc20bd87..58ae743d87 100644 --- a/lib/Tie/Hash/NamedCapture.pm +++ b/lib/Tie/Hash/NamedCapture.pm @@ -1,52 +1,17 @@ package Tie::Hash::NamedCapture; -use strict; -use warnings; +our $VERSION = "0.06"; -our $VERSION = "0.05"; +# The real meat implemented in XS in universal.c in the core, but this +# method was left behind because gv.c expects a Purl-Perl method in +# this package when it loads the tie magic for %+ and %- -sub TIEHASH { - my $classname = shift; - my %opts = @_; - - my $self = bless { all => $opts{all} }, $classname; - return $self; -} - -sub FETCH { - return re::regname($_[1],$_[0]->{all}); -} - -sub STORE { - require Carp; - Carp::croak("STORE forbidden: hashes tied to ",__PACKAGE__," are read-only."); -} - -sub FIRSTKEY { - re::regnames_iterinit(); - return $_[0]->NEXTKEY; -} +my ($one, $all) = Tie::Hash::NamedCapture::flags(); -sub NEXTKEY { - return re::regnames_iternext($_[0]->{all}); -} - -sub EXISTS { - return defined re::regname( $_[1], $_[0]->{all}); -} - -sub DELETE { - require Carp; - Carp::croak("DELETE forbidden: hashes tied to ",__PACKAGE__," are read-only"); -} - -sub CLEAR { - require Carp; - Carp::croak("CLEAR forbidden: hashes tied to ",__PACKAGE__," are read-only"); -} - -sub SCALAR { - return scalar re::regnames($_[0]->{all}); +sub TIEHASH { + my ($pkg, %arg) = @_; + my $flag = $arg{all} ? $all : $one; + bless \$flag => $pkg; } tie %+, __PACKAGE__; @@ -91,6 +56,7 @@ buffers that have captured (and that are thus associated to defined values). =head1 SEE ALSO -L<re>, L<perlmodlib/Pragmatic Modules>, L<perlvar/"%+">, L<perlvar/"%-">. +L<perlreapi>, L<re>, L<perlmodlib/Pragmatic Modules>, L<perlvar/"%+">, +L<perlvar/"%-">. =cut |