1 package Tie::Hash::NamedCapture;
12 my $self = bless { all => $opts{all} }, $classname;
17 return re::regname($_[1],$_[0]->{all});
22 Carp::croak("STORE forbidden: hashes tied to ",__PACKAGE__," are read-only.");
26 re::regnames_iterinit();
27 return $_[0]->NEXTKEY;
31 return re::regnames_iternext($_[0]->{all});
35 return defined re::regname( $_[1], $_[0]->{all});
40 Carp::croak("DELETE forbidden: hashes tied to ",__PACKAGE__," are read-only");
45 Carp::croak("CLEAR forbidden: hashes tied to ",__PACKAGE__," are read-only");
49 return scalar re::regnames($_[0]->{all});
53 tie %-, __PACKAGE__, all => 1;
61 Tie::Hash::NamedCapture - Named regexp capture buffers
65 tie my %hash, "Tie::Hash::NamedCapture";
66 # %hash now behaves like %+
68 tie my %hash, "Tie::Hash::NamedCapture", all => 1;
69 # %hash now access buffers from regexp in $qr like %-
73 This module is used to implement the special hashes C<%+> and C<%->, but it
74 can be used to tie other variables as you choose.
76 When the C<all> parameter is provided, then the tied hash elements will be
77 array refs listing the contents of each capture buffer whose name is the
78 same as the associated hash key. If none of these buffers were involved in
79 the match, the contents of that array ref will be as many C<undef> values
80 as there are capture buffers with that name. In other words, the tied hash
83 When the C<all> parameter is omitted or false, then the tied hash elements
84 will be the contents of the leftmost defined buffer with the name of the
85 associated hash key. In other words, the tied hash will behave as
88 The keys of C<%->-like hashes correspond to all buffer names found in the
89 regular expression; the keys of C<%+>-like hashes list only the names of
90 buffers that have captured (and that are thus associated to defined values).
94 L<re>, L<perlmodlib/Pragmatic Modules>, L<perlvar/"%+">, L<perlvar/"%-">.