| 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
| |||||||||||||||||||||||||||||
| 20 | or die "Can't AUTOLOAD '$AUTOLOAD'"; | ||||||||||||||||||||||||||||
| 21 | 13 | my $class_id = $1; | |||||||||||||||||||||||||||
| 22 | 13 | ▶ | return if $class_id eq 'DESTROY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 36 | my ($class_id, $method) = | ||||||||||||||||||||||||||||
| 37 | 0 | @{$self->registry->lookup->action->{$action}}; | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | $method ||= $action; | ||||||||||||||||||||||||||
|
Condition0%0/3
$method ||= $action
MC/DC0%0/2
$method ||= $action
$method
$action
Truth table0%0/3
A ||= B
A= $methodB= $action
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$hash{'priority'} || 0
$hash{'priority'}
Truth table0%0/2
A
A= $hash{'priority'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 58 | return $self->$class_id | ||||||||||||||||||||||||||||
| 59 | 9 | ▶ | if $self->can($class_id) and defined $self->{$class_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->can($class_id) and defined $self->{$class_id}
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}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 70 | unless $class_name; | ||||||||||||||||||||||||||||
| 71 | 9 | ▶ | unless ($class_name->can('new')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 8 | eval "require $class_name"; | |||||||||||||||||||||||||||
| 73 | 8 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | $self->add_hooks | ||||||||||||||||||||||||||||
| 76 | 7 | ▶ | unless $class_id eq 'hooks'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 7 | ▶ | my $object = $class_name->new | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 80 | 7 | ▶ | die "No class_id defined for class: '$class_name'\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 91 | my $hooks = $self->registry->lookup->{hook} | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | for my $class_name (keys %$hooks) { | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | next unless $class_name->can('new'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $self->add_hook(@$_) for @{$hooks->{$class_name} || []}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$hooks->{$class_name} || []
MC/DC0%0/1
$hooks->{$class_name} || []
$hooks->{$class_name}
Truth table0%0/2
A
A= $hooks->{$class_name}
| |||||||||||||||||||||||||||||
| 96 | 0 | delete $hooks->{$class_name}; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | delete $self->registry->lookup->{hook} | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if not keys %$hooks; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 121 | 2 | $self->remove_hooks; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 5 | __END__ | |||||||||||||||||||||||||||