| 1 | package Miril::Config; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use autodie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use XML::TreePP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Data::AsObject dao => { mode => 'silent' }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Ref::List qw(list); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use File::Spec::Functions qw(catfile catdir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Miril::Topic; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Miril::Type; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 0 | my $miril_dir = shift; | |||||||||||||||||||||||||||
| 17 | 0 | my $site = shift; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | my $tpp = XML::TreePP->new(); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | my $base_dir = catdir($miril_dir, 'sites', $site); | |||||||||||||||||||||||||||
| 22 | 0 | my $filename = catfile($base_dir, 'cfg', 'config.xml'); | |||||||||||||||||||||||||||
| 23 | 0 | my $tree = $tpp->parsefile($filename); | |||||||||||||||||||||||||||
| 24 | 0 | my $cfg = $tree->{'xml'}; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | ### SUPPLY DEFAULT VALUES ### | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $cfg->{store} = 'File' unless defined $cfg->{store}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | $cfg->{user_manager} = 'XMLTPP' unless defined $cfg->{user_manager}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $cfg->{filter} = 'Markdown' unless defined $cfg->{filter}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $cfg->{template} = 'HTML::Template' unless defined $cfg->{template}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $cfg->{posts_per_page} = 10 unless defined $cfg->{posts_per_page}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | $cfg->{cache_data} = catfile($base_dir, 'cache', 'cache.xml' ); | |||||||||||||||||||||||||||
| 36 | 0 | $cfg->{latest_data} = catfile($base_dir, 'cache', 'latest.xml'); | |||||||||||||||||||||||||||
| 37 | 0 | $cfg->{users_data} = catfile($base_dir, 'cfg', 'users.xml' ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | $cfg->{data_path} = catdir($base_dir, 'data'); | |||||||||||||||||||||||||||
| 40 | 0 | $cfg->{tmpl_path} = catdir($base_dir, 'tmpl'); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | $cfg->{statuses} = [qw(draft published)]; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $cfg->{sort} = 'published' if !$cfg->{sort} || $cfg->{sort} ne 'modified'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $cfg->{"sort"} or $cfg->{"sort"} ne "modified"
MC/DC0%0/2
not $cfg->{"sort"} or $cfg->{"sort"} ne "modified"
not $cfg->{"sort"}
$cfg->{"sort"} ne "modified"
Truth table0%0/3
not(A) or B
A= not $cfg->{"sort"}B= $cfg->{"sort"} ne "modified"
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | my @topics = map { | ||||||||||||||||||||||||||||
| 47 | Miril::Topic->new( | ||||||||||||||||||||||||||||
| 48 | id => $_->{id}, | ||||||||||||||||||||||||||||
| 49 | name => $_->{name}, | ||||||||||||||||||||||||||||
| 50 | ) | ||||||||||||||||||||||||||||
| 51 | 0 | } list $cfg->{topics}{topic}; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | my @types = map { | ||||||||||||||||||||||||||||
| 54 | Miril::Type->new( | ||||||||||||||||||||||||||||
| 55 | id => $_->{id}, | ||||||||||||||||||||||||||||
| 56 | name => $_->{name}, | ||||||||||||||||||||||||||||
| 57 | location => $_->{location}, | ||||||||||||||||||||||||||||
| 58 | template => $_->{template}, | ||||||||||||||||||||||||||||
| 59 | ) | ||||||||||||||||||||||||||||
| 60 | 0 | } list $cfg->{types}{type}; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | ### SIMPLIFY THE HASHREF ### | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $cfg->{authors} = $cfg->{authors}{author} ? $cfg->{authors}{author} : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | $cfg->{topics} = \@topics; | |||||||||||||||||||||||||||
| 66 | 0 | $cfg->{types} = \@types; | |||||||||||||||||||||||||||
| 67 | 0 | $cfg->{lists} = $cfg->{lists}{list}; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | ### ADD BASE DIR INFO ### | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | $cfg->{base_dir} = $cfg->{domain} . $cfg->{http_dir}; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | return dao $cfg; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||||||||||