lib/Rapi/Blog/Scaffold/Config.pm

filter: Statementstmt 45.5% 36 / 79 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 26.9% 7 / 26 Podpod 0.0% 0 / 1 totaltotal 34.1% 43 / 126 CC 10 SCAR 22.7
CC
10
Cov
38%
_apply_params
42.0
_load_from_yaml
12.0
__ANON__
6.0
CRAP 9.7
« lib/Rapi/Blog/DB/Result/Category.pm ↑ Summary lib/Rapi/Blog/Util/Mailer.pm »
1 package Rapi::Blog::Scaffold::Config;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 2 ▶use RapidApp::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Rapi::Blog::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Types::Standard ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 2 ▶use YAML::XS 0.64 'LoadFile';
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13 0 ▶has 'favicon', is => 'rw', isa => Maybe[Str], default => sub { 'favicon.ico' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
14 0 ▶has 'landing_page', is => 'rw', isa => Maybe[Str], default => sub { 'index.html' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
15 0 ▶has 'internal_post_path', is => 'rw', isa => Maybe[Str], default => sub { 'private/post/' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
16 0 ▶has 'default_view_path', is => 'rw', isa => Maybe[Str], default => sub { 'post/' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
17 0 ▶has 'not_found', is => 'rw', isa => Maybe[Str], default => sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=1.2
18 0 ▶has 'view_wrappers', is => 'rw', isa => ArrayRef[HashRef], default => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
19 0 ▶has 'static_paths', is => 'rw', isa => ArrayRef, default => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
20 0 ▶has 'template_names', is => 'rw', isa => ArrayRef, default => sub { ['*'] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
21 0 ▶has 'private_paths', is => 'rw', isa => ArrayRef, default => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
22 0 ▶has 'default_ext', is => 'rw', isa => Maybe[Str], default => sub { 'html' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
23
24 0 ▶has 'preview_path', is => 'rw', lazy => 1, default => sub { (shift)->default_view_path }, isa => Maybe[Str];
Subroutine __ANON__: not called CC=1 SCAR=1.2
25
26
27 2 has '_supplied_params', is => 'ro', isa => HashRef, required => 1;
28 0 ▶around BUILDARGS => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
29 0 my $orig = shift;
30 0 my $class = shift;
31 0 ▶ my %params = (ref($_[0]) eq 'HASH') ? %{ $_[0] } : @_; # <-- arg as hash or hashref
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
32
33 0 $params{_supplied_params} = { %params };
34 0 $class->$orig(%params)
35 2 };
36
37
38 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
39 0 my $self = shift;
40 0 $self->_apply_params( $self->_supplied_params )
41 }
42
43
44 0 ▶has '_extra_params', is => 'rw', isa => HashRef, default => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
45 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
46 0 my $self = shift;
47 0 my $meth = (reverse(split('::',our $AUTOLOAD)))[0];
48 0 $self->_extra_params->{$meth}
49 }
50
51
52 0 ▶sub _load_from_yaml {
Subroutine _load_from_yaml: not called CC=3 SCAR=24.8
53 0 my $self = shift;
54 0 ▶ my $yaml_file = shift or die "Missing required yaml_file argument";
Branch: 1 branch
BranchTrueFalseTotal
my $yaml_file = shift() or die "Missing required yaml_file argument" 0 0 0
55 0 ▶ -e $yaml_file or die "YAML file '$yaml_file' not found";
Branch: 1 branch
BranchTrueFalseTotal
-e $yaml_file or die "YAML file '${yaml_file}' not found" 0 0 0
56
57 0 my $data = LoadFile( $yaml_file );
58
59 0 $self->_apply_params( $data, 1 );
60
61 #for (keys %$data) {
62 # if ($self->_supplied_params->{$_}) { # Don't override any user-supplied params
63 # delete $data->{$_}
64 # }
65 # elsif ($self->can($_)) {
66 # $self->$_( delete $data->{$_} )
67 # }
68 #}
69 #
70 ## Save leftover params so they can still be accessed via AUTOLOAD
71 #$self->_extra_params( $data );
72
73 }
74
75
76
77 0 ▶sub _apply_params {
Subroutine _apply_params: not called CC=6 SCAR=37.4
78 0 my ($self, $new_params, $no_ovr) = @_;
79
80 0 my $params = clone( $new_params );
81
82 0 for (keys %$params) {
83 0 ▶ if ($no_ovr && $self->_supplied_params->{$_}) { # Don't override any user-supplied params
Branch: 2 branches
BranchTrueFalseTotal
if ($no_ovr and $self->_supplied_params->{$_}) { } 0 0 0
elsif ($self->can($_)) { } 0 0 0
Condition0%0/3
$no_ovr and $self->_supplied_params->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$no_ovr and $self->_supplied_params->{$_}
$no_ovr $self->_supplied_params->{$_}
Truth table0%0/3
A and B
A= $no_ovrB= $self->_supplied_params->{$_}
ABresult
0X0
100
111
84 0 delete $params->{$_}
85 }
86 elsif ($self->can($_)) {
87 0 $self->$_( delete $params->{$_} )
88 }
89 }
90
91 # Save leftover params so they can still be accessed via AUTOLOAD
92 0 ▶ my $extra = $self->_extra_params || {};
Condition0%0/2
$self->_extra_params || {}
l!l
00
MC/DC0%0/1
$self->_extra_params || {}
$self->_extra_params
Truth table0%0/2
A
A= $self->_extra_params
Aresult
11
00
93 0 $self->_extra_params( { %$extra, %$params } );
94 }
95
96
97
98 0 ▶sub _has_param {
Subroutine _has_param: not called CC=2 SCAR=17.9
99 0 my ($self, $p) = @_;
100 0 ▶ $self->can($p) || exists $self->_extra_params->{$p}
Branch: 1 branch
BranchTrueFalseTotal
$self->can($p) or exists $self->_extra_params->{$p} 0 0 0
101 }
102
103
104
105 0 ▶sub _all_as_hash {
Subroutine _all_as_hash: not called CC=1 SCAR=6.9
106 0 my $self = shift;
107
108 return {
109 0 map { $_ => $self->$_ }
110 0 grep { ! /^_/ } # exclude "private" attributes with start with underscore '_'
111 0 keys %{ $self->_extra_params },
112 $self->meta->get_attribute_list
113 }
114 }
115
116
117 2 1;
« lib/Rapi/Blog/DB/Result/Category.pm ↑ Summary lib/Rapi/Blog/Util/Mailer.pm »