| 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
| |||||||||||||||
| 34 | 36 | ▶ | croak ref($self).': manifest file '.$path.' is neither .pk8s nor .yaml/.yml' unless $format; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 34 | ▶ | croak ref($self).': manifest file '.$path.' does not exist' unless $path->is_file; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 40 | 30 | ▶ | $format eq 'pk8s' ? $io->load( $path->stringify ) : $io->load_yaml( $path->slurp_utf8 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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__ | ||||||||||||||