This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
db86908a49ba3e9978f4a325d377d1cca53f05d2
[perl5.git] / ext / Tie-Hash-NamedCapture / NamedCapture.pm
1 use strict;
2 package Tie::Hash::NamedCapture;
3
4 our $VERSION = "0.08";
5
6 sub TIEHASH;
7
8 require XSLoader;
9 XSLoader::load();
10
11 tie %+, __PACKAGE__;
12 tie %-, __PACKAGE__, all => 1;
13
14 1;
15
16 __END__
17
18 =head1 NAME
19
20 Tie::Hash::NamedCapture - Named regexp capture buffers
21
22 =head1 SYNOPSIS
23
24     tie my %hash, "Tie::Hash::NamedCapture";
25     # %hash now behaves like %+
26
27     tie my %hash, "Tie::Hash::NamedCapture", all => 1;
28     # %hash now access buffers from regexp in $qr like %-
29
30 =head1 DESCRIPTION
31
32 This module is used to implement the special hashes C<%+> and C<%->, but it
33 can be used to tie other variables as you choose.
34
35 When the C<all> parameter is provided, then the tied hash elements will be
36 array refs listing the contents of each capture buffer whose name is the
37 same as the associated hash key. If none of these buffers were involved in
38 the match, the contents of that array ref will be as many C<undef> values
39 as there are capture buffers with that name. In other words, the tied hash
40 will behave as C<%->.
41
42 When the C<all> parameter is omitted or false, then the tied hash elements
43 will be the contents of the leftmost defined buffer with the name of the
44 associated hash key. In other words, the tied hash will behave as
45 C<%+>.
46
47 The keys of C<%->-like hashes correspond to all buffer names found in the
48 regular expression; the keys of C<%+>-like hashes list only the names of
49 buffers that have captured (and that are thus associated to defined values).
50
51 =head1 SEE ALSO
52
53 L<perlreapi>, L<re>, L<perlmodlib/Pragmatic Modules>, L<perlvar/"%+">,
54 L<perlvar/"%-">.
55
56 =cut