CYG23-544-stat
[p5sagit/p5-mst-13.2.git] / lib / Tie / Hash / NamedCapture.pm
CommitLineData
80305961 1package Tie::Hash::NamedCapture;
3195cf34 2
192b9cd1 3our $VERSION = "0.06";
3195cf34 4
192b9cd1 5# The real meat implemented in XS in universal.c in the core, but this
6# method was left behind because gv.c expects a Purl-Perl method in
7# this package when it loads the tie magic for %+ and %-
44a2ac75 8
192b9cd1 9my ($one, $all) = Tie::Hash::NamedCapture::flags();
44a2ac75 10
192b9cd1 11sub TIEHASH {
12 my ($pkg, %arg) = @_;
13 my $flag = $arg{all} ? $all : $one;
14 bless \$flag => $pkg;
44a2ac75 15}
16
67261566 17tie %+, __PACKAGE__;
18tie %-, __PACKAGE__, all => 1;
19
44a2ac75 201;
21
22__END__
23
24=head1 NAME
25
80305961 26Tie::Hash::NamedCapture - Named regexp capture buffers
44a2ac75 27
28=head1 SYNOPSIS
29
80305961 30 tie my %hash, "Tie::Hash::NamedCapture";
3195cf34 31 # %hash now behaves like %+
44a2ac75 32
28d8d7f4 33 tie my %hash, "Tie::Hash::NamedCapture", all => 1;
3195cf34 34 # %hash now access buffers from regexp in $qr like %-
44a2ac75 35
36=head1 DESCRIPTION
37
3195cf34 38This module is used to implement the special hashes C<%+> and C<%->, but it
28d8d7f4 39can be used to tie other variables as you choose.
44a2ac75 40
3195cf34 41When the C<all> parameter is provided, then the tied hash elements will be
42array refs listing the contents of each capture buffer whose name is the
43same as the associated hash key. If none of these buffers were involved in
44the match, the contents of that array ref will be as many C<undef> values
45as there are capture buffers with that name. In other words, the tied hash
9f8c97d1 46will behave as C<%->.
44a2ac75 47
3195cf34 48When the C<all> parameter is omitted or false, then the tied hash elements
49will be the contents of the leftmost defined buffer with the name of the
9f8c97d1 50associated hash key. In other words, the tied hash will behave as
51C<%+>.
44a2ac75 52
3195cf34 53The keys of C<%->-like hashes correspond to all buffer names found in the
54regular expression; the keys of C<%+>-like hashes list only the names of
55buffers that have captured (and that are thus associated to defined values).
44a2ac75 56
44a2ac75 57=head1 SEE ALSO
58
192b9cd1 59L<perlreapi>, L<re>, L<perlmodlib/Pragmatic Modules>, L<perlvar/"%+">,
60L<perlvar/"%-">.
44a2ac75 61
62=cut