blib/lib/pluskeys.pm

filter: Statementstmt 100% 35 / 35 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 95.9% 47 / 49 CC 4 SCAR 6.6
CC
4
Cov
95%
import
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
↑ Summary
1 package pluskeys;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our($VERSION) = q($Revision: 2.4 $) =~ / \b ( \d+ (?: \. \d+ )+ ) \b /x;
9  
10 2 my $My_Package = __PACKAGE__;
11  
12 4 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
13 4 shift; # discard "pluskeys" invocant
14  
15 #################################################################
16 # Create named constants in caller's package so they
17 # can be used to access munged member names with +NAME
18 # which both catches typos and adds package-name munging so
19 # that more than one class in a hierarchy can have a key
20 # with the same name.
21 #
22 # Must be called from a BEGIN block to do any good. That's
23 # why it is a use statement, since that has a BEGIN blocked
24 # wrapped around it.
25 #################################################################
26  
27 4 for my $member (@_) {
28 # Has to start with a letter or an underscore, and be one
29 # or more identifier characters long and nothing else.
30 5 ▶ $member =~ / ^ (?= [\p{Letter}_] ) \w+ $ /x
Branch: 1 branch
BranchTrueFalseTotal
$member =~ / ^ (?= [\p{Letter}_] ) \w+ $ /x or croak("Bad pluskey: '${member}' is not a valid identifier") 5 0 5
31 || croak "Bad pluskey: '$member' is not a valid identifier";
32  
33 5 my $his_package = caller;
34  
35 5 ▶ eval <<"MAKE_A_MEMBER_CONSTANT" || croak "member init of $member failed: $@";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval " package $his_package;\n use constant $member => ${My_Package}::_mk_safe_member('${member}');\n 1;\n" or croak("member init of $member failed: $@") 5 0 5
36 package $his_package;
37 use constant $member => ${My_Package}::_mk_safe_member('$member');
38 1;
39 MAKE_A_MEMBER_CONSTANT
40 }
41 }
42  
43 5 ▶sub _mk_safe_member($) {
Subroutine _mk_safe_member: called CC=1 SCAR=0.0
44 5 my($member_name) = @_;
45 5 my $his_package = caller;
46 5 return $his_package . "::" . $member_name;
47 }
48  
49 2 1;
50  
51 __END__
↑ Summary