| 1 | # vim: ai et sw=4 | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | package Mojolicious::Plugin::YamlConfig; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base 'Mojolicious::Plugin::JSONConfig'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.2.4'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 3 | my ( $self, $app, $conf ) = @_; | |||||||||||||||||||||||||||
| 12 | 3 | ▶ | $conf ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$conf ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||||||||||||||||||
| 13 | 3 | $conf->{ext} = 'yaml'; | |||||||||||||||||||||||||||
| 14 | 3 | ▶ | $conf->{class} ||= $ENV{MOJO_YAML} || 'YAML::Tiny'; | ||||||||||||||||||||||||||
|
Condition40%2/5
$conf->{"class"} ||= $ENV{"MOJO_YAML"} || "YAML::Tiny"
$ENV{'MOJO_YAML'} || 'YAML::Tiny'
MC/DC0%0/2
$conf->{"class"} ||= $ENV{"MOJO_YAML"} || "YAML::Tiny"
$conf->{"class"}
$ENV{'MOJO_YAML'}
Truth table0%0/3
A ||= B
A= $conf->{"class"}B= $ENV{'MOJO_YAML'}
| |||||||||||||||||||||||||||||
| 15 | 3 | $self->{class} = $conf->{class}; | |||||||||||||||||||||||||||
| 16 | 3 | my @supported = qw(YAML YAML::XS YAML::Tiny YAML::Old YAML::PP); | |||||||||||||||||||||||||||
| 17 | 3 | ▶ | unless ( grep { $conf->{class} eq $_ } @supported) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | warn("$conf->{class} is not supported, use at your own risk"); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | 3 | return $self->SUPER::register( $app, $conf ); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=8 SCAR=23.9
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 1 | my ($self, $content, $file, $conf, $app) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | my $class = $self->{class}; | |||||||||||||||||||||||||||
| 27 | 1 | ▶ | eval "require $class; 1" || die($@); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | my ($config,$error); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Render | ||||||||||||||||||||||||||||
| 32 | 1 | $content = $self->render($content, $file, $conf, $app); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | my @broken = qw(YAML YAML::Old YAML::Tiny YAML::PP); | |||||||||||||||||||||||||||
| 35 | 1 | ▶ | unless (grep { $class eq $_ } @broken) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | # they are broken *sigh* | ||||||||||||||||||||||||||||
| 37 | 0 | $content = Encode::encode('UTF-8', $content); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | $config = eval $class.'::Load($content)'; | |||||||||||||||||||||||||||
| 41 | 1 | ▶ | if($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $error = $@; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | die qq/Couldn't parse config "$file": $error/ if !$config && $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $config and $error
MC/DC0%0/2
not $config and $error
not $config
$error
Truth table33%1/3
not(A) and B
A= not $configB= $error
| |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | die qq/Invalid config "$file"./ if !$config || ref $config ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $config or ref $config ne "HASH"
MC/DC0%0/2
not $config or ref $config ne "HASH"
not $config
ref $config ne "HASH"
Truth table33%1/3
not(A) or B
A= not $configB= ref $config ne "HASH"
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | return $config; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | 1; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||||||||||