Thunk/ScalarValue.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 60 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/perl
2  
3 package Data::Thunk::ScalarValue;
4 BEGIN {
5 $Data::Thunk::ScalarValue::AUTHORITY = 'cpan:NUFFIN';
6 }
7 BEGIN {
8 $Data::Thunk::ScalarValue::VERSION = '0.07';
9 }
10  
11 use strict;
12 use warnings;
13  
14 use Carp;
15 use Check::ISA;
16  
17 use namespace::clean;
18  
19 use UNIVERSAL::ref;
20  
21 our $vivify_scalar;
22  
23 BEGIN {
24 $vivify_scalar = sub {
25 my $self = $_[0];
26  
27 # must rebless to something unoverloaded in order to get at the value
28 bless $self, "Data::Thunk::NoOverload";
29 my $val = $$self;
30 bless $self, __PACKAGE__;
31  
32 # try to replace the container with the value wherever we found it
33 local $@;
34 eval { $_[0] = $val }; # might be readonly;
35  
36 $val;
37 };
38 }
39  
40 use overload (
41 fallback => 1, map {
42 $_ => $vivify_scalar,
43 } qw( bool "" 0+ ${} @{} %{} &{} *{} )
44 );
45  
46 sub ref {
47 CORE::ref($_[0]->$vivify_scalar());
48 }
49  
50 sub AUTOLOAD {
51 my ( $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ );
52 $_[0]->$vivify_scalar();
53 unshift @_, $method;
54 goto $Data::Thunk::Code::call_method;
55 }
56  
57 sub DESTROY { }
58  
59 1;
60  
61 __END__