| 1 | package Spoon::Registry; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Spoon::Base -Base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | const class_id => 'registry'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | const registry_file => 'registry.dd'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | const registry_directory => '.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | const lookup_class => 'Spoon::Lookup'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | field lookup => | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | -init => '$self->load'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | field 'temp_lookup'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | field 'current_class_id'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub registry_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
registry_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | join '/', $self->registry_directory, $self->registry_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=3 SCAR=14.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my $path = $self->registry_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $lookup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | if (-e $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $lookup = eval io($path)->all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | die "$path seems to be corrupt:\n$@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | $lookup = $self->update->lookup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $self->lookup(bless $lookup, $self->lookup_class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return $self->lookup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $lookup = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $self->temp_lookup($lookup); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $self->set_core_classes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | for my $class_name (@{$self->hub->config->plugin_classes}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $object = $self->load_class($class_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $self->not_a_plugin($class_name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | unless $object->can('register'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $class_id = $self->$set_class_info($object); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $self->current_class_id($class_id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $object->register($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self->transform; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $self->lookup($self->temp_lookup); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub not_a_plugin { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
not_a_plugin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $class_name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | die "$class_name is not a plugin\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | sub load_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_class: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | my $class_name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 4 | ▶ | eval "require $class_name"; die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | $class_name->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub set_core_classes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_core_classes: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my %all = $self->hub->config->all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | my $hub = $self->hub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | for my $key (keys %all) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | ▶ | next unless $key =~ /(.*)_class$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | my $class_id = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | my $class_name = $all{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | $self->temp_lookup->{classes}{$class_id} = $class_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | ▶ | my $object = $hub->can($class_id) && $hub->$class_id || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$hub->can($class_id) && $hub->$class_id || $self->load_class($class_name)
$hub->can($class_id) and $hub->$class_id
MC/DC0%0/3
$hub->can($class_id) && $hub->$class_id || $self->load_class($class_name)
$hub->can($class_id)
$hub->$class_id
$self->load_class($class_name)
Truth table60%3/5
A and B || C
A= $hub->can($class_id)B= $hub->$class_idC= $self->load_class($class_name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | $self->load_class($class_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | $self->add_classes($object); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my sub set_class_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $object = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $lookup = $self->temp_lookup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $class_name = ref $object; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $class_id = $object->class_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | or die "No class_id for $class_name\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if (my $prev_name = $lookup->{classes}{$class_id}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $self->plugin_redefined($class_id, $class_name, $prev_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $lookup->{classes}{$class_id} = $class_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self->add_classes($object); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | push @{$lookup->{plugins}}, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | id => $class_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | title => $object->class_title, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return $class_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 5 | ▶ | sub add_classes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_classes: called CC=3 SCAR=16.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 5 | my $object = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | return unless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | ▶ | $object->can('inline_classes'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $classes = $self->temp_lookup->{classes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | for my $class_name (@{$object->inline_classes}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $object = $class_name->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $classes->{$object->class_id} = $class_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub plugin_redefined {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plugin_redefined: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $class_id = $self->current_class_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($key eq 'hook') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | push @{$self->temp_lookup->{$key}}, [$class_id, @_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->temp_lookup->{$key}{$value} = [ $class_id, @_ ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | push @{$self->temp_lookup->{add_order}{$class_id}{$key}}, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $self->dumper_to_file($self->registry_path, $self->lookup); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub transform { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->transform_hook; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub transform_hook { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform_hook: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $lookup = $self->temp_lookup; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return unless defined $lookup->{hook}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my @hooks = @{$lookup->{hook}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $new_hooks = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | for my $hook (@hooks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my ($class_id, $target, %args) = @$hook; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $class_name = $lookup->{classes}{$class_id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my ($target_class_id, $target_method) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | $target =~ /^(\w+):(\w+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $target_class_name = $lookup->{classes}{$target_class_id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | die "Invalid hook '$target' in class '$class_id'\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | unless $target_class_id and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | $target_class_name and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | ($args{pre} or $args{post}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$target_class_id and $target_class_name and $args{"pre"} || $args{"post"}
$target_class_id and $target_class_name
$args{"pre"} or $args{"post"}
MC/DC0%0/4
$target_class_id and $target_class_name and $args{"pre"} || $args{"post"}
$target_class_id
$target_class_name
$args{"pre"}
$args{"post"}
Truth table0%0/5
A and B and C or D
A= $target_class_idB= $target_class_nameC= $args{"pre"}D= $args{"post"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | push @{$new_hooks->{$target_class_name}}, [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | $target_class_name . '::' .$target_method, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $method = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ($_, $class_name . '::' . $method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } (keys %args), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $self->temp_lookup->{hook} = $new_hooks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | package Spoon::Lookup; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | use Spiffy -base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # XXX consider an AUTOLOAD here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | field action => {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | field add_order => {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | field classes => {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | field plugins => []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | field preference => {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | field preload => {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | field wafl => {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||