Spoon/Hub.pm

filter: Statementstmt 65.8% 56 / 85 Branchbran 44.7% 17 / 38 Conditioncond 15.3% 2 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 73.3% 11 / 15 Podpod 0.0% 0 / 10 totaltotal 50.8% 86 / 169 CC 27 SCAR 27.8
CC
27
Cov
55%
add_hooks
46.2
load_class
16.4
process
12.0
CRAP 16.1
« Spoon/Trace.pm ↑ Summary Spoon/Command.pm »
1 package Spoon::Hub;
2 5 ▶use Spoon::Base -Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 const class_id => 'hub';
5 5 field action => '_default_';
6  
7 5 field main => -weak;
8 5 field config_files => [];
9 5 field all_hooks => [];
10  
11 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
12 6 $self = super;
13 6 $self->init;
14 6 $Spoon::Base::HUB = $self;
15 }
16  
17 5 our $AUTOLOAD;
18 13 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=11.2
19 13 ▶ $AUTOLOAD =~ /.*::(.*)/
Branch: 1 branch
BranchTrueFalseTotal
$Spoon::Hub::AUTOLOAD =~ /.*::(.*)/ or die "Can't AUTOLOAD '$Spoon::Hub::AUTOLOAD'" 13 0 13
20 or die "Can't AUTOLOAD '$AUTOLOAD'";
21 13 my $class_id = $1;
22 13 ▶ return if $class_id eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $class_id eq "DESTROY" 0 13 13
23 13 field $class_id =>
24 -init => "\$self->load_class('$class_id')";
25 13 $self->$class_id(@_);
26 }
27  
28 0 ▶sub pre_process {}
Subroutine pre_process: not called CC=1 SCAR=6.9
Pod undocumented
29 0 ▶sub post_process {}
Subroutine post_process: not called CC=1 SCAR=6.9
Pod undocumented
30  
31 0 ▶sub process {
Subroutine process: not called CC=3 SCAR=24.8
Pod undocumented
32 0 $self->preload;
33 0 my $action = $self->action;
34 die "No plugin for action '$action'"
35 0 ▶ unless defined $self->registry->lookup->action->{$action};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->registry->lookup->action->{$action} 0 0 0
36 my ($class_id, $method) =
37 0 @{$self->registry->lookup->action->{$action}};
38 0 ▶ $method ||= $action;
Condition0%0/3
$method ||= $action
l!l&&r!l&&!r
000
MC/DC0%0/2
$method ||= $action
$method $action
Truth table0%0/3
A ||= B
A= $methodB= $action
ABresult
1X1
011
000
39 0 return $self->$class_id->$method;
40 }
41  
42 0 ▶sub preload {
Subroutine preload: not called CC=2 SCAR=17.9
Pod undocumented
43 0 my $preload = $self->registry->lookup->preload;
44 map {
45 0 $self->load_class($_->[0])
46 } sort {
47 0 $b->[1] <=> $a->[1]
48 } map {
49 0 my %hash = @{$preload->{$_}}[1..$#{$preload->{$_}}];
50 0 ▶ [$_, $hash{priority} || 0];
Condition0%0/2
$hash{'priority'} || 0
l!l
00
MC/DC0%0/1
$hash{'priority'} || 0
$hash{'priority'}
Truth table0%0/2
A
A= $hash{'priority'}
Aresult
11
00
51 } keys %$preload;
52 0 return $self;
53 }
54  
55 9 ▶sub load_class {
Subroutine load_class: called CC=13 SCAR=28.0
Pod undocumented
56 9 my $class_id = shift;
57 9 ▶ return $self if $class_id eq 'hub';
Branch: 1 branch
BranchTrueFalseTotal
if $class_id eq "hub" 0 9 9
58 return $self->$class_id
59 9 ▶ if $self->can($class_id) and defined $self->{$class_id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($class_id) and defined $self->{$class_id} 0 9 9
Condition33%1/3
$self->can($class_id) and defined $self->{$class_id}
!ll&&!rl&&r
090
MC/DC0%0/2
$self->can($class_id) and defined $self->{$class_id}
$self->can($class_id) defined $self->{$class_id}
Truth table33%1/3
A and B
A= $self->can($class_id)B= defined $self->{$class_id}
ABresult
0X0
100
111
60  
61 9 my $class_class = $class_id . '_class';
62  
63 my $class_name = $self->config->can($class_class)
64 ? $self->config->$class_class
65 : $self->registry_loaded
66 9 ▶ ? $self->registry->lookup->classes->{$class_id}
Branch: 2 branches
BranchTrueFalseTotal
$self->config->can($class_class) ? : 9 0 9
$self->registry_loaded ? : 0 0 0
67 : Carp::confess "Can't find a class for class_id '$class_id'";
68  
69 9 ▶ Carp::confess "No class defined for class_id '$class_id'"
Branch: 1 branch
BranchTrueFalseTotal
unless $class_name 0 9 9
70 unless $class_name;
71 9 ▶ unless ($class_name->can('new')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_name->can("new")) 8 1 9
72 8 eval "require $class_name";
73 8 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 2 6 8
74 }
75 $self->add_hooks
76 7 ▶ unless $class_id eq 'hooks';
Branch: 1 branch
BranchTrueFalseTotal
unless $class_id eq "hooks" 6 1 7
77 7 ▶ my $object = $class_name->new
Branch: 1 branch
BranchTrueFalseTotal
my $object = $class_name->new or die "Can't create new '${class_name}' object" 7 0 7
78 or die "Can't create new '$class_name' object";
79 7 ▶ $class_id ||= $object->class_id;
Condition33%1/3
$class_id ||= $object->class_id
l!l&&r!l&&!r
700
MC/DC0%0/2
$class_id ||= $object->class_id
$class_id $object->class_id
Truth table33%1/3
A ||= B
A= $class_idB= $object->class_id
ABresult
1X1
011
000
80 7 ▶ die "No class_id defined for class: '$class_name'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $class_id 0 7 7
81 unless $class_id;
82 7 field $class_id =>
83 -init => "\$self->load_class('$class_id')";
84 7 $self->$class_id($object);
85 7 $object->init;
86 7 return $object;
87 }
88  
89 6 ▶sub add_hooks {
Subroutine add_hooks: called CC=8 SCAR=38.3
Pod undocumented
90 6 ▶ return unless $self->registry_loaded;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->registry_loaded 6 0 6
91 my $hooks = $self->registry->lookup->{hook}
92 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
my $hooks = $self->registry->lookup->{"hook"} or return 0 0 0
93 0 for my $class_name (keys %$hooks) {
94 0 ▶ next unless $class_name->can('new');
Branch: 1 branch
BranchTrueFalseTotal
unless $class_name->can("new") 0 0 0
95 0 ▶ $self->add_hook(@$_) for @{$hooks->{$class_name} || []};
Condition0%0/2
$hooks->{$class_name} || []
l!l
00
MC/DC0%0/1
$hooks->{$class_name} || []
$hooks->{$class_name}
Truth table0%0/2
A
A= $hooks->{$class_name}
Aresult
11
00
96 0 delete $hooks->{$class_name};
97 }
98 delete $self->registry->lookup->{hook}
99 0 ▶ if not keys %$hooks;
Branch: 1 branch
BranchTrueFalseTotal
if not keys %$hooks 0 0 0
100 }
101  
102 1 ▶sub add_hook {
Subroutine add_hook: called CC=1 SCAR=0.2
Pod undocumented
103 1 my $hooks = $self->all_hooks;
104 1 push @$hooks, $self->hooks->add(@_);
105 0 return $hooks->[-1];
106 }
107  
108 2 ▶sub remove_hooks {
Subroutine remove_hooks: called CC=2 SCAR=7.6
Pod undocumented
109 2 my $hooks = $self->all_hooks;
110 2 ▶ while (@$hooks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$hooks) 0 2 2
111 0 pop(@$hooks)->unhook;
112 }
113 }
114  
115 7 ▶sub registry_loaded {
Subroutine registry_loaded: called CC=2 SCAR=7.2
Pod undocumented
116 defined $self->{registry} &&
117 7 ▶ defined $self->{registry}{lookup};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"registry"} and defined $self->{"registry"}{"lookup"} 0 7 7
118 }
119  
120 2 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
121 2 $self->remove_hooks;
122 }
123  
124 5 __END__
« Spoon/Trace.pm ↑ Summary Spoon/Command.pm »