Commit | Line | Data |
---|---|---|
c8472d06 T |
1 | =head1 NAME |
2 | ||
1694bc13 | 3 | CORE - 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 | 17 | The C<CORE> namespace gives access to the original built-in functions of |
4a904372 FC |
18 | Perl. It also provides access to keywords normally available |
19 | only through the L<feature> pragma. There is no C<CORE> | |
20 | package, and therefore you do not need to use or | |
1694bc13 RGS |
21 | require an hypothetical "CORE" module prior to accessing routines in this |
22 | namespace. | |
c8472d06 | 23 | |
1694bc13 | 24 | A 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 |
28 | To override a Perl built-in routine with your own version, you need to |
29 | import it at compile-time. This can be conveniently achieved with the | |
30 | C<subs> pragma. This will affect only the package in which you've imported | |
31 | the said subroutine: | |
c8472d06 | 32 | |
1694bc13 RGS |
33 | use subs 'chdir'; |
34 | sub chdir { ... } | |
35 | chdir $somewhere; | |
c8472d06 | 36 | |
1694bc13 RGS |
37 | To override a built-in globally (that is, in all namespaces), you need to |
38 | import your function into the C<CORE::GLOBAL> pseudo-namespace at compile | |
39 | time: | |
40 | ||
41 | BEGIN { | |
42 | *CORE::GLOBAL::hex = sub { | |
43 | # ... your code here | |
44 | }; | |
45 | } | |
46 | ||
47 | The new routine will be called whenever a built-in function is called | |
c8472d06 T |
48 | without a qualifying package: |
49 | ||
1694bc13 | 50 | print hex("0x50"),"\n"; # prints 1 |
c8472d06 | 51 | |
1694bc13 RGS |
52 | In both cases, if you want access to the original, unaltered routine, use |
53 | the C<CORE::> prefix: | |
c8472d06 | 54 | |
1694bc13 | 55 | print CORE::hex("0x50"),"\n"; # prints 80 |
c8472d06 T |
56 | |
57 | =head1 AUTHOR | |
58 | ||
1694bc13 | 59 | This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007. |
c8472d06 T |
60 | |
61 | =head1 SEE ALSO | |
62 | ||
1694bc13 | 63 | L<perlsub>, L<perlfunc>. |
c8472d06 T |
64 | |
65 | =cut |