blib/lib/Kubernetes/Comb/Role/Static.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 53 / 53 CC 7 SCAR 13.9
CC
7
Cov
100%
_load_manifest_file
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« blib/lib/Kubernetes/Comb/Upstream/K8s.pm ↑ Summary blib/lib/Kubernetes/Comb/Endpoint.pm »
1 package Kubernetes::Comb::Role::Static;
2 # ABSTRACT: Comb manifests loaded from .pk8s and YAML files
3 2 our $VERSION = '0.002';
4  
5 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 requires qw( io_k8s manifest_files );
12  
13  
14 2 has _static_manifests => (
15 is => 'lazy',
16 init_arg => undef
17 );
18  
19 24 ▶sub _build__static_manifests {
Subroutine _build__static_manifests: called CC=1 SCAR=0.0
20 24 my ( $self ) = @_;
21 24 return [ map { $self->_load_manifest_file($_) } $self->manifest_files ];
22 }
23  
24 29 ▶sub manifests { @{ shift->_static_manifests } }
Subroutine manifests: called CC=1 SCAR=0.0
Pod documented
25  
26  
27 1 ▶sub manifest_dir { return }
Subroutine manifest_dir: called CC=1 SCAR=0.0
Pod documented
28  
29  
30 36 ▶sub _load_manifest_file {
Subroutine _load_manifest_file: called CC=7 SCAR=19.5
31 36 my ( $self, $file ) = @_;
32 36 my $path = path($file)->absolute( $self->manifest_dir );
33 36 ▶ my $format = $path =~ /\.pk8s\z/ ? 'pk8s' : $path =~ /\.ya?ml\z/ ? 'yaml' : undef;
Branch: 2 branches
BranchTrueFalseTotal
$path =~ /\.pk8s\z/ ? : 7 29 36
$path =~ /\.ya?ml\z/ ? : 27 2 29
34 36 ▶ croak ref($self).': manifest file '.$path.' is neither .pk8s nor .yaml/.yml' unless $format;
Branch: 1 branch
BranchTrueFalseTotal
unless $format 2 34 36
35 34 ▶ croak ref($self).': manifest file '.$path.' does not exist' unless $path->is_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $path->is_file 4 30 34
36 30 my $io = $self->io_k8s;
37 # load_yaml gets the text: given a path it reads bytes, and takes a path
38 # that is not a file for YAML.
39 30 ▶ my $objects = eval {
Branch: 1 branch
BranchTrueFalseTotal
my $objects = eval { do { $format eq "pk8s" ? $io->load($path->stringify) : $io->load_yaml($path->slurp_utf8) } } or croak(ref($self) . ': cannot load manifest file ' . $path . ': ' . $@ =~ s/\s+\z//r) 24 6 30
40 30 ▶ $format eq 'pk8s' ? $io->load( $path->stringify ) : $io->load_yaml( $path->slurp_utf8 );
Branch: 1 branch
BranchTrueFalseTotal
$format eq 'pk8s' ? : 7 23 30
41 } or croak ref($self).': cannot load manifest file '.$path.': '.( $@ =~ s/\s+\z//r );
42 24 return @$objects;
43 }
44  
45  
46 2 1;
47  
48 __END__
« blib/lib/Kubernetes/Comb/Upstream/K8s.pm ↑ Summary blib/lib/Kubernetes/Comb/Endpoint.pm »