File Coverage

blib/lib/Const/PP.pm
Criterion Covered Total %
statement 17 78 21.7
branch 0 36 0.0
condition 0 29 0.0
subroutine 6 14 42.8
pod 0 5 0.0
total 23 162 14.2


line stmt bran cond sub pod time code
1             package Const::PP;
2              
3 1     1   99508 use 5.006;
  1         3  
4 1     1   4 use strict;
  1         5  
  1         26  
5 1     1   4 use warnings;
  1         1  
  1         43  
6 1     1   4 no warnings 'recursion';
  1         1  
  1         47  
7              
8             our $VERSION = '1.00';
9              
10 1     1   4 use Scalar::Util qw/reftype/;
  1         1  
  1         49  
11              
12 1     1   3 use base qw/Import::Export/;
  1         2  
  1         544  
13              
14             our %EX = (
15             const => [qw/all/],
16             make_readonly => [qw/all/],
17             make_readonly_ref => [qw/all/],
18             unmake_readonly => [qw/all/],
19             is_readonly => [qw/all/],
20             );
21              
22             our $RECURSION_LIMIT = 10000;
23              
24             sub _make_readonly {
25              
26 0 0 0 0     if (my $type = reftype $_[0] and not &Internals::SvREADONLY($_[0])) {
27 0           &Internals::SvREADONLY($_[0], 1);
28 0 0         if ($type eq 'ARRAY') {
    0          
29 0           _make_readonly($_) for @{ $_[0] };
  0            
30             }
31             elsif ($type eq 'HASH') {
32 0           &Internals::hv_clear_placeholders($_[0]);
33 0           _make_readonly($_) for values %{ $_[0] };
  0            
34             }
35             }
36              
37 0           Internals::SvREADONLY($_[0], 1);
38              
39 0           return;
40             }
41              
42             sub _make_readwrite {
43 0 0 0 0     if (my $type = reftype $_[0] and &Internals::SvREADONLY($_[0])) {
44 0           &Internals::SvREADONLY($_[0], 0);
45 0 0         if ($type eq 'ARRAY') {
    0          
46 0           _make_readwrite($_) for @{ $_[0] };
  0            
47             }
48             elsif ($type eq 'HASH') {
49 0           &Internals::hv_clear_placeholders($_[0]);
50 0           _make_readwrite($_) for values %{ $_[0] };
  0            
51             }
52              
53             }
54 0           Internals::SvREADONLY($_[0], 0);
55             }
56              
57             sub _is_readonly {
58 0 0   0     if (my $type = reftype $_[0]) {
59 0 0 0       if ($type eq 'HASH' || $type eq 'ARRAY') {
60 0 0         return &Internals::SvREADONLY($_[0]) ? 1 : 0;
61             }
62             }
63              
64 0 0         return Internals::SvREADONLY($_[0]) ? 1 : 0;
65             }
66              
67             sub const (\[$@%]@) {
68 0     0 0   my (undef, @args) = @_;
69              
70 0 0         if ( ! scalar @args ) {
71 0           die "No value for readonly variable";
72             }
73              
74 0 0         if ( ref $_[0] eq 'ARRAY') {
    0          
75 0           @{ $_[0] } = @args;
  0            
76             }
77             elsif ( ref $_[0] eq 'HASH') {
78 0 0         die 'Odd number of elements in hash assignment' if @args % 2;
79 0           %{ $_[0] } = @args;
  0            
80             }
81             else {
82 0   0       my $ref = reftype($args[0]) || "";
83 0 0 0       if ($ref eq 'HASH' || $ref eq 'ARRAY') {
84 0           ${ $_[0] } = $args[0];
  0            
85 0           $_[0] = ${$_[0]};
  0            
86             } else {
87 0           ${ $_[0] } = $args[0];
  0            
88             }
89             }
90              
91 0           _make_readonly($_[0]);
92              
93 0           return $_[0];
94             }
95              
96             sub make_readonly (\[$@%]@) {
97 0   0 0 0   my $ref= reftype($_[0]) || "";
98 0 0 0       if ( $ref eq 'HASH' || $ref eq 'ARRAY' ) {
99 0           _make_readonly($_[0]);
100             } else {
101 0           _make_readonly(${$_[0]});
  0            
102             }
103 0           $_[0];
104             }
105              
106             sub make_readonly_ref {
107 0     0 0   _make_readonly($_[0]);
108 0           return $_[0];
109             }
110              
111             sub unmake_readonly (\[$@%]@) {
112 0   0 0 0   my $ref= reftype($_[0]) || "";
113 0 0 0       if ( $ref eq 'HASH' || $ref eq 'ARRAY' ) {
114 0           _make_readwrite($_[0]);
115             } else {
116 0           _make_readwrite(${$_[0]});
  0            
117             }
118 0           $_[0];
119             }
120              
121             sub is_readonly (\[$@%]@) {
122 0   0 0 0   my $ref= reftype($_[0]) || "";
123 0 0 0       if ($ref eq 'HASH' || $ref eq 'ARRAY' ) {
124 0           return _is_readonly($_[0]);
125             } else {
126 0           return _is_readonly(${$_[0]});
  0            
127             }
128             }
129              
130             1;
131              
132             __END__