| 1 | package Bootylicious::Plugin::BootyConfig; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use base 'Mojolicious::Plugin'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 2 | ▶ | use Mojolicious::Controller; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | sub register { | ||||||||||||
| 11 | 2 | ▶ | my ($self, $app, $conf) = @_; | ||||||||||
|
Subroutine
register: called CC=7 SCAR=37.4
Pod
documented
| |||||||||||||
| 12 | |||||||||||||
| 13 | 2 | my $c = Mojolicious::Controller->new(app => $app); | |||||||||||
| 14 | |||||||||||||
| 15 | 2 | ▶ | $conf ||= {}; | ||||||||||
|
Condition50%1/2
$conf ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||
| 16 | |||||||||||||
| 17 | 2 | $app->log->level('error'); | |||||||||||
| 18 | |||||||||||||
| 19 | # Default plugins | ||||||||||||
| 20 | 2 | $app->plugin('charset' => {charset => 'utf-8'}); | |||||||||||
| 21 | 0 | $app->plugin('PODRenderer', {no_perldoc => 1}); | |||||||||||
| 22 | 0 | $app->plugin('TagHelpers'); | |||||||||||
| 23 | 0 | $app->plugin( | |||||||||||
| 24 | validator => { | ||||||||||||
| 25 | messages => { | ||||||||||||
| 26 | REQUIRED => 'Required', | ||||||||||||
| 27 | EMAIL_CONSTRAINT_FAILED => "Doesn't look like an email to me", | ||||||||||||
| 28 | URL_CONSTRAINT_FAILED => "Doesn't look like an url to me" | ||||||||||||
| 29 | } | ||||||||||||
| 30 | } | ||||||||||||
| 31 | ); | ||||||||||||
| 32 | |||||||||||||
| 33 | 0 | ▶ | $conf->{default} = $self->_default unless exists $conf->{default}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 0 | my $config = $app->plugin('JSONConfig' => $conf); | |||||||||||
| 35 | |||||||||||||
| 36 | 0 | $app->secrets([$config->{secret}]); | |||||||||||
| 37 | |||||||||||||
| 38 | # Config access | ||||||||||||
| 39 | $app->helper( | ||||||||||||
| 40 | config => sub { | ||||||||||||
| 41 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 42 | |||||||||||||
| 43 | 0 | ▶ | if (@_) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | ▶ | return $config->{$_[0]} if @_ == 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | |||||||||||||
| 46 | 0 | $config = {%$config, @_}; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 0 | return $config; | |||||||||||
| 50 | } | ||||||||||||
| 51 | 0 | ); | |||||||||||
| 52 | |||||||||||||
| 53 | # Set appropriate log level | ||||||||||||
| 54 | 0 | $app->log->level($config->{loglevel}); | |||||||||||
| 55 | |||||||||||||
| 56 | # Additional Perl modules | ||||||||||||
| 57 | 0 | $self->_setup_inc($config->{perl5lib}); | |||||||||||
| 58 | |||||||||||||
| 59 | # CGI hack | ||||||||||||
| 60 | 0 | ▶ | $ENV{SCRIPT_NAME} = $config->{base} if defined $config->{base}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | |||||||||||||
| 62 | # Don't use set locale unless it is explicitly specified via a config file | ||||||||||||
| 63 | 0 | $ENV{LC_ALL} = 'C'; | |||||||||||
| 64 | |||||||||||||
| 65 | # set proper templates base dir, if defined | ||||||||||||
| 66 | 0 | push @{$app->renderer->paths}, $app->home->rel_dir($config->{templates_directory}) | |||||||||||
| 67 | 0 | ▶ | if defined $config->{templates_directory}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | # set proper public base dir, if defined | ||||||||||||
| 70 | 0 | push @{$app->static->paths}, $app->home->rel_dir($config->{public_directory}) | |||||||||||
| 71 | 0 | ▶ | if defined $config->{public_directory}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | |||||||||||||
| 73 | 0 | $app->defaults(title => '', description => '', layout => 'wrapper'); | |||||||||||
| 74 | |||||||||||||
| 75 | # Parser helpers | ||||||||||||
| 76 | 0 | ▶ | $app->helper(parsers => sub { $config->{_parsers} }); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 77 | |||||||||||||
| 78 | $app->helper( | ||||||||||||
| 79 | add_parser => sub { | ||||||||||||
| 80 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 81 | 0 | my ($ext, $cb) = @_; | |||||||||||
| 82 | |||||||||||||
| 83 | 0 | $config->{_parsers}->{$ext} = $cb; | |||||||||||
| 84 | } | ||||||||||||
| 85 | 0 | ); | |||||||||||
| 86 | |||||||||||||
| 87 | 0 | $app->plugin('booty_helpers'); | |||||||||||
| 88 | |||||||||||||
| 89 | $c->add_parser( | ||||||||||||
| 90 | 0 | ▶ | pod => sub { $app->renderer->helpers->{pod_to_html}->(undef, @_) }); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 91 | |||||||||||||
| 92 | 0 | ▶ | if (my $theme = $config->{theme}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 93 | 0 | my $theme_class = join '::' => 'Bootylicious::Theme', | |||||||||||
| 94 | Mojo::ByteStream->new($theme)->camelize; | ||||||||||||
| 95 | |||||||||||||
| 96 | 0 | $app->renderer->classes([$theme_class]); | |||||||||||
| 97 | 0 | $app->static->classes([$theme_class]); | |||||||||||
| 98 | |||||||||||||
| 99 | 0 | $app->plugin($theme_class); | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | # Load additional plugins | ||||||||||||
| 103 | 0 | $self->_load_plugins($app, $config->{plugins}); | |||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | sub _setup_inc { | ||||||||||||
| 107 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_setup_inc: not called CC=4 SCAR=30.0
| |||||||||||||
| 108 | 0 | my $perl5lib = shift; | |||||||||||
| 109 | |||||||||||||
| 110 | 0 | ▶ | return unless $perl5lib; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | |||||||||||||
| 112 | 0 | ▶ | push @INC, $_ for (ref $perl5lib eq 'ARRAY' ? @{$perl5lib} : $perl5lib); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 113 | } | ||||||||||||
| 114 | |||||||||||||
| 115 | sub _load_plugins { | ||||||||||||
| 116 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_load_plugins: not called CC=7 SCAR=40.3
| |||||||||||||
| 117 | 0 | my ($app, $plugins_arrayref) = @_; | |||||||||||
| 118 | |||||||||||||
| 119 | 0 | ▶ | return unless $plugins_arrayref; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 120 | 0 | ▶ | $plugins_arrayref = [$plugins_arrayref] | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 121 | unless ref $plugins_arrayref eq 'ARRAY'; | ||||||||||||
| 122 | |||||||||||||
| 123 | 0 | my @plugins; | |||||||||||
| 124 | |||||||||||||
| 125 | my $prev; | ||||||||||||
| 126 | 0 | ▶ | while (my $plugin = shift @{$plugins_arrayref}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 127 | 0 | ▶ | if (ref($plugin) eq 'HASH') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 128 | 0 | ▶ | next unless $plugins[-1]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 129 | |||||||||||||
| 130 | 0 | $plugins[-1]->{args} = $plugin; | |||||||||||
| 131 | } | ||||||||||||
| 132 | else { | ||||||||||||
| 133 | 0 | push @plugins, {name => $plugin, args => {}}; | |||||||||||
| 134 | } | ||||||||||||
| 135 | } | ||||||||||||
| 136 | |||||||||||||
| 137 | 0 | foreach my $plugin (@plugins) { | |||||||||||
| 138 | 0 | $app->plugin($plugin->{name} => $plugin->{args}); | |||||||||||
| 139 | } | ||||||||||||
| 140 | } | ||||||||||||
| 141 | |||||||||||||
| 142 | sub _default { | ||||||||||||
| 143 | 0 | ▶ | { author => 'whoami', | ||||||||||
|
Subroutine
_default: not called CC=1 SCAR=6.9
| |||||||||||||
| 144 | email => '', | ||||||||||||
| 145 | title => 'Just another blog', | ||||||||||||
| 146 | about => 'Perl hacker', | ||||||||||||
| 147 | description => 'I do not know if I need this', | ||||||||||||
| 148 | |||||||||||||
| 149 | cuttag => '[cut]', | ||||||||||||
| 150 | cuttext => 'Keep reading', | ||||||||||||
| 151 | pagelimit => 10, | ||||||||||||
| 152 | datefmt => '%a, %d %b %Y', | ||||||||||||
| 153 | |||||||||||||
| 154 | menu => [ | ||||||||||||
| 155 | index => '/', | ||||||||||||
| 156 | tags => '/tags.html', | ||||||||||||
| 157 | archive => '/articles.html' | ||||||||||||
| 158 | ], | ||||||||||||
| 159 | footer => | ||||||||||||
| 160 | 'Powered by <a href="https://github.com/vti/bootylicious">Bootylicious</a>', | ||||||||||||
| 161 | theme => '', | ||||||||||||
| 162 | |||||||||||||
| 163 | comments_enabled => 1, | ||||||||||||
| 164 | rss_enabled => 1, | ||||||||||||
| 165 | |||||||||||||
| 166 | meta => [], | ||||||||||||
| 167 | css => [], | ||||||||||||
| 168 | js => [], | ||||||||||||
| 169 | |||||||||||||
| 170 | strings => { | ||||||||||||
| 171 | 'archive' => 'Archive', | ||||||||||||
| 172 | 'archive-description' => 'Articles index', | ||||||||||||
| 173 | 'tags' => 'Tags', | ||||||||||||
| 174 | 'tags-description' => 'Tags overview', | ||||||||||||
| 175 | 'tag' => 'Tag', | ||||||||||||
| 176 | 'tag-description' => 'Articles with tag [_1]', | ||||||||||||
| 177 | 'draft' => 'Draft', | ||||||||||||
| 178 | 'permalink-to' => 'Permalink to', | ||||||||||||
| 179 | 'later' => 'Later', | ||||||||||||
| 180 | 'earlier' => 'Earlier', | ||||||||||||
| 181 | 'not-found' => 'The page you are looking for was not found', | ||||||||||||
| 182 | 'error' => 'Internal error occurred :(' | ||||||||||||
| 183 | }, | ||||||||||||
| 184 | template_handler => 'ep', | ||||||||||||
| 185 | |||||||||||||
| 186 | perl5lib => '', | ||||||||||||
| 187 | loglevel => 'error', | ||||||||||||
| 188 | |||||||||||||
| 189 | articles_directory => 'articles', | ||||||||||||
| 190 | pages_directory => 'pages', | ||||||||||||
| 191 | drafts_directory => 'drafts', | ||||||||||||
| 192 | public_directory => 'public', | ||||||||||||
| 193 | templates_directory => 'templates', | ||||||||||||
| 194 | }; | ||||||||||||
| 195 | } | ||||||||||||
| 196 | |||||||||||||
| 197 | 2 | 1; | |||||||||||