This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Continue what #4494 started; introduce uid and gid formats.
[perl5.git] / lib / caller.pm
CommitLineData
f3aa04c2
GS
1package caller;
2use vars qw($VERSION);
3$VERSION = "1.0";
4
5=head1 NAME
6
7caller - inherit pragmatic attributes from the context of the caller
8
9=head1 SYNOPSIS
10
11 use caller qw(encoding);
12
13=head1 DESCRIPTION
14
15This pragma allows a module to inherit some attributes from the
16context which loaded it.
17
18Inheriting attributes takes place at compile time; this means
19only attributes that are visible in the calling context at compile
20time will be propagated.
21
22Currently, the only supported attribute is C<encoding>.
23
24=over
25
26=item encoding
27
28Indicates that the character set encoding of the caller's context
29must be inherited. This can be used to inherit the C<use utf8>
30setting in the calling context.
31
32=back
33
34=cut
35
22b491d3 36my %bitmask = (
f3aa04c2
GS
37 # only HINT_UTF8 supported for now
38 encoding => 0x8
39);
40
41sub bits {
42 my $bits = 0;
43 for my $s (@_) { $bits |= $bitmask{$s} || 0; };
44 $bits;
45}
46
47sub import {
48 shift;
49 my @cxt = caller(3);
50 if (@cxt and $cxt[7]) { # was our parent require-d?
22b491d3 51 $^H |= bits(@_) & $cxt[8];
f3aa04c2
GS
52 }
53}
54
55sub unimport {
56 # noop currently
57}
58
591;