blib/lib/Class/Data/Lite.pm

filter: Statementstmt 100% 37 / 37 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 98.3% 58 / 59 CC 8 SCAR 11.4
CC
8
Cov
98%
import
6.0
__ANON__
3.0
BEGIN
1.0
CRAP 3.1
↑ Summary
1 package Class::Data::Lite;
2 4 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = "0.0010";
7  
8 1 ▶sub _croak {require Carp; Carp::croak(@_) }
Subroutine _croak: called CC=1 SCAR=0.0
9  
10 4 ▶sub import {
Subroutine import: called CC=6 SCAR=17.9
11 4 shift;
12 4 my %args = @_;
13 4 my $pkg = caller(0);
14  
15 4 my %key_ctor = (
16 rw => \&_mk_accessor,
17 ro => \&_mk_ro_accessor,
18 );
19  
20 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 for my $key (keys %key_ctor) {
22 8 ▶ if (my $accessors = delete $args{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $accessors = delete $args{$key}) 5 3 8
23 5 ▶ _croak "value of the '$key' parameter should be an arrayref or hashref"
Branch: 1 branch
BranchTrueFalseTotal
unless ref($accessors) =~ /^(?:HASH|ARRAY)$/ 0 5 5
24 unless ref($accessors) =~ /^(?:HASH|ARRAY)$/;
25 5 ▶ my %h = ref($accessors) eq 'HASH' ? %$accessors : map {($_ => undef)} @$accessors;
Branch: 1 branch
BranchTrueFalseTotal
ref $accessors eq 'HASH' ? : 4 1 5
26 5 ▶ while (my ($k, $v) = each %h) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %h) 7 5 12
27 7 *{"${pkg}::${k}"} = $key_ctor{$key}->($pkg, $k, $v);
28 }
29 }
30 }
31 }
32  
33 5 ▶sub _mk_accessor {
Subroutine _mk_accessor: called CC=1 SCAR=0.0
34 5 my ($pkg, $meth, $data) = @_;
35 10 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
36 10 ▶ if (@_>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 3 7 10
37 3 ▶ if ($_[0] ne $pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] ne $pkg) 1 2 3
38 # In the case of rw, raise an exception here because there is a
39 # possibility of being overwritten from a child class.
40 # In the case of ro, there is no risk, so we do not raise
41 # exceptions in particular.
42 1 _croak qq[can't call "${pkg}::${meth}" as object method or inherited class method];
43 }
44 2 $data = $_[1];
45 }
46 9 $data;
47 5 };
48 }
49  
50 2 ▶sub _mk_ro_accessor {
Subroutine _mk_ro_accessor: called CC=1 SCAR=0.0
51 2 my ($pkg, $meth, $data) = @_;
52 2 ▶ return sub { $data };
Subroutine __ANON__: called CC=1 SCAR=0.0
53 }
54  
55 4 1;
56 __END__
↑ Summary