blib/lib/Sub/Lib.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 20 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 100% 8 / 8 totaltotal 100% 99 / 99 CC 12 SCAR 11.0
CC
12
Cov
100%
__ANON__
6.0
new
5.0
void
2.0
CRAP 3.0
↑ Summary
1 package Sub::Lib;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use v5.8.8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.03';
8  
9 5 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
10 5 my ($class, @args) = @_;
11  
12 5 my $args;
13 5 ▶ if(1 == @args) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == @args) { } 2 3 5
14 2 ▶ die "reference argument to new() must be a HASH\n"
Branch: 1 branch
BranchTrueFalseTotal
unless "HASH" eq ref $args[0] 1 1 2
15 unless 'HASH' eq ref $args[0];
16 1 $args = $args[0];
17 }
18 else {
19 3 ▶ die "non-reference argument list to new() must have an even number of elements\n"
Branch: 1 branch
BranchTrueFalseTotal
unless 0 == @args % 2 1 2 3
20 unless 0 == @args % 2;
21 2 $args = {@args};
22 }
23  
24 # \o/ Lobe den Abgrund
25 3 my $self = bless do {
26 3 my $_lib = { };
27 15 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
28 15 my ($name, $sub) = @_;
29  
30 15 ▶ return $_lib
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 5 10 15
31 unless defined $name;
32  
33 10 ▶ if(defined $sub) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sub) { } 3 7 10
34 3 ▶ die "sub-routine ($name) is not a sub-routine?\n"
Branch: 1 branch
BranchTrueFalseTotal
unless "CODE" eq ref $sub 1 2 3
35 unless 'CODE' eq ref $sub;
36 die "sub-routine ($name) already installed in library\n"
37 2 ▶ if exists $_lib->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_lib->{$name} 1 1 2
38  
39 1 $_lib->{$name} = $sub;
40 }
41 else {
42 die "sub-routine ($name) not installed in library\n"
43 7 ▶ unless exists $_lib->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_lib->{$name} 1 6 7
44 }
45  
46 7 return $_lib->{$name};
47 }
48 3 }, $class;
49  
50 $self->($_, $args->{$_})
51 3 for keys %$args;
52 2 return $self;
53 }
54  
55 2 ▶sub has {
Subroutine has: called CC=1 SCAR=0.0
Pod documented
56 2 my ($self, $name) = @_;
57  
58 2 my $_lib = $self->();
59 2 return $_lib->{$name};
60 }
61  
62 1 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod documented
63 1 my ($self, $name, @args) = @_;
64  
65 1 return $self->($name)->(@args);
66 }
67  
68 1 ▶sub call {
Subroutine call: called CC=1 SCAR=0.0
Pod documented
69 1 my ($self, $name, $object, @args) = @_;
70  
71 1 my $sub = $self->($name);
72 1 return $object->$sub(@args);
73 }
74  
75 2 ▶sub void {
Subroutine void: called CC=2 SCAR=6.9
Pod documented
76 2 my ($self, $name) = @_;
77  
78 2 my $_lib = $self->();
79 my $sub = exists $_lib->{$name}
80 ? $_lib->{$name}
81 1 ▶ : sub { return }
Subroutine __ANON__: called CC=1 SCAR=0.0
82 2 ▶ ;
Branch: 1 branch
BranchTrueFalseTotal
exists $_lib->{$name} ? : 1 1 2
83  
84 2 return $sub;
85 }
86  
87 1 ▶sub curry {
Subroutine curry: called CC=1 SCAR=0.0
Pod documented
88 1 my ($self, $name, @args) = @_;
89  
90 1 my $sub = $self->($name);
91 1 ▶ return sub { $sub->(@args, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
92 }
93  
94 1 ▶sub o {
Subroutine o: called CC=1 SCAR=0.0
Pod documented
95 1 my ($self, $name, $object, @args) = @_;
96  
97 1 my $sub = $self->($name);
98 1 ▶ return sub { $object->$sub(@args, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
99 }
100  
101 2 ▶sub y {
Subroutine y: called CC=2 SCAR=6.9
Pod documented
102 2 my ($self, $name, $sub, @args) = @_;
103  
104 2 ▶ die "code reference required for lambda\n"
Branch: 1 branch
BranchTrueFalseTotal
unless "CODE" eq ref $sub 1 1 2
105 unless 'CODE' eq ref $sub;
106  
107 1 ▶ return sub { $sub->( $self->($name), @args, @_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
108 1 }
109  
110  
111 1 1
112 __END__
↑ Summary