File Coverage

blib/lib/Keyword/Value.pm
Criterion Covered Total %
statement 24 24 100.0
branch 4 8 50.0
condition 3 9 33.3
subroutine 8 8 100.0
pod n/a
total 39 49 79.5


line stmt bran cond sub pod time code
1             ########################################################################
2             # housekeeping
3             ########################################################################
4             package Keyword::Value v0.1.1;
5 11     11   215848 use v5.22;
  11         26  
6              
7 11     11   6507 use Keyword::Declare;
  11         1322688  
  11         59  
8              
9 11     11   5068 use Data::Lock qw( dlock );
  11         46216  
  11         519  
10 11     11   51 use Carp qw( carp croak );
  11         15  
  11         1397  
11              
12             ########################################################################
13             # package variables
14             ########################################################################
15              
16             our @CARP_NOT = ( __PACKAGE__ );
17              
18             # variable avoids having to export the sub into every caller's space.
19              
20             our $const
21             = sub : lvalue
22             {
23 12   50 12   85 state $verbose = $ENV{ VERBOSE_KEYWORD_VALUE } // '';
24              
25             # lvalue delays dlock until after state sets its own magic flag.
26              
27 12 50       25 $_[0] = $_[1] if @_ > 1;
28              
29 12 50 0     18 $_[0] // carp "Fixing undefined value"
30             if $verbose;
31              
32 12         30 dlock $_[0];
33              
34             # returns ref from stack to allow assignment via lvalue.
35              
36 12         131 $_[0]
37             };
38              
39             ########################################################################
40             # exported subs
41             ########################################################################
42              
43             sub import
44             {
45             # defined inside of "import" this pushes the "value" keyword
46             # into the caller's space.
47             #
48             # lock a variable (i.e., with a sigil).
49             # lacking a leading variable, constify the entire expression.
50 10     10   66  
51 11 50 50 11   148785 keyword value( Var $var, Expr $expr )
  10         134  
  10         29  
52             {
53             ( 0 > index "$var", '::' )
54             ? "\$Keyword::Value::const->( my $var $expr )"
55             : "\$Keyword::Value::const->( $var $expr )"
56             }
57 10         379  
58 11 50 50 11   75486 keyword value ( Expr $expr )
  10         86  
  10         29  
59             {{{
60             $Keyword::Value::const->( <{$expr}> )
61             }}}
62             }
63              
64             # keep require happy
65             1
66             __END__