lib/Kwiki/Config.pm

filter: Statementstmt 45.7% 43 / 94 Branchbran 15.3% 4 / 26 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 10 / 15 Podpod 18.1% 2 / 11 totaltotal 36.6% 59 / 161 CC 21 SCAR 29.5
CC
21
Cov
36%
read_plugins
56.0
change_plugin
20.0
get_packed_files
20.0
CRAP 19.1
« lib/Kwiki/Theme.pm ↑ Summary lib/Kwiki/Edit.pm »
1 package Kwiki::Config;
2 7 ▶use Spoon::Config -Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use mixin 'Kwiki::Installer';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 const class_id => 'config';
6 7 const class_title => 'Kwiki Configuration';
7 7 const config_file => 'config.yaml';
8 7 field script_name => '';
9 7 const default_path => [ 'config' ];
10 7 field path => [];
11 7 field plugins_file => '';
12  
13 9 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
14 9 $self->add_path(@{$self->default_path});
15 9 $self->add_file($self->config_file);
16 }
17  
18 9 ▶sub paired_arguments { qw(-plugins) }
Subroutine paired_arguments: called CC=1 SCAR=0.0
Pod documented
19 9 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod undocumented
20 9 my ($args, @configs) = $self->parse_arguments(@_);
21 9 $self = super(@configs);
22 9 ▶ if (my $plugins_file = $args->{-plugins}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $plugins_file = $args->{"-plugins"}) 0 9 9
23 0 $self->add_plugins_file($plugins_file);
24 0 $self->plugins_file($plugins_file);
25 }
26 9 return $self;
27 }
28  
29 0 ▶sub add_plugins_file {
Subroutine add_plugins_file: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my $plugins_file = shift;
31 0 ▶ return unless -f $plugins_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $plugins_file 0 0 0
32 0 $self->add_config(
33 {
34 plugin_classes => [ $self->read_plugins($plugins_file) ],
35 }
36 );
37 }
38  
39 0 ▶sub read_plugins {
Subroutine read_plugins: not called CC=7 SCAR=40.3
Pod undocumented
40 0 my $plugins_file = io(shift);
41 my @plugins = grep {
42 0 s/^([\+\-]?[\w\:]+)\s*$/$1/;
43 } $plugins_file->slurp;
44 0 ▶ return @plugins unless grep /^[\+\-]/, @plugins or not @plugins;
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^[\+\-]/, @plugins or not @plugins 0 0 0
Condition0%0/3
grep /^[\+\-]/, @plugins or not @plugins
l!l&&r!l&&!r
000
MC/DC0%0/2
grep /^[\+\-]/, @plugins or not @plugins
grep /^[\+\-]/, @plugins not @plugins
Truth table0%0/3
A or not(B)
A= grep /^[\+\-]/, @pluginsB= not @plugins
ABresult
1X1
011
000
45 0 my $filename = $plugins_file->filename;
46 0 ▶ die "Can't create plugins list"
Branch: 1 branch
BranchTrueFalseTotal
unless -e "../$filename" 0 0 0
47 unless -e "../$filename";
48 0 my $updir = io->updir->chdir;
49 0 my @parent_plugins = $self->read_plugins($filename);
50 0 for (@plugins) {
51 0 my $remove = $_;
52 0 ▶ $remove =~ s/^\-// or next;
Branch: 1 branch
BranchTrueFalseTotal
$remove =~ s/^\-// or next 0 0 0
53 0 @parent_plugins = grep {$_ ne $remove} @parent_plugins;
54 }
55 0 my %have;
56 0 @have{@parent_plugins} = ('1') x @parent_plugins;
57 return @parent_plugins, grep {
58 0 ▶ not /^\-/ and do {
Condition0%0/3
!/^\-/ && do { s/^\+//; not $have{$_} }
!ll&&!rl&&r
000
MC/DC0%0/2
!/^\-/ && do { s/^\+//; not $have{$_} }
!/^\-/ do { s/^\+//; not $have{$_} }
Truth table0%0/3
not(A) && B
A= !/^\-/B= do { s/^\+//; not $have{$_} }
ABresult
0X0
100
111
59 0 s/^\+//;
60 0 not $have{$_};
61 }
62 } @plugins;
63 }
64  
65 9 ▶sub default_classes {
Subroutine default_classes: called CC=1 SCAR=0.0
Pod undocumented
66 (
67 9 cgi_class => 'Kwiki::CGI',
68 command_class => 'Kwiki::Command',
69 config_class => 'Kwiki::Config',
70 cookie_class => 'Kwiki::Cookie',
71 css_class => 'Kwiki::CSS',
72 files_class => 'Kwiki::Files',
73 formatter_class => 'Kwiki::Formatter',
74 headers_class => 'Spoon::Headers',
75 hooks_class => 'Spoon::Hooks',
76 hub_class => 'Kwiki::Hub',
77 javascript_class => 'Kwiki::Javascript',
78 pages_class => 'Kwiki::Pages',
79 preferences_class => 'Kwiki::Preferences',
80 registry_class => 'Kwiki::Registry',
81 template_class => 'Kwiki::Template::TT2',
82 users_class => 'Kwiki::Users',
83 )
84 }
85  
86 0 ▶sub add_plugin {
Subroutine add_plugin: not called CC=1 SCAR=6.9
Pod undocumented
87 0 push @{$self->plugin_classes}, shift;
88 }
89  
90 0 ▶sub change_plugin {
Subroutine change_plugin: not called CC=4 SCAR=30.0
Pod undocumented
91 0 my ($new_class, $old_class) = @_;
92 0 ▶ my $pattern = $old_class || do {
Condition0%0/3
$old_class || do { my $temp = $new_class; $temp =~ s/^\w+:://; '\\w+::' . $temp }
l!l&&r!l&&!r
000
MC/DC0%0/2
$old_class || do { my $temp = $new_class; $temp =~ s/^\w+:://; '\\w+::' . $temp }
$old_class do { my $temp = $new_class; $temp =~ s/^\w+:://; '\\w+::' . $temp }
Truth table0%0/3
A || B
A= $old_classB= do { my $temp = $new_class; $temp =~ s/^\w+:://; '\\w+::' . $temp }
ABresult
1X1
011
000
93 0 my $temp = $new_class;
94 0 $temp =~ s/^\w+:://;
95 0 '\w+::' . $temp;
96 };
97 0 my $plugins = $self->plugin_classes;
98 0 for (@$plugins) {
99 0 ▶ last if s/$pattern/$new_class/;
Branch: 1 branch
BranchTrueFalseTotal
if s/$pattern/$new_class/ 0 0 0
100 }
101 }
102  
103 9 ▶sub add_file {
Subroutine add_file: called CC=7 SCAR=25.7
Pod undocumented
104 9 ▶ my $file = shift
Branch: 1 branch
BranchTrueFalseTotal
my $file = shift() or return 9 0 9
105 or return;
106 9 my $file_path = '';
107 9 for (@{$self->path}) {
108 9 ▶ $file_path = "$_/$file", last
Branch: 1 branch
BranchTrueFalseTotal
if -f "$_/$file" 0 9 9
109 if -f "$_/$file";
110 }
111 9 ▶ return unless $file_path;
Branch: 1 branch
BranchTrueFalseTotal
unless $file_path 9 0 9
112 0 my $hash = $self->hash_from_file($file_path);
113 0 for my $key (keys %$hash) {
114 0 ▶ next if defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$key} 0 0 0
115 0 field $key;
116 0 $self->{$key} = $hash->{$key};
117 }
118 }
119  
120 9 ▶sub add_path {
Subroutine add_path: called CC=1 SCAR=0.0
Pod undocumented
121 9 splice @{$self->path}, 0, 0, @_;
122 }
123  
124 0 ▶sub get_packed_files {
Subroutine get_packed_files: not called CC=4 SCAR=30.0
Pod undocumented
125 0 my @return;
126 0 my @packed = super;
127 0 ▶ while (my ($name, $content) = splice(@packed, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@packed, 0, 2)) 0 0 0
128 0 ▶ if ($name =~ /^(plugins|config\.yaml)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(plugins|config\.yaml)$/) 0 0 0
129 0 ▶ next if -f $name;
Branch: 1 branch
BranchTrueFalseTotal
if -f $name 0 0 0
130 }
131 0 push @return, $name, $content;
132 }
133 0 @return;
134 }
135  
136 7 __DATA__
« lib/Kwiki/Theme.pm ↑ Summary lib/Kwiki/Edit.pm »