| 1 | 2 | ▶ | use 5.14.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | package Dist::Iller::Config; | ||||||||||
| 6 | |||||||||||
| 7 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||
| 8 | # ABSTRACT: Role for Dist::Iller configs | ||||||||||
| 9 | 2 | our $VERSION = '0.1411'; | |||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use MooseX::AttributeShortcuts; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use Module::Load qw/load/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 2 | ▶ | use Types::Standard qw/Bool Str Maybe InstanceOf/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 2 | ▶ | use YAML::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | ▶ | use File::ShareDir 'dist_dir'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | ▶ | use String::CamelCase qw/camelize/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 2 | requires qw/filepath/; | |||||||||
| 24 | |||||||||||
| 25 | has main_module => ( | ||||||||||
| 26 | is => 'ro', | ||||||||||
| 27 | isa => Str, | ||||||||||
| 28 | lazy => 1, | ||||||||||
| 29 | traits => ['Documented'], | ||||||||||
| 30 | 3 | ▶ | default => sub { shift->meta->name }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 2 | documentation => q{Override this attribute when there's more than one config in a distribution. It uses the main_module's sharedir location for the config files.}, | |||||||||
| 32 | documentation_default => 'The package name', | ||||||||||
| 33 | ); | ||||||||||
| 34 | has distribution_name => ( | ||||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | isa => Str, | ||||||||||
| 37 | lazy => 1, | ||||||||||
| 38 | predicate => 1, | ||||||||||
| 39 | 0 | ▶ | default => sub { undef }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 40 | 2 | traits => ['Documented'], | |||||||||
| 41 | documentation_order => 0, | ||||||||||
| 42 | ); | ||||||||||
| 43 | 2 | has global => ( | |||||||||
| 44 | is => 'ro', | ||||||||||
| 45 | isa => Maybe[InstanceOf['Dist::Iller::DocType::Global']], | ||||||||||
| 46 | ); | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | 3 | ▶ | sub config_location { | ||||||||
|
Subroutine
config_location: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 50 | 3 | my $self = shift; | |||||||||
| 51 | 3 | my $package = $self->main_module; | |||||||||
| 52 | 3 | $package =~ s{::}{-}g; | |||||||||
| 53 | |||||||||||
| 54 | 3 | my $dir = path('.'); | |||||||||
| 55 | |||||||||||
| 56 | 3 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 57 | 3 | $dir = path(dist_dir($package)); | |||||||||
| 58 | } | ||||||||||
| 59 | 3 | ▶ | finally { }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 60 | |||||||||||
| 61 | 3 | return $dir->child($self->filepath); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 3 | ▶ | sub get_yaml_for { | ||||||||
|
Subroutine
get_yaml_for: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 65 | 3 | my $self = shift; | |||||||||
| 66 | 3 | my $doctype = shift; | |||||||||
| 67 | |||||||||||
| 68 | 3 | my $fullyaml = YAML::Tiny->read($self->config_location->absolute->stringify); | |||||||||
| 69 | |||||||||||
| 70 | 3 | my $yaml = (grep { $_->{'doctype'} eq $doctype } @{ $fullyaml })[0]; | |||||||||
| 71 | 3 | ▶ | return if !defined $yaml; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | |||||||||||
| 73 | 3 | my $doctype_class = sprintf 'Dist::Iller::DocType::%s', camelize($yaml->{'doctype'}); | |||||||||
| 74 | 3 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 75 | 3 | load $doctype_class; | |||||||||
| 76 | } | ||||||||||
| 77 | 0 | ▶ | catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 78 | 0 | croak "Can't load $doctype_class: $_"; | |||||||||
| 79 | 3 | }; | |||||||||
| 80 | |||||||||||
| 81 | 3 | return $doctype_class->new(config_obj => $self)->parse($yaml)->to_yaml; | |||||||||
| 82 | |||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 2 | 1; | |||||||||
| 86 | |||||||||||
| 87 | __END__ | ||||||||||