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