File Coverage

blib/lib/Devel/PeekPoke/Constants.pm
Criterion Covered Total %
statement 23 27 85.1
branch 3 8 37.5
condition n/a
subroutine 5 5 100.0
pod n/a
total 31 40 77.5


line stmt bran cond sub pod time code
1             package Devel::PeekPoke::Constants;
2              
3 4     4   21744 use strict;
  4         7  
  4         324  
4 4     4   23 use warnings;
  4         18  
  4         120  
5              
6 4     4   19 use Config;
  4         13  
  4         983  
7              
8             BEGIN {
9 4     4   4171 my $ptr_size = $Config{ptrsize};
10 4         13476 eval "sub PTR_SIZE () { $ptr_size }";
11              
12 4         15 my $ptr_pack_type = do {
13 4 50       32 if ($ptr_size == 4) {
    50          
14 0         0 'L'
15             }
16             elsif ($ptr_size == 8) {
17 4         12 'Q'
18             }
19             else {
20 0         0 die "Unsupported \$Config{ptrsize}: $ptr_size\n";
21             }
22             };
23 4         169 eval "sub PTR_PACK_TYPE () { $ptr_pack_type }";
24              
25 4         12 my $big_endian = do {
26 4         42 my $ivnums = join '', (1 .. $Config{ivsize});
27 4 50       260 if ($Config{byteorder} eq $ivnums ) {
    0          
28 4         107 0
29             }
30             elsif ($Config{byteorder} eq scalar reverse $ivnums ) {
31 0         0 1
32             }
33             else {
34 0         0 die "Weird byteorder: $Config{byteorder}\n";
35             }
36             };
37 4         291 eval "sub BIG_ENDIAN () { $big_endian }";
38             }
39              
40 4     4   32 use base 'Exporter';
  4         9  
  4         690  
41             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 template type suitable for L pointers.
59             Either C (32 bit) or C (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.
69              
70             =head1 LICENSE
71              
72             See L.
73              
74             =cut
75              
76             1;