This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Doc update for changes in 5.15.0 + tweaks
[perl5.git] / lib / CORE.pod
CommitLineData
c8472d06
T
1=head1 NAME
2
1694bc13 3CORE - Pseudo-namespace for Perl's core routines
c8472d06
T
4
5=head1 SYNOPSIS
6
1694bc13
RGS
7 BEGIN {
8 *CORE::GLOBAL::hex = sub { 1; };
9 }
c8472d06 10
1694bc13
RGS
11 print hex("0x50"),"\n"; # prints 1
12 print CORE::hex("0x50"),"\n"; # prints 80
4a904372 13 CORE::say "yes"; # prints yes
c8472d06
T
14
15=head1 DESCRIPTION
16
1694bc13 17The C<CORE> namespace gives access to the original built-in functions of
4a904372
FC
18Perl. It also provides access to keywords normally available
19only through the L<feature> pragma. There is no C<CORE>
20package, and therefore you do not need to use or
1694bc13
RGS
21require an hypothetical "CORE" module prior to accessing routines in this
22namespace.
c8472d06 23
1694bc13 24A list of the built-in functions in Perl can be found in L<perlfunc>.
c8472d06
T
25
26=head1 OVERRIDING CORE FUNCTIONS
27
1694bc13
RGS
28To override a Perl built-in routine with your own version, you need to
29import it at compile-time. This can be conveniently achieved with the
30C<subs> pragma. This will affect only the package in which you've imported
31the said subroutine:
c8472d06 32
1694bc13
RGS
33 use subs 'chdir';
34 sub chdir { ... }
35 chdir $somewhere;
c8472d06 36
1694bc13
RGS
37To override a built-in globally (that is, in all namespaces), you need to
38import your function into the C<CORE::GLOBAL> pseudo-namespace at compile
39time:
40
41 BEGIN {
42 *CORE::GLOBAL::hex = sub {
43 # ... your code here
44 };
45 }
46
47The new routine will be called whenever a built-in function is called
c8472d06
T
48without a qualifying package:
49
1694bc13 50 print hex("0x50"),"\n"; # prints 1
c8472d06 51
1694bc13
RGS
52In both cases, if you want access to the original, unaltered routine, use
53the C<CORE::> prefix:
c8472d06 54
1694bc13 55 print CORE::hex("0x50"),"\n"; # prints 80
c8472d06
T
56
57=head1 AUTHOR
58
1694bc13 59This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007.
c8472d06
T
60
61=head1 SEE ALSO
62
1694bc13 63L<perlsub>, L<perlfunc>.
c8472d06
T
64
65=cut