blib/lib/Package/Prototype.pm

filter: Statementstmt 100% 53 / 53 Branchbran 94.4% 34 / 36 Conditioncond 83.3% 15 / 18 MC/DCmcdc 77.7% 7 / 9 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 93.6% 117 / 125 CC 29 SCAR 27.0
CC
29
Cov
95%
create
22.1
__ANON__
6.2
__ANON__
2.0
CRAP 14.9
↑ Summary lib/Package/Prototype.xs »
1 package Package::Prototype;
2 10 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 our $VERSION = "0.02";
7  
8 10 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 XSLoader::load(__PACKAGE__, $VERSION);
10  
11 19 ▶sub create {
Subroutine create: called CC=22 SCAR=30.9
Pod undocumented
12 19 my $class = shift;
13 19 ▶ die "create expects named options" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 18 19
14 18 my %options = @_;
15 18 for my $key (keys %options) {
16 21 ▶ die "Unknown create option: $key"
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "properties" or $key eq "methods" or $key eq "classname" 1 20 21
Condition100%6/6
$key eq "properties" or $key eq "methods" or $key eq "classname"
l!l&&r!l&&!r
1911
$key eq "properties" or $key eq "methods"
l!l&&r!l&&!r
1452
MC/DC100%3/3
$key eq "properties" or $key eq "methods" or $key eq "classname"
$key eq "properties" $key eq "methods" $key eq "classname"
Truth table100%4/4
A or B or C
A= $key eq "properties"B= $key eq "methods"C= $key eq "classname"
ABCresult
1XX1
01X1
0011
0000
17 unless $key eq 'properties' || $key eq 'methods' || $key eq 'classname';
18 }
19 17 ▶ my $properties = exists $options{properties} ? $options{properties} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $options{'properties'} ? : 14 3 17
20 17 ▶ my $methods = exists $options{methods} ? $options{methods} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $options{'methods'} ? : 5 12 17
21 17 ▶ die "properties must be a hash reference" unless ref($properties) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $properties eq "HASH" 1 16 17
22 16 ▶ die "methods must be a hash reference" unless ref($methods) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $methods eq "HASH" 0 16 16
23  
24 16 my %installed;
25 32 ▶ my $install = sub {
Subroutine __ANON__: called CC=6 SCAR=18.2
26 32 my ($name, $code) = @_;
27 32 ▶ die "Method name must be a nonempty string"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or ref $name or not length $name 1 31 32
Condition50%3/6
not defined $name or ref $name or not length $name
l!l&&r!l&&!r
0131
not defined $name or ref $name
l!l&&r!l&&!r
0032
MC/DC33%1/3
not defined $name or ref $name or not length $name
not defined $name ref $name not length $name
Truth table50%2/4
not(A) or B or not(C)
A= not defined $nameB= ref $nameC= not length $name
ABCresult
1XX1
01X1
0011
0000
28 if !defined($name) || ref($name) || !length($name);
29 31 ▶ die "Method name prototype is reserved by create" if $name eq 'prototype';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "prototype" 1 30 31
30 30 ▶ die "Duplicate method name: $name" if exists $installed{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $installed{$name} 2 28 30
31 28 $installed{$name} = $code;
32 16 };
33 16 for my $name (sort keys %$methods) {
34 5 ▶ die "Method $name must be a code reference" unless ref($methods->{$name}) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $methods->{$name} eq "CODE" 1 4 5
35 4 $install->($name, $methods->{$name});
36 }
37 14 for my $name (sort keys %$properties) {
38 21 my $spec = $properties->{$name};
39 21 ▶ die "Property $name must be a hash reference" unless ref($spec) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec eq "HASH" 0 21 21
40 21 for my $key (keys %$spec) {
41 32 ▶ die "Unknown property option: $key"
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "value" or $key eq "reader" or $key eq "writer" 1 31 32
Condition100%6/6
$key eq "value" or $key eq "reader" or $key eq "writer"
l!l&&r!l&&!r
2291
$key eq "value" or $key eq "reader"
l!l&&r!l&&!r
19310
MC/DC100%3/3
$key eq "value" or $key eq "reader" or $key eq "writer"
$key eq "value" $key eq "reader" $key eq "writer"
Truth table100%4/4
A or B or C
A= $key eq "value"B= $key eq "reader"C= $key eq "writer"
ABCresult
1XX1
01X1
0011
0000
42 unless $key eq 'value' || $key eq 'reader' || $key eq 'writer';
43 }
44 20 ▶ die "Property $name requires value" unless exists $spec->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $spec->{"value"} 1 19 20
45 19 my $value = $spec->{value};
46 19 ▶ my $reader = exists $spec->{reader} ? $spec->{reader} : $name;
Branch: 1 branch
BranchTrueFalseTotal
exists $spec->{'reader'} ? : 3 16 19
47 19 ▶ $install->($reader, sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
48 19 ▶ die "Reader $reader expects no arguments" unless @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 1 18 19
49 18 return $value;
50 19 });
51 17 ▶ if (exists $spec->{writer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{"writer"}) 9 8 17
52 9 my $writer = $spec->{writer};
53 10 ▶ $install->($writer, sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
54 10 ▶ die "Writer $writer expects one argument" unless @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 2 8 10
55 8 $value = $_[1];
56 8 return $value;
57 9 });
58 }
59 }
60 my $obj = exists $options{classname}
61 ? Package::Prototype::bless($class, {}, $options{classname})
62 9 ▶ : Package::Prototype::bless($class, {});
Branch: 1 branch
BranchTrueFalseTotal
exists $options{'classname'} ? : 1 8 9
63 9 $obj->prototype(%installed);
64 9 return $obj;
65 }
66  
67 10 1;
68 __END__
↑ Summary lib/Package/Prototype.xs »