Singleton/Frame.pm

filter: Statementstmt 90.5% 96 / 106 Branchbran 96.1% 25 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.1% 35 / 38 Podpod 0.0% 0 / 12 totaltotal 85.7% 156 / 182 CC 14 SCAR 6.0
CC
14
Cov
92%
_frame_by_depth
4.0
proclaim
4.0
deduce
3.0
CRAP 1.8
« Singleton/Frame/Deducer/Notifying.pm ↑ Summary Singleton/Frame/Builder/Base.pm »
1  
2 9 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Context::Singleton::Frame;
7 9 $Context::Singleton::Frame::VERSION = '1.0.9';
8 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use Context::Singleton::Frame::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Context::Singleton::Exception::Invalid;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Context::Singleton::Exception::Deduced;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Context::Singleton::Exception::Nondeducible;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Context::Singleton::Frame::Deducer::Notifying;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 9 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 9 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
19 196 ▶ q ("") => sub { ref ($_[0]) . q ([) . $_[0]->depth . q (]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 9 fallback => 1,
21 9 );
22  
23 9 __PACKAGE__->_generate_frame_class_internals;
24  
25 has q (_deducer_class)
26 => is => q (ro)
27 => init_arg => +undef
28 => lazy => 1
29 37 ▶ => default => sub { Context::Singleton::Frame::Deducer::Notifying:: }
Subroutine __ANON__: called CC=1 SCAR=0.0
30 9 ;
31  
32 has q (_deducer)
33 => is => q (ro)
34 => init_arg => +undef
35 => lazy => 1
36 50 ▶ => default => sub { $_[0]->root_frame->_deducer_class->new (frame => $_[0]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
37 9 => handles => [
38 q (is_deducible),
39 ];
40  
41 has q (db)
42 => is => q (ro)
43 => init_arg => +undef
44 => lazy => 1
45 50 ▶ => default => sub { $_[0]->parent ? $_[0]->parent->db : $_[0]->db_class->instance }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->parent ? : 13 37 50
46 9 ;
47  
48 has q (db_class)
49 => is => q (ro)
50 => lazy => 1
51 37 ▶ => default => sub { Context::Singleton::Frame::DB:: }
Subroutine __ANON__: called CC=1 SCAR=0.0
52 9 ;
53  
54 has q (depth)
55 => is => q (ro)
56 => init_arg => +undef
57 => lazy => 1
58 68 ▶ => default => sub { $_[0]->parent ? $_[0]->parent->depth + 1 : 0 }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->parent ? : 22 46 68
59 9 ;
60  
61 9 has q (parent)
62 => is => q (ro)
63 ;
64  
65 has q (root_frame)
66 => is => q (ro)
67 => init_arg => +undef
68 => lazy => 1
69 57 ▶ => default => sub { $_[0]->parent ? $_[0]->parent->root_frame : $_[0] }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->parent ? : 17 40 57
70 9 ;
71  
72 646 ▶sub _effective_frame {
Subroutine _effective_frame: called CC=2 SCAR=6.9
73 646 my $frame = shift;
74  
75 646 ▶ ref ($frame) ? $frame : $frame->current_frame;
Branch: 1 branch
BranchTrueFalseTotal
ref $frame ? : 610 36 646
76 }
77  
78 77 ▶sub _frame_by_depth {
Subroutine _frame_by_depth: called CC=4 SCAR=13.9
79 77 my ($frame, $depth) = @_;
80  
81 return
82 77 ▶ if $depth < 0
Branch: 1 branch
BranchTrueFalseTotal
if $depth < 0 1 76 77
83 ;
84  
85 76 my $distance = $frame->depth - $depth;
86 return
87 76 ▶ if $distance < 0
Branch: 1 branch
BranchTrueFalseTotal
if $distance < 0 1 75 76
88 ;
89  
90 75 my $found = $frame;
91  
92 75 ▶ $found = $found->parent
Branch: 1 branch
BranchTrueFalseTotal
$distance-- > 0 and do { $found = $found->parent } 10 75 85
93 while $distance-- > 0
94 ;
95  
96 75 $found;
97 }
98  
99 10 ▶sub _generate_frame_class_internals {
Subroutine _generate_frame_class_internals: called CC=1 SCAR=0.0
100 10 my ($class) = @_;
101  
102 10 my $current_frame = [ $class->build_frame ];
103  
104 9 ▶ no strict q (refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
105 10 ▶ *{"${class}::_localisable_current_frame"} = sub { $current_frame };
Subroutine __ANON__: called CC=1 SCAR=0.0
106 }
107  
108 3 ▶sub _throw_deduced {
Subroutine _throw_deduced: called CC=1 SCAR=0.0
109 3 my ($frame, $singleton) = @_;
110  
111 3 throw Context::Singleton::Exception::Deduced ($singleton);
112 }
113  
114 3 ▶sub _throw_nondeducible {
Subroutine _throw_nondeducible: called CC=1 SCAR=0.0
115 3 my ($frame, $singleton) = @_;
116  
117 3 throw Context::Singleton::Exception::Nondeducible ($singleton);
118 }
119  
120 81 ▶sub build_frame {
Subroutine build_frame: called CC=2 SCAR=6.9
Pod undocumented
121 81 my ($class, %proclaim) = @_;
122  
123 81 ▶ my $frame = ref ($class)
Branch: 1 branch
BranchTrueFalseTotal
ref $class ? : 30 51 81
124 ? $class->new (parent => $class)
125 : $class->new
126 ;
127  
128 81 $frame->proclaim (%proclaim);
129  
130 81 return $frame;
131 }
132  
133 309 ▶sub contrive {
Subroutine contrive: called CC=1 SCAR=0.0
Pod undocumented
134 309 (&_effective_frame)->db->contrive (@_);
135 }
136  
137 2 ▶sub contrive_class {
Subroutine contrive_class: called CC=1 SCAR=0.0
Pod undocumented
138 2 (&_effective_frame)->db->contrive_class (@_);
139 }
140  
141 69 ▶sub current_frame {
Subroutine current_frame: called CC=1 SCAR=0.0
Pod undocumented
142 69 shift->_localisable_current_frame->[0];
143 }
144  
145 0 ▶sub debug {
Subroutine debug: not called CC=1 SCAR=2.6
Pod undocumented
146 0 my ($frame, @message) = @_;
147  
148 0 my $sub = (caller(1))[3];
149 0 $sub =~ s/^.*://;
150  
151 9 ▶ use feature q (say);
Subroutine BEGIN: called CC=1 SCAR=0.0
152 0 say qq (# [${\ $frame->depth}] $sub ${\ join ' ', @message });
153 }
154  
155 28 ▶sub deduce {
Subroutine deduce: called CC=3 SCAR=11.0
Pod undocumented
156 28 my ($frame, $singleton, @proclaim) = (&_effective_frame, @_);
157  
158 28 ▶ $frame = $frame->new (@proclaim)
Branch: 1 branch
BranchTrueFalseTotal
if @proclaim 0 28 28
159 if @proclaim
160 ;
161  
162 28 ▶ $frame->_throw_nondeducible ($singleton)
Branch: 1 branch
BranchTrueFalseTotal
unless $frame->try_deduce($singleton) 3 24 27
163 unless $frame->try_deduce ($singleton)
164 ;
165  
166 24 $frame->_deducer->deduce ($singleton);
167 }
168  
169 0 ▶sub frame {
Subroutine frame: not called CC=1 SCAR=6.9
Pod undocumented
170 0 my ($frame, $code) = (&_effective_frame, @_);
171  
172 0 local $frame->_localisable_current_frame->[0] = $frame->build_frame;
173  
174 0 $code->();
175 }
176  
177 129 ▶sub is_deduced {
Subroutine is_deduced: called CC=1 SCAR=0.0
Pod undocumented
178 129 (&_effective_frame)->_deducer->is_deduced (@_);
179 }
180  
181 6 ▶sub load_rules {
Subroutine load_rules: called CC=1 SCAR=0.0
Pod undocumented
182 6 (&_effective_frame)->db->load_rules (@_);
183 }
184  
185 139 ▶sub proclaim {
Subroutine proclaim: called CC=4 SCAR=13.9
Pod undocumented
186 139 my ($frame, @proclaim) = (&_effective_frame, @_);
187  
188 return
189 unless @proclaim
190 139 ▶ ;
Branch: 1 branch
BranchTrueFalseTotal
unless @proclaim 66 73 139
191  
192 73 my $retval;
193 73 ▶ while (@proclaim) {
Branch: 1 branch
BranchTrueFalseTotal
if (@proclaim) 75 70 145
194 75 my $singleton = shift @proclaim;
195 75 my $value = shift @proclaim;
196  
197 75 ▶ $frame->_throw_deduced ($singleton)
Branch: 1 branch
BranchTrueFalseTotal
if $frame->is_deduced($singleton) 3 72 75
198 if $frame->is_deduced ($singleton)
199 ;
200  
201 72 $retval = $frame->_deducer->proclaim ($singleton, $value);
202 }
203  
204 70 $retval;
205 }
206  
207 0 ▶sub trigger {
Subroutine trigger: not called CC=1 SCAR=6.9
Pod undocumented
208 0 (&_effective_frame)->db->trigger (@_);
209 }
210  
211 33 ▶sub try_deduce {
Subroutine try_deduce: called CC=1 SCAR=0.0
Pod undocumented
212 33 (&_effective_frame)->_deducer->try_deduce (@_);
213 }
214  
215 9 1;
216  
217 __END__
« Singleton/Frame/Deducer/Notifying.pm ↑ Summary Singleton/Frame/Builder/Base.pm »