blib/lib/App/RecordStream/BaseRegistry.pm

filter: Statementstmt 79.7% 59 / 74 Branchbran 58.3% 7 / 12 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 8 totaltotal 72.4% 79 / 109 CC 10 SCAR 12.7
CC
10
Cov
77%
show_implementation
6.0
parse_single_nameless_implementation
5.5
list_implementations
5.0
CRAP 3.6
« blib/lib/App/RecordStream/Record.pm ↑ Summary blib/lib/App/RecordStream/Operation/fromjsonarray.pm »
1 package App::RecordStream::BaseRegistry;
2  
3 112 ▶use App::RecordStream::Site;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 112 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 112 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 112 ▶use Module::Pluggable::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub load_implementations
10 {
11 46 ▶ my $registry_class = shift;
Subroutine load_implementations: called CC=1 SCAR=0.2
Pod undocumented
12  
13 46 my $subtree = $registry_class->subtree();
14  
15 # include sites, overriding lower priority with higher priority
16 46 App::RecordStream::Site::bootstrap();
17 46 my @sites = sort { $a->{'priority'} <=> $b->{'priority'} } App::RecordStream::Site::list_sites();
18  
19 Module::Pluggable::Object->new(
20 require => 1,
21 search_path => [
22 "App::RecordStream::$subtree",
23 46 map { "$_->{path}::$subtree" } @sites
24 ],
25 )->plugins;
26 }
27  
28 {
29 112 my %class_registry;
30  
31 sub register_implementation
32 {
33 395 ▶ my $registry_class = shift;
Subroutine register_implementation: called CC=1 SCAR=0.0
Pod undocumented
34 395 my $name = shift;
35 395 my $class = shift;
36  
37 395 $class_registry{$registry_class}->{$name} = $class;
38 }
39  
40 sub parse_single_nameless_implementation
41 {
42 38 ▶ my $registry_class = shift;
Subroutine parse_single_nameless_implementation: called CC=5 SCAR=17.1
Pod undocumented
43 38 my $spec = shift;
44  
45 38 my @spec = split(/,/, $spec);
46  
47 38 ▶ if(!@spec)
Branch: 1 branch
BranchTrueFalseTotal
unless (@spec) 0 38 38
48 {
49 0 die "Bad " . $registry_class->typename() . " spec: " . $spec . "\n";
50 }
51  
52 38 my $aggr_name = shift(@spec);
53 38 my $class = $class_registry{$registry_class}->{$aggr_name};
54 38 ▶ if(!$class)
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 38 38
55 {
56 0 die "Bad " . $registry_class->typename() . ": " . $aggr_name . "\n";
57 }
58  
59 38 my $argct = $class->argct();
60 38 ▶ if(!ref($argct))
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $argct) 36 2 38
61 {
62 36 $argct = [$argct];
63 }
64 38 ▶ if(!(grep { $_ == @spec } @$argct))
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ == @spec;} @$argct) 0 38 38
65 {
66 0 print $class->long_usage();
67 0 exit 1;
68 }
69  
70 38 return $class->new(@spec);
71 }
72  
73 sub list_implementations
74 {
75 4 ▶ my $registry_class = shift;
Subroutine list_implementations: called CC=5 SCAR=16.1
Pod undocumented
76 4 ▶ my $prefix = shift || '';
Condition100%2/2
shift() || ''
l!l
22
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
77  
78 4 my %reverse;
79 my @classes;
80 4 for my $name (sort(keys(%{$class_registry{$registry_class}})))
81 {
82 66 my $class = $class_registry{$registry_class}->{$name};
83 66 my $ar = $reverse{$class};
84 66 ▶ if(!$ar)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ar) 38 28 66
85 {
86 38 $reverse{$class} = $ar = [];
87 38 push @classes, $class;
88 }
89 66 push @$ar, $name;
90 }
91 4 my $ret = "";
92 4 for my $class (@classes)
93 {
94 38 my $usage = $class->short_usage();
95 38 $ret .= $prefix . join(", ", @{$reverse{$class}}) . ": " . $usage . "\n";
96 }
97 4 return $ret;
98 }
99  
100 sub show_implementation
101 {
102 0 ▶ my $registry_class = shift;
Subroutine show_implementation: not called CC=2 SCAR=17.9
Pod undocumented
103 0 my $name = shift;
104  
105 0 my $class = $class_registry{$registry_class}->{$name};
106 0 ▶ if(!$class)
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 0 0
107 {
108 0 print "Bad " . $registry_class->typename() . ": " . $name . "\n";
109 0 exit 1;
110 }
111  
112 0 print $class->long_usage();
113 }
114 }
115  
116 # subclasses may override these all if they wish
117  
118 sub subtree
119 112 {
120 46 ▶ my $registry_class = shift;
Subroutine subtree: called CC=1 SCAR=0.0
Pod undocumented
121  
122 46 return $registry_class->begin_sentence_typename();
123 }
124  
125 sub begin_sentence_typename
126 {
127 46 ▶ my $registry_class = shift;
Subroutine begin_sentence_typename: called CC=1 SCAR=0.0
Pod undocumented
128  
129 46 my $t = $registry_class->typename();
130  
131 46 return uc(substr($t, 0, 1)) . substr($t, 1);
132 }
133  
134 sub typename
135 {
136 0 ▶ my $registry_class = shift;
Subroutine typename: not called CC=1 SCAR=6.9
Pod undocumented
137  
138 0 die "BaseRegistry subclass $registry_class did not implement typename()";
139 }
140  
141 112 1;
« blib/lib/App/RecordStream/Record.pm ↑ Summary blib/lib/App/RecordStream/Operation/fromjsonarray.pm »