Introduce 5.16/5.17 support
[p5sagit/Devel-PeekPoke.git] / lib / Devel / PeekPoke / Constants.pm
CommitLineData
6be43b56 1package Devel::PeekPoke::Constants;
2
3use strict;
4use warnings;
5
6use Config;
7
8BEGIN {
9 my $ptr_size = $Config{ptrsize};
10 eval "sub PTR_SIZE () { $ptr_size }";
11
12 my $ptr_pack_type = do {
13 if ($ptr_size == 4) {
14 'L'
15 }
16 elsif ($ptr_size == 8) {
17 'Q'
18 }
19 else {
20 die "Unsupported \$Config{ptrsize}: $ptr_size\n";
21 }
22 };
23 eval "sub PTR_PACK_TYPE () { $ptr_pack_type }";
24
25 my $big_endian = do {
26 my $ivnums = join '', (1 .. $Config{ivsize});
27 if ($Config{byteorder} eq $ivnums ) {
28 0
29 }
30 elsif ($Config{byteorder} eq scalar reverse $ivnums ) {
31 1
32 }
33 else {
34 die "Weird byteorder: $Config{byteorder}\n";
35 }
36 };
37 eval "sub BIG_ENDIAN () { $big_endian }";
38}
39
40use base 'Exporter';
41our @EXPORT_OK = (qw/PTR_SIZE PTR_PACK_TYPE BIG_ENDIAN/);
42
43=head1 NAME
44
45Devel::PeekPoke::Constants - Some convenience constants based on your machine
46
47=head1 DESRIPTION
48
49This module provides some convenience constants based on your machine. It
50provides the following constants (exportable on request)
51
52=head2 PTR_SIZE
53
54The size of your pointer, equivalent to L<$Config::ptr_size|Config>.
55
56=head2 PTR_PACK_TYPE
57
58The L<pack|perlfunc/pack> template type suitable for L</PTR_SIZE> pointers.
59Either C<L> (32 bit) or C<Q> (64 bit).
60
61=head2 BIG_ENDIAN
62
63An indicator whether your system is big-endian (constant is set to C<1>) or
64little-endian (constant is set to C<0>).
65
66=head1 COPYRIGHT
67
68See L<Devel::PeekPoke/COPYRIGHT>.
69
70=head1 LICENSE
71
72See L<Devel::PeekPoke/LICENSE>.
73
74=cut
75
761;