| 1 | package Spoon::Config; | ||||||||||||||||||||
| 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 => 'config'; | |||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | sub all { | ||||||||||||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 7 | 2 | return %$self; | |||||||||||||||||||
| 8 | } | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | ▶ | sub default_configs { return } | ||||||||||||||||||
|
Subroutine
default_configs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 6 | ▶ | sub new() { | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 13 | 6 | my $class = shift; | |||||||||||||||||||
| 14 | 6 | my $self = bless {}, $class; | |||||||||||||||||||
| 15 | my (@configs) = map { | ||||||||||||||||||||
| 16 | 6 | ▶ | /\*/ ? (sort glob) : ($_) | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 2 branches
| |||||||||||||||||||||
| 17 | } @_ ? @_ : $self->default_configs; | ||||||||||||||||||||
| 18 | 6 | $self->add_config($self->default_config, 1); | |||||||||||||||||||
| 19 | 6 | for my $config (@configs) { | |||||||||||||||||||
| 20 | 3 | $self->rebless($self->add_config($config)); | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | 6 | $self->init; | |||||||||||||||||||
| 23 | 6 | return $self; | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | sub add_field { | ||||||||||||||||||
|
Subroutine
add_field: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 27 | 0 | my ($field, $default) = @_; | |||||||||||||||||||
| 28 | 0 | field $field => $default; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 9 | ▶ | sub add_config { | ||||||||||||||||||
|
Subroutine
add_config: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 32 | 9 | my $config = shift; | |||||||||||||||||||
| 33 | 9 | ▶ | my $hash = ref $config | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | ? $config | ||||||||||||||||||||
| 35 | : $self->hash_from_file($config); | ||||||||||||||||||||
| 36 | 9 | for my $key (keys %$hash) { | |||||||||||||||||||
| 37 | 67 | field $key; | |||||||||||||||||||
| 38 | 67 | $self->{$key} = $hash->{$key}; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | 9 | return $hash; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 3 | ▶ | sub rebless { | ||||||||||||||||||
|
Subroutine
rebless: called CC=3 SCAR=16.0
Pod
undocumented
| |||||||||||||||||||||
| 44 | 3 | my $hash = shift; | |||||||||||||||||||
| 45 | 3 | ▶ | if (defined (my $config_class = $hash->{config_class})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | ▶ | eval qq{ require $config_class }; die $@ if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | bless $self, $config_class; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | sub hash_from_file { | ||||||||||||||||||
|
Subroutine
hash_from_file: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 52 | 0 | my $config = shift; | |||||||||||||||||||
| 53 | 0 | ▶ | die "Invalid name for config file '$config'\n" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | unless $config =~ /\.(\w+)$/; | ||||||||||||||||||||
| 55 | 0 | my $extension = lc("$1"); # quotes fix 5.8.0 perl bug | |||||||||||||||||||
| 56 | 0 | my $method = "parse_${extension}_file"; | |||||||||||||||||||
| 57 | 0 | ▶ | -f $config ? $self->$method($config) : {}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | sub parse_file { | ||||||||||||||||||
|
Subroutine
parse_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 61 | 0 | $self->parse_yaml_file(@_); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ▶ | sub parse_yaml_file { | ||||||||||||||||||
|
Subroutine
parse_yaml_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 65 | 0 | my $file = shift; | |||||||||||||||||||
| 66 | 0 | $self->parse_yaml(io($file)->utf8->all); | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | ▶ | sub parse_yaml { | ||||||||||||||||||
|
Subroutine
parse_yaml: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 70 | 0 | my $yaml = shift; | |||||||||||||||||||
| 71 | 0 | my $hash = {}; | |||||||||||||||||||
| 72 | 0 | my $latest_key = ''; | |||||||||||||||||||
| 73 | 0 | for (split /\n/, $yaml) { | |||||||||||||||||||
| 74 | 0 | ▶ | next if (/^#/); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 0 | ▶ | if (/^-\s*(.*)$/) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 76 | 0 | ▶ | $hash->{$latest_key} = [] unless ref $hash->{$latest_key}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 0 | push @{$hash->{$latest_key}}, $1; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | ▶ | elsif (/(.*?)\s*:\s+(.*?)\s*$/ or /(.*?):()\s*$/) { | |||||||||||||||||||
|
Condition0%0/3
/(.*?)\s*:\s+(.*?)\s*$/ or /(.*?):()\s*$/
MC/DC0%0/2
/(.*?)\s*:\s+(.*?)\s*$/ or /(.*?):()\s*$/
/(.*?)\s*:\s+(.*?)\s*$/
/(.*?):()\s*$/
Truth table0%0/3
A or B
A= /(.*?)\s*:\s+(.*?)\s*$/B= /(.*?):()\s*$/
| |||||||||||||||||||||
| 80 | 0 | $hash->{$1} = $2; | |||||||||||||||||||
| 81 | 0 | $latest_key = $1; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | 0 | return $hash; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 6 | ▶ | sub default_config { | ||||||||||||||||||
|
Subroutine
default_config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 88 | +{ | ||||||||||||||||||||
| 89 | 6 | $self->default_classes, | |||||||||||||||||||
| 90 | plugin_classes => [$self->default_plugin_classes], | ||||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 6 | ▶ | sub default_classes { | ||||||||||||||||||
|
Subroutine
default_classes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 95 | ( | ||||||||||||||||||||
| 96 | 6 | cgi_class => 'Spoon::CGI', | |||||||||||||||||||
| 97 | config_class => 'Spoon::Config', | ||||||||||||||||||||
| 98 | formatter_class => 'Spoon::Formatter', | ||||||||||||||||||||
| 99 | headers_class => 'Spoon::Headers', | ||||||||||||||||||||
| 100 | hooks_class => 'Spoon::Hooks', | ||||||||||||||||||||
| 101 | hub_class => 'Spoon::Hub', | ||||||||||||||||||||
| 102 | main_class => 'Spoon', | ||||||||||||||||||||
| 103 | registry_class => 'Spoon::Registry', | ||||||||||||||||||||
| 104 | template_class => 'Spoon::Template', | ||||||||||||||||||||
| 105 | ) | ||||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 6 | ▶ | sub default_plugin_classes { () } | ||||||||||||||||||
|
Subroutine
default_plugin_classes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 5 | __END__ | |||||||||||||||||||