blib/lib/Dallycot/Registry.pm

filter: Statementstmt 83.1% 64 / 77 Branchbran 66.6% 16 / 24 Conditioncond 66.6% 12 / 18 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 7 totaltotal 72.5% 111 / 153 CC 24 SCAR 17.1
CC
24
Cov
77%
get_assignment_uri
13.0
has_assignment
7.2
get_assignment
6.3
CRAP 5.6
« blib/lib/Dallycot/Library.pm ↑ Summary blib/lib/Dallycot/Value/Lambda.pm »
1 package Dallycot::Registry;
2 30 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: Manage namespace handler mappings
5  
6 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 30 ▶use MooseX::Singleton;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 30 ▶use MooseX::Types::Moose qw(ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 30 ▶use Promises qw(collect deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 has type_handlers => (
15 is => 'ro',
16 isa => 'HashRef',
17 30 ▶ default => sub { +{} }
Subroutine __ANON__: called CC=1 SCAR=0.0
18 30 );
19  
20 has namespaces => (
21 is => 'ro',
22 isa => 'HashRef',
23 30 ▶ default => sub { +{} }
Subroutine __ANON__: called CC=1 SCAR=0.0
24 30 );
25  
26 has _namespace_promises => (
27 is => 'ro',
28 isa => 'HashRef',
29 30 ▶ default => sub { +{} }
Subroutine __ANON__: called CC=1 SCAR=0.0
30 30 );
31  
32 sub register_used_namespaces {
33 201 ▶ my ( $self, @uris ) = @_;
Subroutine register_used_namespaces: called CC=4 SCAR=13.9
Pod undocumented
34  
35 201 ▶ if(@uris) {
Branch: 1 branch
BranchTrueFalseTotal
if (@uris) { } 118 83 201
36 118 for my $ns (@uris) {
37 161 ▶ $self->_namespace_promises->{$ns} ||= deferred;
Condition66%2/3
$self->_namespace_promises->{$ns} ||= &deferred()
l!l&&r!l&&!r
15290
MC/DC0%0/2
$self->_namespace_promises->{$ns} ||= &deferred()
$self->_namespace_promises->{$ns} &deferred()
Truth table66%2/3
A ||= B
A= $self->_namespace_promises->{$ns}B= &deferred()
ABresult
1X1
011
000
38 }
39  
40 118 return collect( map { $self->_namespace_promises->{$_}->promise } @uris );
41 }
42 else {
43 83 my $d = deferred;
44 83 $d -> resolve;
45 83 return $d -> promise;
46 }
47 }
48  
49 sub has_assignment {
50 933 ▶ my ( $self, $ns, $symbol ) = @_;
Subroutine has_assignment: called CC=7 SCAR=19.7
Pod undocumented
51  
52 933 ▶ if ( is_ArrayRef($ns) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ArrayRef($ns)) 324 609 933
53 324 for my $n (@$ns) {
54 return 1
55 if defined($n)
56 && $self->namespaces->{$n}
57 504 ▶ && $self->namespaces->{$n}->has_assignment($symbol);
Branch: 1 branch
BranchTrueFalseTotal
if defined $n and $self->namespaces->{$n} and $self->namespaces->{$n}->has_assignment($symbol) 303 201 504
Condition50%3/6
defined $n and $self->namespaces->{$n} and $self->namespaces->{$n}->has_assignment($symbol)
!ll&&!rl&&r
0201303
defined $n and $self->namespaces->{$n}
!ll&&!rl&&r
00504
MC/DC33%1/3
defined $n and $self->namespaces->{$n} and $self->namespaces->{$n}->has_assignment($symbol)
defined $n $self->namespaces->{$n} $self->namespaces->{$n}->has_assignment($symbol)
Truth table50%2/4
A and B and C
A= defined $nB= $self->namespaces->{$n}C= $self->namespaces->{$n}->has_assignment($symbol)
ABCresult
0XX0
10X0
1100
1111
58 }
59 21 return;
60 }
61  
62 return $self->namespaces->{$ns}
63 609 ▶ && $self->namespaces->{$ns}->has_assignment($symbol);
Condition100%3/3
$self->namespaces->{$ns} && $self->namespaces->{$ns}->has_assignment($symbol)
!ll&&!rl&&r
105201303
MC/DC100%2/2
$self->namespaces->{$ns} && $self->namespaces->{$ns}->has_assignment($symbol)
$self->namespaces->{$ns} $self->namespaces->{$ns}->has_assignment($symbol)
Truth table100%3/3
A && B
A= $self->namespaces->{$ns}B= $self->namespaces->{$ns}->has_assignment($symbol)
ABresult
0X0
100
111
64 }
65  
66 sub get_assignment {
67 604 ▶ my ( $self, $namespace, $symbol ) = @_;
Subroutine get_assignment: called CC=6 SCAR=18.5
Pod undocumented
68  
69 604 ▶ if ( is_ArrayRef($namespace) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ArrayRef($namespace)) 302 302 604
70 302 foreach my $n (@$namespace) {
71 502 ▶ if ( $self->has_assignment( $n, $symbol ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_assignment($n, $symbol)) 302 200 502
72 302 return $self->get_assignment( $n, $symbol );
73 }
74 }
75 0 return;
76 }
77  
78 302 ▶ if ( $self->namespaces->{$namespace} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->namespaces->{$namespace}) 302 0 302
79 302 my $ns = $self->namespaces->{$namespace};
80 302 ▶ if ( $ns->has_assignment($symbol) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ns->has_assignment($symbol)) 302 0 302
81 302 return $ns->get_assignment($symbol);
82 }
83 }
84  
85 0 return;
86 }
87  
88 sub get_assignment_uri {
89 1 ▶ my( $self, $namespace, $symbol ) = @_;
Subroutine get_assignment_uri: called CC=6 SCAR=25.6
Pod undocumented
90  
91 1 ▶ if ( is_ArrayRef($namespace) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ArrayRef($namespace)) 1 0 1
92 1 foreach my $n (@$namespace) {
93 2 ▶ if ( $self->has_assignment( $n, $symbol ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_assignment($n, $symbol)) 1 1 2
94 1 return "$n$symbol";
95 }
96 }
97 0 return;
98 }
99  
100 0 ▶ if ( $self->namespaces->{$namespace} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->namespaces->{$namespace}) 0 0 0
101 0 my $ns = $self->namespaces->{$namespace};
102 0 ▶ if ( $ns->has_assignment($symbol) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ns->has_assignment($symbol)) 0 0 0
103 0 return "$ns$symbol";
104 }
105 }
106  
107 0 return;
108 }
109  
110 sub has_namespace {
111 280 ▶ my ( $self, $ns ) = @_;
Subroutine has_namespace: called CC=2 SCAR=7.1
Pod undocumented
112  
113 280 ▶ return exists $self->namespaces->{$ns} && defined $self->namespaces->{$ns};
Condition66%2/3
exists $self->namespaces->{$ns} && defined $self->namespaces->{$ns}
!ll&&!rl&&r
720208
MC/DC50%1/2
exists $self->namespaces->{$ns} && defined $self->namespaces->{$ns}
exists $self->namespaces->{$ns} defined $self->namespaces->{$ns}
Truth table66%2/3
A && B
A= exists $self->namespaces->{$ns}B= defined $self->namespaces->{$ns}
ABresult
0X0
100
111
114 }
115  
116 sub register_namespace {
117 72 ▶ my ( $self, $ns, $context ) = @_;
Subroutine register_namespace: called CC=3 SCAR=11.2
Pod undocumented
118  
119 72 ▶ if ( !$self->has_namespace($ns) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_namespace($ns)) 72 0 72
120 72 $self->namespaces->{$ns} = $context;
121 }
122  
123 72 ▶ $self->_namespace_promises->{$ns} ||= deferred;
Condition66%2/3
$self->_namespace_promises->{$ns} ||= &deferred()
l!l&&r!l&&!r
9630
MC/DC0%0/2
$self->_namespace_promises->{$ns} ||= &deferred()
$self->_namespace_promises->{$ns} &deferred()
Truth table66%2/3
A ||= B
A= $self->_namespace_promises->{$ns}B= &deferred()
ABresult
1X1
011
000
124 72 $self->_namespace_promises->{$ns}->resolve();
125  
126 72 return;
127 }
128  
129 sub initialize {
130 0 ▶ my $self = shift;
Subroutine initialize: not called CC=2 SCAR=17.9
Pod undocumented
131  
132 0 $self->SUPER::initialize(@_);
133  
134 0 for my $type ( Dallycot::Value->types ) {
135 0 $self->type_handlers->{ $type->type } = $type;
136 }
137  
138 0 return $self;
139 }
140  
141 30 __PACKAGE__ -> meta -> make_immutable;
142  
143 30 1;
« blib/lib/Dallycot/Library.pm ↑ Summary blib/lib/Dallycot/Value/Lambda.pm »